Skip to content

Commit c62838f

Browse files
update production deploy and add rollback
1 parent 7d445a3 commit c62838f

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Rollback production
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
# Rollback job in case of failure (Revert production to the previous task definition)
8+
rollback:
9+
permissions:
10+
id-token: write
11+
contents: read
12+
name: Rollback to Previous Version
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version-file: ".nvmrc"
22+
cache: npm
23+
24+
- name: Configure AWS credentials from production account
25+
uses: aws-actions/configure-aws-credentials@v2
26+
with:
27+
role-to-assume: arn:aws:iam::946183545209:role/GithubActionsDeployerRole
28+
aws-region: us-east-1
29+
30+
- name: Login to Amazon ECR
31+
id: login-ecr
32+
uses: aws-actions/amazon-ecr-login@v2
33+
34+
- name: Pull and tag previous image
35+
env:
36+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
37+
ECR_REPOSITORY: discovery-api
38+
run: |
39+
docker pull $ECR_REGISTRY/$ECR_REPOSITORY:production-previous
40+
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:production-previous $ECR_REGISTRY/$ECR_REPOSITORY:production-latest
41+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:production-latest
42+
43+
- name: Force ECS Update
44+
run: |
45+
aws ecs update-service --cluster discovery-api-production --service discovery-api-production --force-new-deployment

.github/workflows/test-and-deploy.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ jobs:
115115
id: login-ecr
116116
uses: aws-actions/amazon-ecr-login@v1
117117

118+
- name: Back up previous image for rollback
119+
env:
120+
ECR_REPOSITORY: discovery-api
121+
run: |
122+
MANIFEST=$(aws ecr batch-get-image --repository-name $ECR_REPOSITORY --image-ids imageTag="production-latest" --output json | jq --raw-output --join-output '.images[0].imageManifest')
123+
aws ecr put-image --repository-name $ECR_REPOSITORY --image-tag "production-previous" --image-manifest "$MANIFEST"
124+
118125
- name: Build, tag, and push image to Amazon ECR
119126
env:
120127
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}

0 commit comments

Comments
 (0)