Skip to content

Automatically deploy verified OpenSensor API images from main #436

Automatically deploy verified OpenSensor API images from main

Automatically deploy verified OpenSensor API images from main #436

Workflow file for this run

# This is a basic workflow to help you get started with Actions
name: CI
# Keep main releases in order and let an active rollout finish.
concurrency:
group: opensensor-api-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
lint_codebase:
# The type of runner that the job will run on
runs-on: ubuntu-latest
environment: DigitalOcean-PROD
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: '3.11'
- run: |
python -m pip install pre-commit
pre-commit run --all-files --verbose --show-diff-on-failure
build_api:
# The type of runner that the job will run on
runs-on: ubuntu-latest
environment: DigitalOcean-PROD
outputs:
image: ${{ steps.build.outputs.image_digest }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v6
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Run Docker Build; main Publishes Image to Container Registry
id: build
uses: ./.github/workflows/build_api
with:
dockerfile: ./Dockerfile
image_path: whitewhale/opensensor
deploy_api:
needs: [lint_codebase, build_api]
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
runs-on: ubuntu-latest
environment: DigitalOcean-PROD
timeout-minutes: 15
env:
IMAGE: ${{ needs.build_api.outputs.image }}
KUBE_CONTEXT: do-nyc1-k8s-1-33-1-do-1-nyc1-1752275240114
steps:
- name: Install doctl
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Configure production Kubernetes access
run: doctl kubernetes cluster kubeconfig save k8s-1-33-1-do-1-nyc1-1752275240114
- name: Deploy the exact published image
run: |
[[ "$IMAGE" =~ ^registry\.digitalocean\.com/whitewhale/opensensor@sha256:[a-f0-9]{64}$ ]]
kubectl --context "$KUBE_CONTEXT" -n whitewhale set image deployment/opensensor-api opensensor-api="$IMAGE"
kubectl --context "$KUBE_CONTEXT" -n whitewhale rollout status deployment/opensensor-api --timeout=600s
- name: Verify the running release
run: |
actual=$(kubectl --context "$KUBE_CONTEXT" -n whitewhale get deployment opensensor-api -o jsonpath='{.spec.template.spec.containers[?(@.name=="opensensor-api")].image}')
test "$actual" = "$IMAGE"
kubectl --context "$KUBE_CONTEXT" -n whitewhale exec deployment/opensensor-api -- /usr/src/.venv/bin/python -c '
import os, sys, urllib.request
import sentry_sdk
assert os.environ["SENTRY_RELEASE"] == "opensensor-api@" + sys.argv[1]
assert os.environ.get("SENTRY_DSN")
with urllib.request.urlopen("http://127.0.0.1:8010/health", timeout=10) as response:
assert response.status == 200
print("Application health and Sentry release configuration verified")
' "$GITHUB_SHA"
printf 'Deployed %s after lint and image build passed.\n' "$IMAGE" >> "$GITHUB_STEP_SUMMARY"