|
20 | 20 | # This workflow does NOT run Terraform — infrastructure is managed by a |
21 | 21 | # dedicated pipeline in mypythonproject1-infra2. |
22 | 22 | # |
23 | | -# Secrets (GitHub Environments "staging" and "production"): |
| 23 | +# Secrets (GitHub Environments "dev", "staging", and "production"): |
24 | 24 | # AWS_ROLE_TO_ASSUME — OIDC role ARN with ECR push permission |
25 | 25 | # AWS_REGION — e.g. us-east-1 |
26 | 26 | # GITOPS_DEPLOY_TOKEN — PAT (contents:write) on mypythonproject1-gitops |
|
46 | 46 | description: "Target environment" |
47 | 47 | required: true |
48 | 48 | type: choice |
49 | | - options: [staging, production] |
| 49 | + options: [dev, staging, production] |
50 | 50 | default: staging |
51 | 51 |
|
52 | 52 | permissions: |
|
75 | 75 | (github.event_name == 'workflow_run' |
76 | 76 | && github.event.workflow_run.conclusion == 'success') |
77 | 77 | || (github.event_name == 'workflow_dispatch' |
78 | | - && inputs.environment == 'staging') |
79 | | - environment: staging |
| 78 | + && inputs.environment == 'dev') |
| 79 | + environment: dev |
80 | 80 | strategy: |
81 | 81 | matrix: |
82 | 82 | service: [backend, frontend] |
@@ -133,7 +133,7 @@ jobs: |
133 | 133 | runs-on: ubuntu-latest |
134 | 134 | timeout-minutes: 10 |
135 | 135 | needs: [build-dev] |
136 | | - environment: staging |
| 136 | + environment: dev |
137 | 137 | permissions: |
138 | 138 | contents: read |
139 | 139 | steps: |
@@ -167,6 +167,64 @@ jobs: |
167 | 167 | git commit -m "chore(deploy): dev image tag ${{ steps.tag.outputs.new-tag }} [skip ci]" |
168 | 168 | git push origin main |
169 | 169 |
|
| 170 | + # --------------------------------------------------------------------------- |
| 171 | + # 0c. Wait for ArgoCD to sync dev and report health |
| 172 | + # --------------------------------------------------------------------------- |
| 173 | + argocd-sync-dev: |
| 174 | + name: "ArgoCD Sync [dev]" |
| 175 | + runs-on: ubuntu-latest |
| 176 | + timeout-minutes: 15 |
| 177 | + needs: [update-gitops-dev] |
| 178 | + environment: dev |
| 179 | + steps: |
| 180 | + - name: Poll ArgoCD application health |
| 181 | + env: |
| 182 | + ARGOCD_SERVER: ${{ secrets.ARGOCD_SERVER }} |
| 183 | + ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }} |
| 184 | + run: | |
| 185 | + APP="mypythonproject1-dev" |
| 186 | + MAX=30 # 30 × 30s = 15 min |
| 187 | + SLEEP=30 |
| 188 | +
|
| 189 | + for i in $(seq 1 $MAX); do |
| 190 | + RESP=$(curl -sf \ |
| 191 | + -H "Authorization: Bearer $ARGOCD_TOKEN" \ |
| 192 | + "https://${ARGOCD_SERVER}/api/v1/applications/${APP}" || true) |
| 193 | +
|
| 194 | + HEALTH=$(echo "$RESP" | jq -r '.status.health.status // "Unknown"') |
| 195 | + SYNC=$(echo "$RESP" | jq -r '.status.sync.status // "Unknown"') |
| 196 | + echo "[$i/$MAX] health=$HEALTH sync=$SYNC" |
| 197 | +
|
| 198 | + if [[ "$HEALTH" == "Healthy" && "$SYNC" == "Synced" ]]; then |
| 199 | + echo "✅ ArgoCD: $APP is Healthy and Synced" |
| 200 | + exit 0 |
| 201 | + fi |
| 202 | +
|
| 203 | + if [[ "$HEALTH" == "Degraded" ]]; then |
| 204 | + echo "❌ ArgoCD: $APP health is Degraded — failing fast" |
| 205 | + exit 1 |
| 206 | + fi |
| 207 | +
|
| 208 | + sleep $SLEEP |
| 209 | + done |
| 210 | +
|
| 211 | + echo "❌ Timeout: $APP did not become Healthy+Synced within $((MAX * SLEEP / 60)) min" |
| 212 | + exit 1 |
| 213 | +
|
| 214 | + # --------------------------------------------------------------------------- |
| 215 | + # 0d. Smoke test (dev) |
| 216 | + # --------------------------------------------------------------------------- |
| 217 | + smoke-test-dev: |
| 218 | + name: "Smoke Test [dev]" |
| 219 | + needs: [argocd-sync-dev] |
| 220 | + uses: ./.github/workflows/_smoke-test.yml |
| 221 | + with: |
| 222 | + environment: dev |
| 223 | + app-url: ${{ vars.APP_URL }} |
| 224 | + warmup-seconds: 15 |
| 225 | + deploy-sha: ${{ github.event.workflow_run.head_sha || github.sha }} |
| 226 | + secrets: inherit |
| 227 | + |
170 | 228 | ############################################################################### |
171 | 229 | # ─── STAGING ──────────────────────────────────────────────────────────────── |
172 | 230 | ############################################################################### |
|
0 commit comments