grada-run 0.41.5 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +18 -8
- package/package.json +1 -1
- package/src/commands/add.js +93 -11
- package/src/commands/alerts.js +69 -31
- package/src/commands/apply.js +62 -10
- package/src/commands/db/backup.js +1 -2
- package/src/commands/db/connect.js +27 -14
- package/src/commands/db/enable-vector.js +19 -6
- package/src/commands/db/import.js +114 -22
- package/src/commands/db/migrate.js +77 -73
- package/src/commands/db/restore.js +38 -6
- package/src/commands/destroy.js +68 -6
- package/src/commands/diagnose.js +57 -32
- package/src/commands/doctor.js +5 -3
- package/src/commands/domain.js +55 -7
- package/src/commands/drift.js +2 -1
- package/src/commands/eject.js +13 -2
- package/src/commands/exec.js +9 -4
- package/src/commands/gc.js +135 -6
- package/src/commands/init.js +75 -9
- package/src/commands/logs.js +127 -38
- package/src/commands/mcp.js +3 -2
- package/src/commands/rollback.js +230 -74
- package/src/commands/secrets.js +251 -61
- package/src/commands/status.js +17 -8
- package/src/commands/sync-ai.js +4 -3
- package/src/commands/wake.js +45 -1
- package/src/data/action-pins.js +26 -0
- package/src/utils/addons.js +9 -6
- package/src/utils/ai-rules.js +3 -2
- package/src/utils/backup.js +16 -2
- package/src/utils/command.js +20 -0
- package/src/utils/db-tunnel.js +15 -5
- package/src/utils/detector.js +8 -0
- package/src/utils/ecs-runner.js +16 -3
- package/src/utils/frameworks.js +14 -2
- package/src/utils/generator.js +33 -16
- package/src/utils/prompts.js +20 -4
- package/src/utils/resolvers.js +74 -11
- package/src/utils/revision-discovery.js +19 -7
- package/templates/docker/nestjs.Dockerfile +2 -2
- package/templates/docker/nextjs.Dockerfile +3 -3
- package/templates/docker/node.Dockerfile +2 -2
- package/templates/docker/nuxt.Dockerfile +2 -2
- package/templates/docker/static.Dockerfile +1 -1
- package/templates/docker/svelte.Dockerfile +2 -2
- package/templates/github/deploy-lambda.yml +73 -11
- package/templates/github/deploy-static.yml +4 -3
- package/templates/github/deploy.yml +114 -12
- package/templates/github/drift.yml +74 -5
- package/templates/github/preview-lambda.yml +143 -13
- package/templates/github/preview.yml +141 -13
- package/templates/github/teardown.yml +77 -12
- package/templates/terraform/addons/bedrock.tf +6 -2
- package/templates/terraform/addons/s3.tf +33 -0
- package/templates/terraform/backend.tf +7 -0
- package/templates/terraform/cloudfront-lambda.tf +125 -6
- package/templates/terraform/cloudfront.tf +137 -10
- package/templates/terraform/database-mysql.tf +5 -1
- package/templates/terraform/database.tf +5 -1
- package/templates/terraform/main.tf +36 -1
- package/templates/terraform/network.tf +5 -2
- package/templates/terraform/oidc.tf +3 -2
- package/templates/terraform/secrets.tf +6 -4
- package/templates/terraform/worker.tf +7 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# Stage 1: Build the Nuxt Nitro output
|
|
2
|
-
FROM node:22-alpine AS builder
|
|
2
|
+
FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 AS builder
|
|
3
3
|
WORKDIR /app
|
|
4
4
|
|
|
5
5
|
# Install native build tools required to compile C++ Node modules (like better-sqlite3)
|
|
@@ -16,7 +16,7 @@ COPY . .
|
|
|
16
16
|
RUN npm run build
|
|
17
17
|
|
|
18
18
|
# Stage 2: Production runner
|
|
19
|
-
FROM node:22-alpine AS runner
|
|
19
|
+
FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 AS runner
|
|
20
20
|
WORKDIR /app
|
|
21
21
|
|
|
22
22
|
ENV NODE_ENV=production
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# ==========================================
|
|
2
2
|
# Stage 1: Builder
|
|
3
3
|
# ==========================================
|
|
4
|
-
FROM node:22-alpine AS builder
|
|
4
|
+
FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914 AS builder
|
|
5
5
|
WORKDIR /app
|
|
6
6
|
|
|
7
7
|
# Install all dependencies (including devDependencies)
|
|
@@ -24,7 +24,7 @@ RUN GRADA_BYPASS=true npm run build
|
|
|
24
24
|
# ==========================================
|
|
25
25
|
# Stage 2: Production (Zero-CVE)
|
|
26
26
|
# ==========================================
|
|
27
|
-
FROM node:22-alpine
|
|
27
|
+
FROM node:22-alpine@sha256:fe4f6d74e20370acb04ad889077d14d0f64a9c8ea6a42bc60cddf1e844699914
|
|
28
28
|
|
|
29
29
|
# 1. DevSecOps: Patch underlying Alpine OS vulnerabilities
|
|
30
30
|
RUN apk update && apk upgrade --no-cache
|
|
@@ -16,6 +16,7 @@ env:
|
|
|
16
16
|
AWS_REGION: {{REGION}}
|
|
17
17
|
ECR_REPOSITORY: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-repo
|
|
18
18
|
LAMBDA_FUNCTION: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-fn
|
|
19
|
+
CF_COMMENT: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-cdn
|
|
19
20
|
|
|
20
21
|
permissions:
|
|
21
22
|
id-token: write
|
|
@@ -25,10 +26,11 @@ jobs:
|
|
|
25
26
|
deploy:
|
|
26
27
|
name: Build & Deploy
|
|
27
28
|
runs-on: ubuntu-latest
|
|
29
|
+
timeout-minutes: 60
|
|
28
30
|
|
|
29
31
|
steps:
|
|
30
32
|
- name: Checkout Code
|
|
31
|
-
uses: actions/checkout@v4
|
|
33
|
+
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
32
34
|
|
|
33
35
|
# --- 1. IaC SECURITY SCAN ---
|
|
34
36
|
- name: Scan Terraform for Misconfigurations
|
|
@@ -52,18 +54,39 @@ jobs:
|
|
|
52
54
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
53
55
|
fi
|
|
54
56
|
|
|
55
|
-
# --- 2.
|
|
56
|
-
- name:
|
|
57
|
-
|
|
57
|
+
# --- 2. AWS AUTH (job-level credentials for every step below) ---
|
|
58
|
+
- name: Configure AWS credentials
|
|
59
|
+
id: aws-creds
|
|
60
|
+
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
|
|
61
|
+
continue-on-error: true
|
|
58
62
|
with:
|
|
59
|
-
aws-region: ${{ env.AWS_REGION }}
|
|
60
63
|
role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
|
|
61
|
-
|
|
64
|
+
aws-region: ${{ env.AWS_REGION }}
|
|
65
|
+
|
|
66
|
+
# Deploy never skips: a failed assume fails the run with the
|
|
67
|
+
# bootstrap pointer (BUG-138).
|
|
68
|
+
- name: Interpret credential failure
|
|
69
|
+
if: steps.aws-creds.outcome == 'failure'
|
|
70
|
+
run: |
|
|
71
|
+
echo "::error::AWS credential assumption failed — if the stack was never provisioned, bootstrap it first (npx grada-run apply); otherwise check terraform/oidc.tf trust."
|
|
72
|
+
exit 1
|
|
73
|
+
|
|
74
|
+
# --- 3. ECR BOOTSTRAP ---
|
|
75
|
+
# The image is pushed BEFORE the full apply (the function must never
|
|
76
|
+
# point at an unpushed tag), but the repository itself is
|
|
77
|
+
# Terraform-managed — so it is bootstrapped with a targeted apply
|
|
78
|
+
# first. Idempotent on existing stacks.
|
|
79
|
+
- name: Bootstrap ECR repository
|
|
80
|
+
working-directory: ./terraform
|
|
81
|
+
run: |
|
|
82
|
+
terraform init -input=false
|
|
83
|
+
terraform workspace select default
|
|
84
|
+
terraform apply -target=aws_ecr_repository.app -auto-approve -input=false
|
|
62
85
|
|
|
63
|
-
# ---
|
|
86
|
+
# --- 4. BUILD ---
|
|
64
87
|
- name: Login to Amazon ECR
|
|
65
88
|
id: login-ecr
|
|
66
|
-
uses: aws-actions/amazon-ecr-login@v2
|
|
89
|
+
uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2
|
|
67
90
|
|
|
68
91
|
- name: Build Docker image
|
|
69
92
|
id: build-image
|
|
@@ -77,8 +100,8 @@ jobs:
|
|
|
77
100
|
docker build --platform linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG .
|
|
78
101
|
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
79
102
|
|
|
80
|
-
# ---
|
|
81
|
-
- name: Scan Container for Vulnerabilities (
|
|
103
|
+
# --- 5. CONTAINER SECURITY SCAN ---
|
|
104
|
+
- name: Scan Container for Vulnerabilities (table summary)
|
|
82
105
|
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
|
|
83
106
|
with:
|
|
84
107
|
image-ref: '${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest'
|
|
@@ -99,8 +122,9 @@ jobs:
|
|
|
99
122
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
100
123
|
fi
|
|
101
124
|
|
|
102
|
-
# ---
|
|
125
|
+
# --- 6. PUSH ---
|
|
103
126
|
- name: Push image to Amazon ECR
|
|
127
|
+
id: push
|
|
104
128
|
env:
|
|
105
129
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
106
130
|
IMAGE_TAG: latest
|
|
@@ -110,6 +134,17 @@ jobs:
|
|
|
110
134
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
111
135
|
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG" >> $GITHUB_OUTPUT
|
|
112
136
|
|
|
137
|
+
# --- 7. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
|
|
138
|
+
# Runs AFTER the push: the function image tags exist by the time the
|
|
139
|
+
# function is created or updated.
|
|
140
|
+
- name: Apply Infrastructure Changes
|
|
141
|
+
uses: grada-run/grada-action@12227808ae4caafaec1041319645586a1132fc57 # v1
|
|
142
|
+
with:
|
|
143
|
+
aws-region: ${{ env.AWS_REGION }}
|
|
144
|
+
role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
|
|
145
|
+
terraform-dir: 'terraform'
|
|
146
|
+
|
|
147
|
+
# --- 8. DEPLOY ---
|
|
113
148
|
# Each code push deploys the immutable SHA-tagged image to the Lambda
|
|
114
149
|
# function, so every ECR tag stays a redeployable rollback point (and
|
|
115
150
|
# `latest` is never the deploy artifact of record).
|
|
@@ -123,3 +158,30 @@ jobs:
|
|
|
123
158
|
aws lambda wait function-updated \
|
|
124
159
|
--function-name ${{ env.LAMBDA_FUNCTION }} \
|
|
125
160
|
--region ${{ env.AWS_REGION }}
|
|
161
|
+
|
|
162
|
+
# --- 9. CACHE INVALIDATION ---
|
|
163
|
+
# New code means new HTML: clear the CDN so deploys go live
|
|
164
|
+
# immediately instead of serving stale pages until TTL expiry.
|
|
165
|
+
- name: Invalidate CloudFront
|
|
166
|
+
run: |
|
|
167
|
+
DIST_ID=$(aws cloudfront list-distributions \
|
|
168
|
+
--query "DistributionList.Items[?Comment=='${{ env.CF_COMMENT }}'].Id | [0]" \
|
|
169
|
+
--output text \
|
|
170
|
+
--region ${{ env.AWS_REGION }})
|
|
171
|
+
if [ -z "$DIST_ID" ] || [ "$DIST_ID" = "None" ]; then
|
|
172
|
+
echo "CloudFront distribution '${{ env.CF_COMMENT }}' not found." >&2
|
|
173
|
+
exit 1
|
|
174
|
+
fi
|
|
175
|
+
aws cloudfront create-invalidation \
|
|
176
|
+
--distribution-id "$DIST_ID" \
|
|
177
|
+
--paths "/*" \
|
|
178
|
+
--region ${{ env.AWS_REGION }}
|
|
179
|
+
|
|
180
|
+
# A cancelled apply/destroy can strand the S3 state lockfile: point
|
|
181
|
+
# at recovery instead of leaving the next run to fail obscurely
|
|
182
|
+
# (BUG-194). Generic by necessity — the lock ID only exists in the
|
|
183
|
+
# follow-up run's own error.
|
|
184
|
+
- name: Cancellation recovery note
|
|
185
|
+
if: cancelled()
|
|
186
|
+
run: |
|
|
187
|
+
echo "::warning::This run was cancelled while Terraform may have held the state lock. If the next run fails with 'Error acquiring the state lock', run terraform force-unlock <LOCK_ID> (the ID is printed in that error) inside ./terraform — or delete the .tflock object beside the state file in S3 — then re-run."
|
|
@@ -26,10 +26,11 @@ jobs:
|
|
|
26
26
|
deploy:
|
|
27
27
|
name: Build & Deploy
|
|
28
28
|
runs-on: ubuntu-latest
|
|
29
|
+
timeout-minutes: 30
|
|
29
30
|
|
|
30
31
|
steps:
|
|
31
32
|
- name: Checkout Code
|
|
32
|
-
uses: actions/checkout@v4
|
|
33
|
+
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
33
34
|
|
|
34
35
|
# --- 1. IaC SECURITY SCAN ---
|
|
35
36
|
- name: Scan Terraform for Misconfigurations
|
|
@@ -55,7 +56,7 @@ jobs:
|
|
|
55
56
|
|
|
56
57
|
# --- 2. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
|
|
57
58
|
- name: Apply Infrastructure Changes
|
|
58
|
-
uses: grada-run/grada-action@v1
|
|
59
|
+
uses: grada-run/grada-action@12227808ae4caafaec1041319645586a1132fc57 # v1
|
|
59
60
|
with:
|
|
60
61
|
aws-region: ${{ env.AWS_REGION }}
|
|
61
62
|
role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
|
|
@@ -63,7 +64,7 @@ jobs:
|
|
|
63
64
|
|
|
64
65
|
# --- 3. BUILD ---
|
|
65
66
|
- name: Setup Node.js
|
|
66
|
-
uses: actions/setup-node@v4
|
|
67
|
+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
|
|
67
68
|
with:
|
|
68
69
|
node-version: '22'
|
|
69
70
|
cache: 'npm'
|
|
@@ -20,6 +20,7 @@ env:
|
|
|
20
20
|
ECS_TASK_FAMILY: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-task
|
|
21
21
|
ECS_WORKER_SERVICE: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-worker-service
|
|
22
22
|
ECS_WORKER_TASK_FAMILY: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-worker-task
|
|
23
|
+
CF_COMMENT: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-cdn
|
|
23
24
|
|
|
24
25
|
permissions:
|
|
25
26
|
id-token: write
|
|
@@ -29,10 +30,11 @@ jobs:
|
|
|
29
30
|
deploy:
|
|
30
31
|
name: Build & Deploy
|
|
31
32
|
runs-on: ubuntu-latest
|
|
33
|
+
timeout-minutes: 60
|
|
32
34
|
|
|
33
35
|
steps:
|
|
34
36
|
- name: Checkout Code
|
|
35
|
-
uses: actions/checkout@v4
|
|
37
|
+
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
36
38
|
|
|
37
39
|
# --- 1. IaC SECURITY SCAN ---
|
|
38
40
|
- name: Scan Terraform for Misconfigurations
|
|
@@ -56,18 +58,39 @@ jobs:
|
|
|
56
58
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
57
59
|
fi
|
|
58
60
|
|
|
59
|
-
# --- 2.
|
|
60
|
-
- name:
|
|
61
|
-
|
|
61
|
+
# --- 2. AWS AUTH (job-level credentials for every step below) ---
|
|
62
|
+
- name: Configure AWS credentials
|
|
63
|
+
id: aws-creds
|
|
64
|
+
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
|
|
65
|
+
continue-on-error: true
|
|
62
66
|
with:
|
|
63
|
-
aws-region: ${{ env.AWS_REGION }}
|
|
64
67
|
role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
|
|
65
|
-
|
|
68
|
+
aws-region: ${{ env.AWS_REGION }}
|
|
66
69
|
|
|
67
|
-
#
|
|
70
|
+
# Deploy never skips: a failed assume fails the run with the
|
|
71
|
+
# bootstrap pointer (BUG-138).
|
|
72
|
+
- name: Interpret credential failure
|
|
73
|
+
if: steps.aws-creds.outcome == 'failure'
|
|
74
|
+
run: |
|
|
75
|
+
echo "::error::AWS credential assumption failed — if the stack was never provisioned, bootstrap it first (npx grada-run apply); otherwise check terraform/oidc.tf trust."
|
|
76
|
+
exit 1
|
|
77
|
+
|
|
78
|
+
# --- 3. ECR BOOTSTRAP ---
|
|
79
|
+
# The image is pushed BEFORE the full apply (fresh stacks must never
|
|
80
|
+
# start tasks on an unpushed tag), but the repository itself is
|
|
81
|
+
# Terraform-managed — so it is bootstrapped with a targeted apply
|
|
82
|
+
# first. Idempotent on existing stacks.
|
|
83
|
+
- name: Bootstrap ECR repository
|
|
84
|
+
working-directory: ./terraform
|
|
85
|
+
run: |
|
|
86
|
+
terraform init -input=false
|
|
87
|
+
terraform workspace select default
|
|
88
|
+
terraform apply -target=aws_ecr_repository.app -auto-approve -input=false
|
|
89
|
+
|
|
90
|
+
# --- 4. BUILD ---
|
|
68
91
|
- name: Login to Amazon ECR
|
|
69
92
|
id: login-ecr
|
|
70
|
-
uses: aws-actions/amazon-ecr-login@v2
|
|
93
|
+
uses: aws-actions/amazon-ecr-login@03f1aad4c6c7ffd436567f42f9384779290529bd # v2
|
|
71
94
|
|
|
72
95
|
- name: Build Docker image
|
|
73
96
|
id: build-image
|
|
@@ -79,8 +102,8 @@ jobs:
|
|
|
79
102
|
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG .
|
|
80
103
|
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
81
104
|
|
|
82
|
-
# ---
|
|
83
|
-
- name: Scan Container for Vulnerabilities (
|
|
105
|
+
# --- 5. CONTAINER SECURITY SCAN ---
|
|
106
|
+
- name: Scan Container for Vulnerabilities (table summary)
|
|
84
107
|
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
|
|
85
108
|
with:
|
|
86
109
|
image-ref: '${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:latest'
|
|
@@ -101,8 +124,9 @@ jobs:
|
|
|
101
124
|
echo '```' >> $GITHUB_STEP_SUMMARY
|
|
102
125
|
fi
|
|
103
126
|
|
|
104
|
-
# ---
|
|
127
|
+
# --- 6. PUSH ---
|
|
105
128
|
- name: Push image to Amazon ECR
|
|
129
|
+
id: push
|
|
106
130
|
env:
|
|
107
131
|
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
|
|
108
132
|
IMAGE_TAG: latest
|
|
@@ -112,6 +136,18 @@ jobs:
|
|
|
112
136
|
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
|
|
113
137
|
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SHA_TAG" >> $GITHUB_OUTPUT
|
|
114
138
|
|
|
139
|
+
# --- 7. INFRASTRUCTURE SYNC (The New Marketplace Action) ---
|
|
140
|
+
# Runs AFTER the push: by the time apply moves tasks onto `:latest`,
|
|
141
|
+
# the tag exists. A gate failure below can therefore never strand
|
|
142
|
+
# the service on an unpullable revision.
|
|
143
|
+
- name: Apply Infrastructure Changes
|
|
144
|
+
uses: grada-run/grada-action@12227808ae4caafaec1041319645586a1132fc57 # v1
|
|
145
|
+
with:
|
|
146
|
+
aws-region: ${{ env.AWS_REGION }}
|
|
147
|
+
role-to-assume: arn:aws:iam::{{AWS_ACCOUNT_ID}}:role/{{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-github-actions-role
|
|
148
|
+
terraform-dir: 'terraform'
|
|
149
|
+
|
|
150
|
+
# --- 8. DEPLOY ---
|
|
115
151
|
# Each code push registers a new task definition revision pinned to the
|
|
116
152
|
# immutable SHA-tagged image, so `rollback` always has history to
|
|
117
153
|
# return to (and `latest` is never overwritten in place as the deploy
|
|
@@ -144,6 +180,27 @@ jobs:
|
|
|
144
180
|
--force-new-deployment \
|
|
145
181
|
--region ${{ env.AWS_REGION }}
|
|
146
182
|
|
|
183
|
+
# update-service returns before the rollout finishes: wait for
|
|
184
|
+
# stability, then verify PRIMARY actually runs the registered
|
|
185
|
+
# revision — a circuit-breaker rollback re-stabilizes on the OLD
|
|
186
|
+
# revision, which the wait alone would report green.
|
|
187
|
+
- name: Wait for web rollout
|
|
188
|
+
run: |
|
|
189
|
+
aws ecs wait services-stable \
|
|
190
|
+
--cluster ${{ env.ECS_CLUSTER }} \
|
|
191
|
+
--services ${{ env.ECS_SERVICE }} \
|
|
192
|
+
--region ${{ env.AWS_REGION }}
|
|
193
|
+
PRIMARY_TD=$(aws ecs describe-services \
|
|
194
|
+
--cluster ${{ env.ECS_CLUSTER }} \
|
|
195
|
+
--services ${{ env.ECS_SERVICE }} \
|
|
196
|
+
--query 'services[0].deployments[?status==`PRIMARY`].taskDefinition' \
|
|
197
|
+
--output text \
|
|
198
|
+
--region ${{ env.AWS_REGION }})
|
|
199
|
+
if [ "$PRIMARY_TD" != "${{ steps.register-task-def.outputs.task-arn }}" ]; then
|
|
200
|
+
echo "Web rollout of ${{ steps.register-task-def.outputs.task-arn }} did not stick (PRIMARY runs $PRIMARY_TD) — the deployment failed or rolled back." >&2
|
|
201
|
+
exit 1
|
|
202
|
+
fi
|
|
203
|
+
|
|
147
204
|
# The background worker ships the same image as web, so it gets the
|
|
148
205
|
# same SHA-pinned revision treatment — otherwise it would run stale
|
|
149
206
|
# code forever while web moves on. Skipped on workerless projects.
|
|
@@ -175,4 +232,49 @@ jobs:
|
|
|
175
232
|
--service ${{ env.ECS_WORKER_SERVICE }} \
|
|
176
233
|
--task-definition ${{ steps.register-worker-task-def.outputs.task-arn }} \
|
|
177
234
|
--force-new-deployment \
|
|
178
|
-
--region ${{ env.AWS_REGION }}
|
|
235
|
+
--region ${{ env.AWS_REGION }}
|
|
236
|
+
|
|
237
|
+
- name: Wait for worker rollout
|
|
238
|
+
if: hashFiles('terraform/worker.tf') != ''
|
|
239
|
+
run: |
|
|
240
|
+
aws ecs wait services-stable \
|
|
241
|
+
--cluster ${{ env.ECS_CLUSTER }} \
|
|
242
|
+
--services ${{ env.ECS_WORKER_SERVICE }} \
|
|
243
|
+
--region ${{ env.AWS_REGION }}
|
|
244
|
+
PRIMARY_TD=$(aws ecs describe-services \
|
|
245
|
+
--cluster ${{ env.ECS_CLUSTER }} \
|
|
246
|
+
--services ${{ env.ECS_WORKER_SERVICE }} \
|
|
247
|
+
--query 'services[0].deployments[?status==`PRIMARY`].taskDefinition' \
|
|
248
|
+
--output text \
|
|
249
|
+
--region ${{ env.AWS_REGION }})
|
|
250
|
+
if [ "$PRIMARY_TD" != "${{ steps.register-worker-task-def.outputs.task-arn }}" ]; then
|
|
251
|
+
echo "Worker rollout of ${{ steps.register-worker-task-def.outputs.task-arn }} did not stick (PRIMARY runs $PRIMARY_TD) — the deployment failed or rolled back." >&2
|
|
252
|
+
exit 1
|
|
253
|
+
fi
|
|
254
|
+
|
|
255
|
+
# --- 9. CACHE INVALIDATION ---
|
|
256
|
+
# New code means new HTML: clear the CDN so deploys go live
|
|
257
|
+
# immediately instead of serving stale pages until TTL expiry.
|
|
258
|
+
- name: Invalidate CloudFront
|
|
259
|
+
run: |
|
|
260
|
+
DIST_ID=$(aws cloudfront list-distributions \
|
|
261
|
+
--query "DistributionList.Items[?Comment=='${{ env.CF_COMMENT }}'].Id | [0]" \
|
|
262
|
+
--output text \
|
|
263
|
+
--region ${{ env.AWS_REGION }})
|
|
264
|
+
if [ -z "$DIST_ID" ] || [ "$DIST_ID" = "None" ]; then
|
|
265
|
+
echo "CloudFront distribution '${{ env.CF_COMMENT }}' not found." >&2
|
|
266
|
+
exit 1
|
|
267
|
+
fi
|
|
268
|
+
aws cloudfront create-invalidation \
|
|
269
|
+
--distribution-id "$DIST_ID" \
|
|
270
|
+
--paths "/*" \
|
|
271
|
+
--region ${{ env.AWS_REGION }}
|
|
272
|
+
|
|
273
|
+
# A cancelled apply/destroy can strand the S3 state lockfile: point
|
|
274
|
+
# at recovery instead of leaving the next run to fail obscurely
|
|
275
|
+
# (BUG-194). Generic by necessity — the lock ID only exists in the
|
|
276
|
+
# follow-up run's own error.
|
|
277
|
+
- name: Cancellation recovery note
|
|
278
|
+
if: cancelled()
|
|
279
|
+
run: |
|
|
280
|
+
echo "::warning::This run was cancelled while Terraform may have held the state lock. If the next run fails with 'Error acquiring the state lock', run terraform force-unlock <LOCK_ID> (the ID is printed in that error) inside ./terraform — or delete the .tflock object beside the state file in S3 — then re-run."
|
|
@@ -17,19 +17,38 @@ jobs:
|
|
|
17
17
|
drift:
|
|
18
18
|
name: Detect Terraform drift
|
|
19
19
|
runs-on: ubuntu-latest
|
|
20
|
+
timeout-minutes: 30
|
|
20
21
|
|
|
21
22
|
steps:
|
|
22
23
|
- name: Checkout Code
|
|
23
|
-
uses: actions/checkout@v4
|
|
24
|
+
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
|
|
24
25
|
|
|
25
26
|
- name: Configure AWS Credentials
|
|
26
|
-
|
|
27
|
+
id: aws-creds
|
|
28
|
+
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a # v4
|
|
29
|
+
continue-on-error: true
|
|
27
30
|
with:
|
|
28
31
|
role-to-assume: {{ROLE_ARN}}
|
|
29
32
|
aws-region: ${{ env.AWS_REGION }}
|
|
30
33
|
|
|
34
|
+
# A missing role means the stack is absent (never provisioned or
|
|
35
|
+
# destroyed): skip loud instead of bursting red assume noise. Any
|
|
36
|
+
# other assume failure fails loud with both cases named (BUG-138).
|
|
37
|
+
- name: Interpret credential failure
|
|
38
|
+
if: steps.aws-creds.outcome == 'failure'
|
|
39
|
+
run: |
|
|
40
|
+
ROLE_ARN="{{ROLE_ARN}}"
|
|
41
|
+
TOKEN="$(curl -fsSL -H "Authorization: bearer ${ACTIONS_ID_TOKEN_REQUEST_TOKEN}" "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=sts.amazonaws.com" | jq -r '.value')"
|
|
42
|
+
ERR="$(aws sts assume-role-with-web-identity --role-arn "$ROLE_ARN" --role-session-name grada-preflight --web-identity-token "$TOKEN" 2>&1)" || true
|
|
43
|
+
if echo "$ERR" | grep -qiE 'NoSuchEntity|does not exist|cannot be found'; then
|
|
44
|
+
echo "::notice::AWS role $ROLE_ARN does not exist — the stack was likely never provisioned or was destroyed. Skipping this run (re-bootstrap with: npx grada-run apply)."
|
|
45
|
+
else
|
|
46
|
+
echo "::error::AWS credential assumption failed. Either the role is missing (stack absent — re-bootstrap with: npx grada-run apply) or the OIDC trust does not cover this run (check terraform/oidc.tf). Raw error: $ERR"
|
|
47
|
+
exit 1
|
|
48
|
+
fi
|
|
49
|
+
|
|
31
50
|
- name: Setup Terraform
|
|
32
|
-
uses: hashicorp/setup-terraform@v3
|
|
51
|
+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3
|
|
33
52
|
with:
|
|
34
53
|
# The wrapper mangles -detailed-exitcode; raw codes (0/1/2) are the signal.
|
|
35
54
|
terraform_wrapper: false
|
|
@@ -41,10 +60,11 @@ jobs:
|
|
|
41
60
|
# -detailed-exitcode: 0 = no changes, 1 = error, 2 = drift detected.
|
|
42
61
|
- name: Terraform Plan
|
|
43
62
|
id: plan
|
|
63
|
+
if: steps.aws-creds.outcome == 'success'
|
|
44
64
|
working-directory: ./terraform
|
|
45
65
|
run: |
|
|
46
66
|
set +e
|
|
47
|
-
terraform plan -detailed-exitcode -no-color -out=tfplan > plan-full.txt 2>&1
|
|
67
|
+
terraform plan -input=false -detailed-exitcode -no-color -out=tfplan > plan-full.txt 2>&1
|
|
48
68
|
EXITCODE=$?
|
|
49
69
|
echo "exitcode=$EXITCODE" >> "$GITHUB_OUTPUT"
|
|
50
70
|
if [ "$EXITCODE" != "1" ]; then
|
|
@@ -54,6 +74,9 @@ jobs:
|
|
|
54
74
|
fi
|
|
55
75
|
echo "### Drift plan (exit $EXITCODE)" >> "$GITHUB_STEP_SUMMARY"
|
|
56
76
|
head -50 plan.txt >> "$GITHUB_STEP_SUMMARY"
|
|
77
|
+
# Exit 2 (drift) stays green — the issue below tracks it. Exit 1
|
|
78
|
+
# (plan ERROR) must fail the run instead of going green-silent.
|
|
79
|
+
if [ "$EXITCODE" = "1" ]; then exit 1; fi
|
|
57
80
|
|
|
58
81
|
# A plan on never-applied infrastructure also exits 2 (everything
|
|
59
82
|
# "to add") — that is not drift. Skip the issue/Slack alarm when
|
|
@@ -73,7 +96,7 @@ jobs:
|
|
|
73
96
|
|
|
74
97
|
- name: Report drift as GitHub Issue
|
|
75
98
|
if: (steps.plan.outputs.exitcode == '2' || steps.plan.outputs.exitcode == '0') && steps.state.outputs.empty != 'true'
|
|
76
|
-
uses: actions/github-script@v7
|
|
99
|
+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
|
|
77
100
|
with:
|
|
78
101
|
script: |
|
|
79
102
|
const fs = require('fs');
|
|
@@ -113,6 +136,52 @@ jobs:
|
|
|
113
136
|
await github.rest.issues.createComment({ owner, repo, issue_number: existing.number, body: `✅ Drift resolved on \`${new Date().toISOString()}\` ([run](${runUrl})).` });
|
|
114
137
|
await github.rest.issues.update({ owner, repo, issue_number: existing.number, state: 'closed' });
|
|
115
138
|
}
|
|
139
|
+
// A 0/2 verdict means the check itself works: close any stale
|
|
140
|
+
// check-failure issue left by an earlier red run.
|
|
141
|
+
const { data: failed } = await github.rest.issues.listForRepo({ owner, repo, state: 'open', labels: 'iac-drift-check-failed' });
|
|
142
|
+
if (failed[0]) {
|
|
143
|
+
await github.rest.issues.createComment({ owner, repo, issue_number: failed[0].number, body: `✅ Drift check healthy again on \`${new Date().toISOString()}\` ([run](${runUrl})); closing.` });
|
|
144
|
+
await github.rest.issues.update({ owner, repo, issue_number: failed[0].number, state: 'closed' });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# Plan errors (exit 1) fail the run (see the plan step) AND leave a
|
|
148
|
+
# trackable issue under their own label — never green-silent.
|
|
149
|
+
- name: Report drift check failure as GitHub Issue
|
|
150
|
+
if: failure() && steps.plan.outputs.exitcode == '1'
|
|
151
|
+
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
|
|
152
|
+
with:
|
|
153
|
+
script: |
|
|
154
|
+
const fs = require('fs');
|
|
155
|
+
const { owner, repo } = context.repo;
|
|
156
|
+
const label = 'iac-drift-check-failed';
|
|
157
|
+
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${context.runId}`;
|
|
158
|
+
let diff = '';
|
|
159
|
+
try {
|
|
160
|
+
diff = fs.readFileSync('terraform/plan.txt', 'utf8');
|
|
161
|
+
} catch (error) {
|
|
162
|
+
diff = '(plan output unavailable)';
|
|
163
|
+
}
|
|
164
|
+
if (diff.length > 30000) {
|
|
165
|
+
diff = `${diff.slice(0, 30000)}\n... (truncated, see ${runUrl})`;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
await github.rest.issues.getLabel({ owner, repo, name: label });
|
|
169
|
+
} catch (error) {
|
|
170
|
+
if (error.status === 404) {
|
|
171
|
+
await github.rest.issues.createLabel({ owner, repo, name: label, color: 'd93f0b', description: 'Terraform drift check itself errored (plan exit 1)' });
|
|
172
|
+
} else {
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const { data: open } = await github.rest.issues.listForRepo({ owner, repo, state: 'open', labels: label });
|
|
177
|
+
const existing = open[0];
|
|
178
|
+
const body = `## ❌ Drift Check Failed\n\nThe scheduled drift check errored on \`${new Date().toISOString()}\` ([workflow run](${runUrl})) — this is a check failure, not drift.\n\n\`\`\`terraform\n${diff}\n\`\`\`\n\nFix the check (credentials, backend, syntax) and the issue closes on the next green run.`;
|
|
179
|
+
if (existing) {
|
|
180
|
+
await github.rest.issues.createComment({ owner, repo, issue_number: existing.number, body: `Check still failing on \`${new Date().toISOString()}\` ([run](${runUrl})).\n\n\`\`\`terraform\n${diff}\n\`\`\`` });
|
|
181
|
+
await github.rest.issues.update({ owner, repo, issue_number: existing.number, body });
|
|
182
|
+
} else {
|
|
183
|
+
await github.rest.issues.create({ owner, repo, title: '❌ IaC Drift Check Failed', labels: [label], body });
|
|
184
|
+
}
|
|
116
185
|
|
|
117
186
|
- name: Notify Slack
|
|
118
187
|
if: steps.plan.outputs.exitcode == '2' && steps.state.outputs.empty != 'true'
|