|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + environment: |
| 9 | + description: "Target environment" |
| 10 | + required: true |
| 11 | + type: choice |
| 12 | + options: |
| 13 | + - staging |
| 14 | + - production |
| 15 | + |
| 16 | +env: |
| 17 | + REGISTRY: ghcr.io |
| 18 | + IMAGE_PREFIX: ghcr.io/${{ github.repository_owner }}/wildfire |
| 19 | + |
| 20 | +permissions: |
| 21 | + contents: read |
| 22 | + packages: write |
| 23 | + |
| 24 | +jobs: |
| 25 | + # ── Build & push images ────────────────────────────────────────── |
| 26 | + build: |
| 27 | + name: Build & Push |
| 28 | + runs-on: ubuntu-latest |
| 29 | + strategy: |
| 30 | + fail-fast: true |
| 31 | + matrix: |
| 32 | + service: |
| 33 | + - { name: apigw, context: ./apps/apigw, dockerfile: ./apps/apigw/Dockerfile } |
| 34 | + - { name: console, context: ./apps/console, dockerfile: ./apps/console/Dockerfile } |
| 35 | + - { name: triangulate, context: ".", dockerfile: ./apps/triangulate/Dockerfile } |
| 36 | + - { name: predict, context: ".", dockerfile: ./apps/predict/Dockerfile } |
| 37 | + - { name: ingest, context: ".", dockerfile: ./apps/ingest/Dockerfile } |
| 38 | + - { name: mission-dispatcher, context: ".", dockerfile: ./apps/mission-dispatcher/Dockerfile } |
| 39 | + - { name: edge-agent, context: ./apps/edge-agent, dockerfile: ./apps/edge-agent/Dockerfile } |
| 40 | + outputs: |
| 41 | + image_tag: ${{ steps.meta.outputs.tags }} |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Set up Docker Buildx |
| 47 | + uses: docker/setup-buildx-action@v3 |
| 48 | + |
| 49 | + - name: Login to GHCR |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - name: Docker metadata |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@v5 |
| 59 | + with: |
| 60 | + images: ${{ env.IMAGE_PREFIX }}-${{ matrix.service.name }} |
| 61 | + tags: | |
| 62 | + type=sha |
| 63 | + type=ref,event=branch |
| 64 | + type=raw,value=latest,enable={{is_default_branch}} |
| 65 | +
|
| 66 | + - name: Build and push |
| 67 | + uses: docker/build-push-action@v5 |
| 68 | + with: |
| 69 | + context: ${{ matrix.service.context }} |
| 70 | + file: ${{ matrix.service.dockerfile }} |
| 71 | + push: true |
| 72 | + tags: ${{ steps.meta.outputs.tags }} |
| 73 | + labels: ${{ steps.meta.outputs.labels }} |
| 74 | + cache-from: type=gha |
| 75 | + cache-to: type=gha,mode=max |
| 76 | + |
| 77 | + # ── Deploy to staging (auto on main push) ──────────────────────── |
| 78 | + staging: |
| 79 | + name: Deploy to Staging |
| 80 | + needs: build |
| 81 | + runs-on: ubuntu-latest |
| 82 | + if: github.ref == 'refs/heads/main' || github.event.inputs.environment == 'staging' |
| 83 | + environment: |
| 84 | + name: staging |
| 85 | + url: https://staging.wildfire-ops.com |
| 86 | + steps: |
| 87 | + - name: Checkout |
| 88 | + uses: actions/checkout@v4 |
| 89 | + |
| 90 | + - name: Configure kubectl |
| 91 | + uses: azure/setup-kubectl@v3 |
| 92 | + |
| 93 | + - name: Set kubeconfig |
| 94 | + run: echo "${{ secrets.KUBE_CONFIG_STAGING }}" | base64 -d > $HOME/.kube/config |
| 95 | + |
| 96 | + - name: Update image tags |
| 97 | + run: | |
| 98 | + TAG="sha-${GITHUB_SHA::7}" |
| 99 | + for svc in apigw console triangulate predict ingest mission-dispatcher edge-agent; do |
| 100 | + kubectl set image deployment/${svc} \ |
| 101 | + ${svc}=${{ env.IMAGE_PREFIX }}-${svc}:${TAG} \ |
| 102 | + -n wildfire-ops --record || true |
| 103 | + done |
| 104 | +
|
| 105 | + - name: Wait for rollout |
| 106 | + run: | |
| 107 | + for svc in apigw console triangulate predict ingest; do |
| 108 | + kubectl rollout status deployment/${svc} -n wildfire-ops --timeout=300s |
| 109 | + done |
| 110 | +
|
| 111 | + - name: Run smoke tests |
| 112 | + run: | |
| 113 | + API_URL="${{ secrets.STAGING_API_URL }}" |
| 114 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${API_URL}/health") |
| 115 | + if [ "$STATUS" != "200" ]; then |
| 116 | + echo "Smoke test failed: API returned $STATUS" |
| 117 | + exit 1 |
| 118 | + fi |
| 119 | + echo "Staging smoke test passed" |
| 120 | +
|
| 121 | + # ── Deploy to production (manual approval required) ────────────── |
| 122 | + production: |
| 123 | + name: Deploy to Production |
| 124 | + needs: staging |
| 125 | + runs-on: ubuntu-latest |
| 126 | + if: github.event.inputs.environment == 'production' || github.ref == 'refs/heads/main' |
| 127 | + environment: |
| 128 | + name: production |
| 129 | + url: https://console.wildfire-ops.com |
| 130 | + steps: |
| 131 | + - name: Checkout |
| 132 | + uses: actions/checkout@v4 |
| 133 | + |
| 134 | + - name: Configure kubectl |
| 135 | + uses: azure/setup-kubectl@v3 |
| 136 | + |
| 137 | + - name: Set kubeconfig |
| 138 | + run: echo "${{ secrets.KUBE_CONFIG_PRODUCTION }}" | base64 -d > $HOME/.kube/config |
| 139 | + |
| 140 | + - name: Update image tags (canary — 1 replica first) |
| 141 | + run: | |
| 142 | + TAG="sha-${GITHUB_SHA::7}" |
| 143 | + for svc in apigw console triangulate predict ingest mission-dispatcher edge-agent; do |
| 144 | + kubectl set image deployment/${svc} \ |
| 145 | + ${svc}=${{ env.IMAGE_PREFIX }}-${svc}:${TAG} \ |
| 146 | + -n wildfire-ops --record || true |
| 147 | + done |
| 148 | +
|
| 149 | + - name: Wait for rollout |
| 150 | + run: | |
| 151 | + for svc in apigw console triangulate predict ingest; do |
| 152 | + kubectl rollout status deployment/${svc} -n wildfire-ops --timeout=600s |
| 153 | + done |
| 154 | +
|
| 155 | + - name: Production smoke test |
| 156 | + run: | |
| 157 | + API_URL="${{ secrets.PRODUCTION_API_URL }}" |
| 158 | + STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${API_URL}/health") |
| 159 | + if [ "$STATUS" != "200" ]; then |
| 160 | + echo "Production smoke test FAILED — rolling back" |
| 161 | + for svc in apigw console triangulate predict ingest mission-dispatcher edge-agent; do |
| 162 | + kubectl rollout undo deployment/${svc} -n wildfire-ops || true |
| 163 | + done |
| 164 | + exit 1 |
| 165 | + fi |
| 166 | + echo "Production deploy successful" |
0 commit comments