|
| 1 | +name: Kubernetes Promotion Evidence |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + environment: |
| 7 | + description: Target environment |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: [dev, staging, prod] |
| 11 | + image: |
| 12 | + description: Full image reference; production requires @sha256 digest |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + deploy: |
| 16 | + description: Apply to the configured cluster instead of render-only evidence |
| 17 | + required: true |
| 18 | + default: false |
| 19 | + type: boolean |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: read |
| 23 | + |
| 24 | +jobs: |
| 25 | + promote: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + environment: ${{ inputs.environment }} |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@v4 |
| 30 | + |
| 31 | + - name: Set up Kustomize |
| 32 | + uses: imranismail/setup-kustomize@v2 |
| 33 | + |
| 34 | + - name: Set up kubectl |
| 35 | + uses: azure/setup-kubectl@v4 |
| 36 | + |
| 37 | + - name: Render immutable candidate manifest |
| 38 | + env: |
| 39 | + TARGET_ENV: ${{ inputs.environment }} |
| 40 | + IMAGE: ${{ inputs.image }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + cd "infra/kubernetes/overlays/${TARGET_ENV}" |
| 44 | + kustomize edit set image "api-gateway=${IMAGE}" |
| 45 | + kustomize build . > "$RUNNER_TEMP/rendered.yaml" |
| 46 | + grep -n "image:" "$RUNNER_TEMP/rendered.yaml" |
| 47 | +
|
| 48 | + - name: Enforce promotion policy before apply |
| 49 | + env: |
| 50 | + TARGET_ENV: ${{ inputs.environment }} |
| 51 | + IMAGE: ${{ inputs.image }} |
| 52 | + DEPLOY: ${{ inputs.deploy }} |
| 53 | + run: | |
| 54 | + set -euo pipefail |
| 55 | + if [[ "$TARGET_ENV" == "prod" && "$IMAGE" != *@sha256:* ]]; then |
| 56 | + echo "Production promotion requires an immutable @sha256 image digest." >&2 |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | + if [[ "$DEPLOY" == "true" && "$TARGET_ENV" != "dev" ]] && \ |
| 60 | + grep -q "replace-me" "$RUNNER_TEMP/rendered.yaml"; then |
| 61 | + echo "Staging/prod OIDC placeholders must be replaced before an actual deployment." >&2 |
| 62 | + exit 1 |
| 63 | + fi |
| 64 | +
|
| 65 | + - name: Client-side manifest validation |
| 66 | + run: kubectl apply --dry-run=client --validate=false -f "$RUNNER_TEMP/rendered.yaml" |
| 67 | + |
| 68 | + - name: Configure cluster credentials |
| 69 | + if: ${{ inputs.deploy }} |
| 70 | + env: |
| 71 | + KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }} |
| 72 | + run: | |
| 73 | + test -n "$KUBE_CONFIG_DATA" |
| 74 | + printf '%s' "$KUBE_CONFIG_DATA" | base64 --decode > "$RUNNER_TEMP/kubeconfig" |
| 75 | + echo "KUBECONFIG=$RUNNER_TEMP/kubeconfig" >> "$GITHUB_ENV" |
| 76 | +
|
| 77 | + - name: Capture current revision |
| 78 | + if: ${{ inputs.deploy }} |
| 79 | + id: before |
| 80 | + run: | |
| 81 | + revision=$(kubectl rollout history deployment/api-gateway | awk 'NR>2 && $1 ~ /^[0-9]+$/ {print $1}' | tail -n 1) |
| 82 | + echo "revision=${revision:-unknown}" >> "$GITHUB_OUTPUT" |
| 83 | +
|
| 84 | + - name: Apply and verify rollout |
| 85 | + if: ${{ inputs.deploy }} |
| 86 | + run: | |
| 87 | + kubectl apply -f "$RUNNER_TEMP/rendered.yaml" |
| 88 | + kubectl rollout status deployment/api-gateway --timeout=180s |
| 89 | +
|
| 90 | + - name: Capture promoted revision |
| 91 | + if: ${{ inputs.deploy }} |
| 92 | + id: after |
| 93 | + run: | |
| 94 | + revision=$(kubectl rollout history deployment/api-gateway | awk 'NR>2 && $1 ~ /^[0-9]+$/ {print $1}' | tail -n 1) |
| 95 | + echo "revision=${revision:-unknown}" >> "$GITHUB_OUTPUT" |
| 96 | +
|
| 97 | + - name: Record render-only evidence |
| 98 | + if: ${{ !inputs.deploy }} |
| 99 | + run: | |
| 100 | + python scripts/k8s_release_evidence.py \ |
| 101 | + --action promote \ |
| 102 | + --environment '${{ inputs.environment }}' \ |
| 103 | + --image '${{ inputs.image }}' \ |
| 104 | + --git-sha '${{ github.sha }}' \ |
| 105 | + --manifest "$RUNNER_TEMP/rendered.yaml" \ |
| 106 | + --deployment-status rendered \ |
| 107 | + --output evidence/kubernetes-deployment-results.json |
| 108 | +
|
| 109 | + - name: Record applied promotion evidence |
| 110 | + if: ${{ inputs.deploy }} |
| 111 | + run: | |
| 112 | + python scripts/k8s_release_evidence.py \ |
| 113 | + --action promote \ |
| 114 | + --environment '${{ inputs.environment }}' \ |
| 115 | + --image '${{ inputs.image }}' \ |
| 116 | + --git-sha '${{ github.sha }}' \ |
| 117 | + --manifest "$RUNNER_TEMP/rendered.yaml" \ |
| 118 | + --deployment-status applied \ |
| 119 | + --from-revision '${{ steps.before.outputs.revision }}' \ |
| 120 | + --to-revision '${{ steps.after.outputs.revision }}' \ |
| 121 | + --output evidence/kubernetes-deployment-results.json |
| 122 | +
|
| 123 | + - name: Upload promotion evidence |
| 124 | + uses: actions/upload-artifact@v4 |
| 125 | + with: |
| 126 | + name: kubernetes-promotion-${{ inputs.environment }}-${{ github.sha }} |
| 127 | + path: | |
| 128 | + ${{ runner.temp }}/rendered.yaml |
| 129 | + evidence/kubernetes-deployment-results.json |
| 130 | + if-no-files-found: error |
0 commit comments