Skip to content

Commit 9ef3832

Browse files
authored
Post release2.1.3 actions (#3427)
This is required to support potential hotfixes of v2.1.3
2 parents 260a38b + c959f94 commit 9ef3832

File tree

6 files changed

+53
-289
lines changed

6 files changed

+53
-289
lines changed

.github/workflows/deploy-application.yml

Lines changed: 29 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ on:
1616
- preview
1717
- training
1818
- production
19-
image_tag:
20-
description: Docker image tag
21-
required: false
22-
type: string
2319
server_types:
2420
description: Server types to deploy
2521
required: true
@@ -34,9 +30,6 @@ on:
3430
environment:
3531
required: true
3632
type: string
37-
image_tag:
38-
required: false
39-
type: string
4033
server_types:
4134
required: true
4235
type: string
@@ -48,60 +41,11 @@ env:
4841
aws-role: ${{ inputs.environment == 'production'
4942
&& 'arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure'
5043
|| 'arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure' }}
51-
terraform-working-directory: terraform/app
5244

5345
jobs:
54-
plan-changes:
55-
name: Plan task definition changes
56-
runs-on: ubuntu-latest
57-
permissions:
58-
id-token: write
59-
steps:
60-
- name: Checkout code
61-
uses: actions/checkout@v4
62-
- name: Configure AWS Credentials
63-
uses: aws-actions/configure-aws-credentials@v4
64-
with:
65-
role-to-assume: ${{ env.aws-role }}
66-
aws-region: eu-west-2
67-
- name: Login to ECR
68-
id: login-ecr
69-
uses: aws-actions/amazon-ecr-login@v2
70-
- name: pull docker image
71-
run: |
72-
DOCKER_IMAGE="${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ inputs.image_tag || github.sha }}"
73-
docker pull "$DOCKER_IMAGE"
74-
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> $GITHUB_ENV
75-
- name: Extract image digest
76-
run: |
77-
DOCKER_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$DOCKER_IMAGE")
78-
DIGEST="${DOCKER_DIGEST#*@}"
79-
echo "DIGEST=$DIGEST" >> $GITHUB_ENV
80-
- name: Install terraform
81-
uses: hashicorp/setup-terraform@v3
82-
with:
83-
terraform_version: 1.10.5
84-
- name: Update the task definition
85-
id: plan
86-
working-directory: ${{ env.terraform-working-directory }}
87-
run: |
88-
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
89-
terraform plan -var-file="env/${{ inputs.environment }}.tfvars" \
90-
-var="image_digest=$DIGEST" -out=${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
91-
- name: Validate the changes
92-
run: |
93-
./terraform/scripts/check_task_definition.sh ${{ runner.temp }}/tf_stdout
94-
- name: Upload artifact
95-
uses: actions/upload-artifact@v4
96-
with:
97-
name: tfplan_app-${{ inputs.environment }}
98-
path: ${{ runner.temp }}/tfplan
99-
100-
apply-changes:
101-
name: Apply task definition changes
46+
prepare-deployment:
47+
name: Prepare deployment
10248
runs-on: ubuntu-latest
103-
needs: plan-changes
104-
environment: ${{ inputs.environment }}
10549
permissions:
10650
id-token: write
10751
steps:
@@ -112,26 +56,25 @@ jobs:
11256
with:
11357
role-to-assume: ${{ env.aws-role }}
11458
aws-region: eu-west-2
115-
- name: Download artifact
116-
uses: actions/download-artifact@v4
117-
with:
118-
name: tfplan_app-${{ inputs.environment }}
119-
path: ${{ runner.temp }}
12059
- name: Install terraform
12160
uses: hashicorp/setup-terraform@v3
12261
with:
12362
terraform_version: 1.10.5
124-
- name: Apply the changes
125-
working-directory: ${{ env.terraform-working-directory }}
63+
- name: Get terraform output
64+
id: terraform-output
65+
working-directory: terraform/app
12666
run: |
127-
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
128-
terraform apply ${{ runner.temp }}/tfplan
129-
echo "s3_bucket=$(terraform output -raw s3_bucket)" >> ${{ runner.temp }}/DEPLOYMENT_ENVS
130-
echo "s3_key=$(terraform output -raw s3_key)" >> ${{ runner.temp }}/DEPLOYMENT_ENVS
131-
echo "application=$(terraform output -raw codedeploy_application_name)" >> ${{ runner.temp }}/DEPLOYMENT_ENVS
132-
echo "application_group=$(terraform output -raw codedeploy_deployment_group_name)" >> ${{ runner.temp }}/DEPLOYMENT_ENVS
133-
echo "ecs_variables=$(terraform output -json ecs_variables | sed 's/\"/\\"/g')" >> ${{ runner.temp }}/DEPLOYMENT_ENVS
134-
- name: Upload artifact
67+
terraform init -backend-config=env/${{ inputs.environment }}-backend.hcl -reconfigure
68+
terraform output -json | jq -r '
69+
"s3_bucket=" + .s3_bucket.value,
70+
"s3_key=" + .s3_key.value,
71+
"application=" + .codedeploy_application_name.value,
72+
"application_group=" + .codedeploy_deployment_group_name.value,
73+
"cluster_name=" + .ecs_variables.value.cluster_name,
74+
"good_job_service=" + .ecs_variables.value.good_job.service_name,
75+
"good_job_task_definition=" + .ecs_variables.value.good_job.task_definition.arn
76+
' > ${{ runner.temp }}/DEPLOYMENT_ENVS
77+
- name: Upload Artifact
13578
uses: actions/upload-artifact@v4
13679
with:
13780
name: DEPLOYMENT_ENVS-${{ inputs.environment }}
@@ -140,7 +83,7 @@ jobs:
14083
create-web-deployment:
14184
name: Create web deployment
14285
runs-on: ubuntu-latest
143-
needs: apply-changes
86+
needs: prepare-deployment
14487
if: inputs.server_types == 'web' || inputs.server_types == 'all'
14588
environment: ${{ inputs.environment }}
14689
permissions:
@@ -150,41 +93,39 @@ jobs:
15093
uses: actions/download-artifact@v4
15194
with:
15295
name: DEPLOYMENT_ENVS-${{ inputs.environment }}
153-
path: ${{ runner.temp }}/artifact
96+
path: ${{ runner.temp }}
15497
- name: Configure AWS Credentials
15598
uses: aws-actions/configure-aws-credentials@v4
15699
with:
157100
role-to-assume: ${{ env.aws-role }}
158101
aws-region: eu-west-2
159-
- name: Install AWS CLI
160-
run: sudo snap install --classic aws-cli
161102
- name: Trigger CodeDeploy deployment
162103
run: |
163-
source ${{ runner.temp }}/artifact/DEPLOYMENT_ENVS
104+
source ${{ runner.temp }}/DEPLOYMENT_ENVS
164105
deployment_id=$(aws deploy create-deployment \
165106
--application-name "$application" --deployment-group-name "$application_group" \
166107
--s3-location bucket="$s3_bucket",key="$s3_key",bundleType=yaml | jq -r .deploymentId)
167108
echo "Deployment started: $deployment_id"
168109
echo "deployment_id=$deployment_id" >> $GITHUB_ENV
169110
- name: Wait up to 30 minutes for deployment to complete
170111
run: |
171-
aws deploy wait deployment-successful --deployment-id $deployment_id
112+
aws deploy wait deployment-successful --deployment-id "$deployment_id"
172113
echo "Deployment successful"
173114
174115
create-good-job-deployment:
175116
name: Create good-job deployment
176117
runs-on: ubuntu-latest
177-
needs: apply-changes
178-
if: inputs.server_types == 'good-job' || inputs.server_types == 'all'
118+
needs: prepare-deployment
119+
if: inputs.server_types == 'good-job' || inputs.server_types == 'all'
179120
environment: ${{ inputs.environment }}
180121
permissions:
181122
id-token: write
182123
steps:
183-
- name: Download artifact
124+
- name: Download Artifact
184125
uses: actions/download-artifact@v4
185126
with:
186127
name: DEPLOYMENT_ENVS-${{ inputs.environment }}
187-
path: ${{ runner.temp }}/artifact
128+
path: ${{ runner.temp }}
188129
- name: Configure AWS Credentials
189130
uses: aws-actions/configure-aws-credentials@v4
190131
with:
@@ -194,26 +135,20 @@ jobs:
194135
run: sudo snap install --classic aws-cli
195136
- name: Trigger ECS Deployment
196137
run: |
197-
source ${{ runner.temp }}/artifact/DEPLOYMENT_ENVS
198-
echo "$ecs_variables"
199-
cluster_name=$(echo "$ecs_variables" | jq -r '.cluster_name')
200-
service_name=$(echo "$ecs_variables" | jq -r '.good_job.service_name')
201-
task_definition=$(echo "$ecs_variables" | jq -r '.good_job.task_definition.arn')
202-
DEPLOYMENT_ID=$(aws ecs update-service --cluster $cluster_name --service $service_name \
203-
--task-definition $task_definition --force-new-deployment \
138+
source ${{ runner.temp }}/DEPLOYMENT_ENVS
139+
DEPLOYMENT_ID=$(aws ecs update-service --cluster $cluster_name --service $good_job_service \
140+
--task-definition $good_job_task_definition --force-new-deployment \
204141
--query 'service.deployments[?rolloutState==`IN_PROGRESS`].[id][0]' --output text)
205142
echo "Deployment started: $DEPLOYMENT_ID"
206143
echo "deployment_id=$DEPLOYMENT_ID" >> $GITHUB_ENV
207144
- name: Wait for deployment to complete
208145
run: |
209-
source ${{ runner.temp }}/artifact/DEPLOYMENT_ENVS
210-
cluster_name=$(echo "$ecs_variables" | jq -r '.cluster_name')
211-
service_name=$(echo "$ecs_variables" | jq -r '.good_job.service_name')
146+
source ${{ runner.temp }}/DEPLOYMENT_ENVS
212147
DEPLOYMENT_STATE=IN_PROGRESS
213148
while [ "$DEPLOYMENT_STATE" == "IN_PROGRESS" ]; do
214149
echo "Waiting for deployment to complete..."
215150
sleep 30
216-
DEPLOYMENT_STATE="$(aws ecs describe-services --cluster $cluster_name --services $service_name \
151+
DEPLOYMENT_STATE="$(aws ecs describe-services --cluster $cluster_name --services $good_job_service \
217152
--query "services[0].deployments[?id == \`$deployment_id\`].[rolloutState][0]" --output text)"
218153
done
219154
if [ "$DEPLOYMENT_STATE" != "COMPLETED" ]; then

.github/workflows/deploy-infrastructure.yml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ on:
1616
- preview
1717
- training
1818
- production
19-
docker_sha:
20-
description: "Docker image sha to deploy. This is used only if no existing task definition is found"
19+
image_tag:
20+
description: Docker image tag to deploy
2121
required: false
2222
type: string
2323
workflow_call:
@@ -26,6 +26,9 @@ on:
2626
description: Deployment environment
2727
required: true
2828
type: string
29+
image_tag:
30+
required: false
31+
type: string
2932

3033
concurrency:
3134
group: deploy-infrastructure-${{ inputs.environment }}
@@ -53,30 +56,36 @@ jobs:
5356
with:
5457
role-to-assume: ${{ env.aws_role }}
5558
aws-region: eu-west-2
59+
- name: Set image tag
60+
run: |
61+
IMAGE_TAG="${{ inputs.image_tag || github.sha }}"
62+
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
63+
- name: Login to ECR
64+
id: login-ecr
65+
uses: aws-actions/amazon-ecr-login@v2
66+
- name: Pull Docker image
67+
run: |
68+
DOCKER_IMAGE="${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${IMAGE_TAG}"
69+
docker pull "$DOCKER_IMAGE"
70+
echo "DOCKER_IMAGE=$DOCKER_IMAGE" >> $GITHUB_ENV
71+
- name: Extract image digest
72+
run: |
73+
DOCKER_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' "$DOCKER_IMAGE")
74+
DIGEST="${DOCKER_DIGEST#*@}"
75+
echo "DIGEST=$DIGEST" >> $GITHUB_ENV
5676
- name: Install terraform
5777
uses: hashicorp/setup-terraform@v3
5878
with:
5979
terraform_version: 1.10.5
60-
- name: Install AWS Cli
80+
- name: Install AWS CLI
6181
run: sudo snap install --classic aws-cli
6282
- name: Check if any deployments are running
6383
run: ../scripts/check-for-running-deployments.sh ${{ inputs.environment }}
64-
- name: Get image digest
65-
run: |
66-
DIGEST="${{ inputs.docker_sha }}"
67-
if terraform state list | grep -q 'aws_ecs_task_definition.task_definition'; then
68-
DIGEST=$(terraform state show aws_ecs_task_definition.task_definition | grep -oP '(?<=mavis/webapp@)sha256:[0-9a-z]{64}')
69-
echo "Existing task definition found, using image digest from the state: $DIGEST"
70-
elif [ -z "$DIGEST" ]; then
71-
echo "Aborting infrastructure deployment: Missing existing task definition or image digest input parameter"
72-
else
73-
echo "No existing task definition found: Using image digest from the input parameter: $DIGEST"
74-
fi
75-
echo "DIGEST=$DIGEST" >> $GITHUB_ENV
7684
- name: Terraform Plan
7785
id: plan
7886
run: |
7987
set -e
88+
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
8089
terraform plan -var="image_digest=$DIGEST" -var-file="env/${{ inputs.environment }}.tfvars" \
8190
-out ${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
8291
- name: Validate the changes

.github/workflows/deploy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ jobs:
5050
uses: ./.github/workflows/deploy-application.yml
5151
with:
5252
environment: ${{ inputs.environment }}
53-
image_tag: ${{ github.sha }}
5453
server_types: ${{ inputs.server_types }}

0 commit comments

Comments
 (0)