-
Notifications
You must be signed in to change notification settings - Fork 59
341 lines (301 loc) · 12.8 KB
/
Copy pathrelease.yml
File metadata and controls
341 lines (301 loc) · 12.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
name: Release
permissions: {}
on:
push:
branches:
- main
workflow_dispatch:
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
AWS_REGION: us-east-1
ECS_CLUSTER: argos-production
ECR_REPOSITORY: argos/app
ECR_CACHE_TAG: buildcache
ECS_TASK_ROLE_ARN: ${{ secrets.ECS_TASK_ROLE_ARN }}
ECS_TASK_EXECUTION_ROLE_ARN: ${{ secrets.ECS_TASK_EXECUTION_ROLE_ARN }}
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
id-token: write
contents: read
outputs:
image: ${{ steps.image.outputs.value }}
steps:
- name: Check out repository code
uses: actions/checkout@v6
- name: Notify deployment start
uses: ./.github/actions/notify-discord
continue-on-error: true
with:
webhook-url: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
title: "Production deployment started"
description: "[GitHub Actions run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- uses: docker/setup-buildx-action@v4
- name: Extract metadata
id: meta
uses: docker/metadata-action@v6
with:
images: ${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}
tags: |
type=sha,prefix=,format=long
type=ref,event=branch
type=semver,pattern={{version}}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.ECR_CACHE_TAG }}
cache-to: type=registry,ref=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ env.ECR_CACHE_TAG }},mode=max
secrets: |
TURBO_TOKEN=${{ secrets.TURBO_TOKEN }}
build-args: |
TURBO_TEAM=${{ vars.TURBO_TEAM }}
- name: Export image reference
id: image
run: echo "value=${{ steps.login-ecr.outputs.registry }}/${{ env.ECR_REPOSITORY }}:${{ github.sha }}" >> "$GITHUB_OUTPUT"
migrate:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: build
permissions:
id-token: write
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v6
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Prepare migration task definition
id: prepare-task-def
run: |
set -euo pipefail
PREPARED_TASK_DEF="$RUNNER_TEMP/argos-migrate.task-definition.json"
sed \
-e "s|__TASK_ROLE_ARN__|$ECS_TASK_ROLE_ARN|g" \
-e "s|__EXECUTION_ROLE_ARN__|$ECS_TASK_EXECUTION_ROLE_ARN|g" \
aws/tasks/argos-migrate.json > "$PREPARED_TASK_DEF"
echo "task-definition=$PREPARED_TASK_DEF" >> "$GITHUB_OUTPUT"
- name: Fill in task definition for migration
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.prepare-task-def.outputs.task-definition }}
container-name: argos-migrate
image: ${{ needs.build.outputs.image }}
environment-variables: |
NODE_ENV=production
secrets: |
DATABASE_URL=/production/database_url
ENCRYPTION_KEY=/production/encryption_key
- name: Run ECS migration task
env:
TASK_DEF_FILE: ${{ steps.task-def.outputs.task-definition }}
run: |
set -euo pipefail
TASK_DEF_ARN=$(aws ecs register-task-definition \
--cli-input-json "file://$TASK_DEF_FILE" \
--query 'taskDefinition.taskDefinitionArn' \
--output text)
SUBNETS=$(aws ecs describe-services \
--cluster "$ECS_CLUSTER" \
--services argos-app \
--query 'services[0].networkConfiguration.awsvpcConfiguration.subnets' \
--output json | jq -r 'join(",")')
SECURITY_GROUPS=$(aws ecs describe-services \
--cluster "$ECS_CLUSTER" \
--services argos-app \
--query 'services[0].networkConfiguration.awsvpcConfiguration.securityGroups' \
--output json | jq -r 'join(",")')
ASSIGN_PUBLIC_IP=$(aws ecs describe-services \
--cluster "$ECS_CLUSTER" \
--services argos-app \
--query 'services[0].networkConfiguration.awsvpcConfiguration.assignPublicIp' \
--output text)
TASK_ARN=$(aws ecs run-task \
--cluster "$ECS_CLUSTER" \
--task-definition "$TASK_DEF_ARN" \
--launch-type FARGATE \
--network-configuration "awsvpcConfiguration={subnets=[$SUBNETS],securityGroups=[$SECURITY_GROUPS],assignPublicIp=$ASSIGN_PUBLIC_IP}" \
--started-by "github-actions-release-${GITHUB_RUN_ID}" \
--query 'tasks[0].taskArn' \
--output text)
aws ecs wait tasks-stopped --cluster "$ECS_CLUSTER" --tasks "$TASK_ARN"
EXIT_CODE=$(aws ecs describe-tasks \
--cluster "$ECS_CLUSTER" \
--tasks "$TASK_ARN" \
--query 'tasks[0].containers[0].exitCode' \
--output text)
if [ "$EXIT_CODE" != "0" ]; then
echo "Migration task failed with exit code: $EXIT_CODE"
exit 1
fi
deploy:
runs-on: ubuntu-latest
timeout-minutes: 20
needs: [build, migrate]
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
include:
- service: argos-app
task-definition: aws/tasks/argos-app.json
container-name: argos-app
- service: argos-worker
task-definition: aws/tasks/argos-worker.json
container-name: argos-worker
steps:
- name: Check out repository code
uses: actions/checkout@v6
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}
- name: Prepare task definition
id: prepare-task-def
run: |
set -euo pipefail
PREPARED_TASK_DEF="$RUNNER_TEMP/${{ matrix.container-name }}.task-definition.json"
sed \
-e "s|__TASK_ROLE_ARN__|$ECS_TASK_ROLE_ARN|g" \
-e "s|__EXECUTION_ROLE_ARN__|$ECS_TASK_EXECUTION_ROLE_ARN|g" \
"${{ matrix.task-definition }}" > "$PREPARED_TASK_DEF"
echo "task-definition=$PREPARED_TASK_DEF" >> "$GITHUB_OUTPUT"
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.prepare-task-def.outputs.task-definition }}
container-name: ${{ matrix.container-name }}
image: ${{ needs.build.outputs.image }}
environment-variables: |
NODE_ENV=production
API_BASE_URL=https://api.argos-ci.com
SERVER_URL=https://app.argos-ci.com
SENTRY_RELEASE_VERSION=${{ github.sha }}
secrets: |
AMQP_URL=/production/amqp_url
AWS_ACCESS_KEY_ID=/production/aws_access_key_id
AWS_SECRET_ACCESS_KEY=/production/aws_secret_access_key
DATABASE_URL=/production/database_url
DEPLOYMENTS_CLOUDFLARE_ZONE_ID=/production/deployments_cloudflare_zone_id
DEPLOYMENTS_CLOUDFLARE_API_TOKEN=/production/deployments_cloudflare_api_token
DEPLOYMENTS_ACCESS_TOKEN_SECRET=/production/deployments_access_token_secret
DISCORD_WEBHOOK_URL=/production/discord_webhook_url
ENCRYPTION_KEY=/production/encryption_key
GITHUB_APP_ID=/production/github_app_id
GITHUB_APP_PRIVATE_KEY=/production/github_app_private_key
GITHUB_APP_URL=/production/github_app_url
GITHUB_CLIENT_ID=/production/github_client_id
GITHUB_CLIENT_SECRET=/production/github_client_secret
GITHUB_LIGHT_APP_ID=/production/github_light_app_id
GITHUB_LIGHT_APP_PRIVATE_KEY=/production/github_light_app_private_key
GITHUB_LIGHT_APP_URL=/production/github_light_app_url
GITHUB_LIGHT_WEBHOOK_SECRET=/production/github_light_webhook_secret
GITHUB_PROXY_URL=/production/github_proxy_url
GITHUB_SSO_STRIPE_PRODUCT_ID=/production/github_sso_stripe_product_id
GITHUB_WEBHOOK_SECRET=/production/github_webhook_secret
GITLAB_APP_ID=/production/gitlab_app_id
GITLAB_APP_SECRET=/production/gitlab_app_secret
GITLAB_ARGOS_AUTH_SECRET=/production/gitlab_argos_auth_secret
GOOGLE_CLIENT_ID=/production/google_client_id
GOOGLE_CLIENT_SECRET=/production/google_client_secret
REDIS_URL=/production/redis_url
RESEND_API_KEY=/production/resend_api_key
RESEND_WEBHOOK_SECRET=/production/resend_webhook_secret
SCREENSHOT_STRIPE_PRODUCT_ID=/production/screenshot_stripe_product_id
SENTRY_AUTH_TOKEN=/production/sentry_auth_token
SENTRY_CLIENT_DSN=/production/sentry_client_dsn
SENTRY_SERVER_DSN=/production/sentry_server_dsn
SERVER_SESSION_SECRET=/production/server_session_secret
SLACK_CLIENT_ID=/production/slack_client_id
SLACK_CLIENT_SECRET=/production/slack_client_secret
SLACK_SIGNING_SECRET=/production/slack_signing_secret
SLACK_STATE_SECRET=/production/slack_state_secret
SQIDS_ALPHABET=/production/sqids_alphabet
STORYBOOK_SCREENSHOT_STRIPE_PRODUCT_ID=/production/storybook_screenshot_stripe_product_id
STRIPE_API_KEY=/production/stripe_api_key
STRIPE_WEBHOOK_SECRET=/production/stripe_webhook_secret
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ matrix.service }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
notify-migration-failure:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: migrate
if: ${{ always() && needs.migrate.result == 'failure' }}
permissions:
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v6
- name: Notify migration failure
uses: ./.github/actions/notify-discord
continue-on-error: true
with:
webhook-url: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
title: "Production migration failed"
description: "Migration failed - [GitHub Actions logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
color: "15548997"
notify-deploy-failure:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: deploy
if: ${{ always() && needs.deploy.result == 'failure' }}
permissions:
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v6
- name: Notify deployment failure
uses: ./.github/actions/notify-discord
continue-on-error: true
with:
webhook-url: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
title: "Production deployment failed"
description: "Deploy failed - [GitHub Actions logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
color: "15548997"
notify-success:
runs-on: ubuntu-latest
timeout-minutes: 5
needs: deploy
if: ${{ needs.deploy.result == 'success' }}
permissions:
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v6
- name: Notify deployment success
uses: ./.github/actions/notify-discord
continue-on-error: true
with:
webhook-url: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }}
title: "Production deployment succeeded"
description: "[GitHub Actions run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
color: "5763719"