-
Notifications
You must be signed in to change notification settings - Fork 352
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add deployment workflows for staging and prod deployment
- Loading branch information
1 parent
f2b9a23
commit dcb7401
Showing
2 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
name: Prod Deployment | ||
on: | ||
push: | ||
branches: ['main'] | ||
workflow_dispatch: | ||
inputs: | ||
stage: | ||
description: 'Stage to deploy (production)' | ||
required: true | ||
run_production: | ||
description: 'Staging deployment completed (yes, no)' | ||
required: true | ||
|
||
jobs: | ||
deploy_prod: | ||
name: Prod Deployment | ||
permissions: | ||
id-token: write | ||
contents: write | ||
environment: prod | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'workflow_dispatch' && github.event.inputs.stage == 'production' && github.event.inputs.run_production == 'yes' | ||
env: | ||
AWS_REGION: eu-west-1 | ||
ECR_REPOSITORY: docs-ecr | ||
ECS_SERVICE: docs-ecs-service | ||
ECS_CLUSTER: frontend-prod-ecs-cluster | ||
ECS_TASK_DEFINITION: prod-taskdef.json | ||
CONTAINER_NAME: docs | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1-node16 | ||
with: | ||
aws-region: ${{ env.AWS_REGION }} | ||
role-to-assume: arn:aws:iam::042947190491:role/docs-GithubActionsRole | ||
role-session-name: GithubActionsSession | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Use Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: pip Install | ||
run: pip install -r requirements.txt --no-cache-dir | ||
|
||
- name: Build mkdocs | ||
run: mkdocs build | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.nginx . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $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: ${{ env.ECS_TASK_DEFINITION }} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: ${{ env.ECS_SERVICE }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
wait-for-service-stability: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Staging Deployment | ||
on: | ||
push: | ||
branches: ['main'] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy_staging: | ||
name: Staging Deployment | ||
permissions: | ||
id-token: write | ||
contents: write | ||
environment: staging | ||
runs-on: ubuntu-latest | ||
env: | ||
AWS_REGION: eu-west-1 | ||
ECR_REPOSITORY: docs-staging-ecr | ||
ECS_SERVICE: docs-staging-ecs-service | ||
ECS_CLUSTER: frontend-staging-ecs-cluster | ||
ECS_TASK_DEFINITION: staging-taskdef.json | ||
CONTAINER_NAME: docs-staging | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1-node16 | ||
with: | ||
aws-region: ${{ env.AWS_REGION }} | ||
role-to-assume: arn:aws:iam::070528468658:role/docs-staging-GithubActionsRole | ||
role-session-name: GithubActionsSession | ||
|
||
- name: Login to Amazon ECR | ||
id: login-ecr | ||
uses: aws-actions/amazon-ecr-login@v1 | ||
|
||
- name: Use Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
|
||
- name: pip Install | ||
run: pip install -r requirements.txt --no-cache-dir | ||
|
||
- name: Build mkdocs | ||
run: mkdocs build | ||
|
||
- name: Build, tag, and push image to Amazon ECR | ||
id: build-image | ||
env: | ||
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
IMAGE_TAG: ${{ github.sha }} | ||
run: | | ||
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.nginx . | ||
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $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: ${{ env.ECS_TASK_DEFINITION }} | ||
container-name: ${{ env.CONTAINER_NAME }} | ||
image: ${{ steps.build-image.outputs.image }} | ||
|
||
- name: Deploy Amazon ECS task definition | ||
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | ||
with: | ||
task-definition: ${{ steps.task-def.outputs.task-definition }} | ||
service: ${{ env.ECS_SERVICE }} | ||
cluster: ${{ env.ECS_CLUSTER }} | ||
wait-for-service-stability: true |