Skip to content

Commit dcb7401

Browse files
committed
add deployment workflows for staging and prod deployment
1 parent f2b9a23 commit dcb7401

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Prod Deployment
2+
on:
3+
push:
4+
branches: ['main']
5+
workflow_dispatch:
6+
inputs:
7+
stage:
8+
description: 'Stage to deploy (production)'
9+
required: true
10+
run_production:
11+
description: 'Staging deployment completed (yes, no)'
12+
required: true
13+
14+
jobs:
15+
deploy_prod:
16+
name: Prod Deployment
17+
permissions:
18+
id-token: write
19+
contents: write
20+
environment: prod
21+
runs-on: ubuntu-latest
22+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.stage == 'production' && github.event.inputs.run_production == 'yes'
23+
env:
24+
AWS_REGION: eu-west-1
25+
ECR_REPOSITORY: docs-ecr
26+
ECS_SERVICE: docs-ecs-service
27+
ECS_CLUSTER: frontend-prod-ecs-cluster
28+
ECS_TASK_DEFINITION: prod-taskdef.json
29+
CONTAINER_NAME: docs
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
with:
34+
submodules: true
35+
36+
- name: Configure AWS credentials
37+
uses: aws-actions/configure-aws-credentials@v1-node16
38+
with:
39+
aws-region: ${{ env.AWS_REGION }}
40+
role-to-assume: arn:aws:iam::042947190491:role/docs-GithubActionsRole
41+
role-session-name: GithubActionsSession
42+
43+
- name: Login to Amazon ECR
44+
id: login-ecr
45+
uses: aws-actions/amazon-ecr-login@v1
46+
47+
- name: Use Python
48+
uses: actions/setup-python@v4
49+
with:
50+
python-version: '3.11'
51+
52+
- name: pip Install
53+
run: pip install -r requirements.txt --no-cache-dir
54+
55+
- name: Build mkdocs
56+
run: mkdocs build
57+
58+
- name: Build, tag, and push image to Amazon ECR
59+
id: build-image
60+
env:
61+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
62+
IMAGE_TAG: ${{ github.sha }}
63+
run: |
64+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.nginx .
65+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
66+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
67+
68+
- name: Fill in the new image ID in the Amazon ECS task definition
69+
id: task-def
70+
uses: aws-actions/amazon-ecs-render-task-definition@v1
71+
with:
72+
task-definition: ${{ env.ECS_TASK_DEFINITION }}
73+
container-name: ${{ env.CONTAINER_NAME }}
74+
image: ${{ steps.build-image.outputs.image }}
75+
76+
- name: Deploy Amazon ECS task definition
77+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
78+
with:
79+
task-definition: ${{ steps.task-def.outputs.task-definition }}
80+
service: ${{ env.ECS_SERVICE }}
81+
cluster: ${{ env.ECS_CLUSTER }}
82+
wait-for-service-stability: true
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Staging Deployment
2+
on:
3+
push:
4+
branches: ['main']
5+
workflow_dispatch:
6+
7+
jobs:
8+
deploy_staging:
9+
name: Staging Deployment
10+
permissions:
11+
id-token: write
12+
contents: write
13+
environment: staging
14+
runs-on: ubuntu-latest
15+
env:
16+
AWS_REGION: eu-west-1
17+
ECR_REPOSITORY: docs-staging-ecr
18+
ECS_SERVICE: docs-staging-ecs-service
19+
ECS_CLUSTER: frontend-staging-ecs-cluster
20+
ECS_TASK_DEFINITION: staging-taskdef.json
21+
CONTAINER_NAME: docs-staging
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
submodules: true
27+
28+
- name: Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v1-node16
30+
with:
31+
aws-region: ${{ env.AWS_REGION }}
32+
role-to-assume: arn:aws:iam::070528468658:role/docs-staging-GithubActionsRole
33+
role-session-name: GithubActionsSession
34+
35+
- name: Login to Amazon ECR
36+
id: login-ecr
37+
uses: aws-actions/amazon-ecr-login@v1
38+
39+
- name: Use Python
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: '3.11'
43+
44+
- name: pip Install
45+
run: pip install -r requirements.txt --no-cache-dir
46+
47+
- name: Build mkdocs
48+
run: mkdocs build
49+
50+
- name: Build, tag, and push image to Amazon ECR
51+
id: build-image
52+
env:
53+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
54+
IMAGE_TAG: ${{ github.sha }}
55+
run: |
56+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.nginx .
57+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
58+
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
59+
60+
- name: Fill in the new image ID in the Amazon ECS task definition
61+
id: task-def
62+
uses: aws-actions/amazon-ecs-render-task-definition@v1
63+
with:
64+
task-definition: ${{ env.ECS_TASK_DEFINITION }}
65+
container-name: ${{ env.CONTAINER_NAME }}
66+
image: ${{ steps.build-image.outputs.image }}
67+
68+
- name: Deploy Amazon ECS task definition
69+
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
70+
with:
71+
task-definition: ${{ steps.task-def.outputs.task-definition }}
72+
service: ${{ env.ECS_SERVICE }}
73+
cluster: ${{ env.ECS_CLUSTER }}
74+
wait-for-service-stability: true

0 commit comments

Comments
 (0)