Skip to content

Commit f456e48

Browse files
Improve new flow
- Replace complicated bash script with python script - Better tooling - Python chosen as the same script can be used for different services with only minor tweaks - Ruby is specific to this repository - Handle any changes in environment variables without needing to modify script - Also use a version-controlled yml file to persist variables - This removes the use of parameter groups for changing variables wihtout code changes - Changing variables in a running system requires in any case a full approval flow - Add singel approval step for all deployments
1 parent 42cce7c commit f456e48

File tree

11 files changed

+318
-605
lines changed

11 files changed

+318
-605
lines changed

.github/workflows/deploy-application.yml

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ jobs:
6161
prepare-deployment:
6262
name: Prepare deployment
6363
runs-on: ubuntu-latest
64-
environment: ${{ inputs.environment }}
6564
permissions:
6665
id-token: write
6766
steps:
@@ -72,37 +71,27 @@ jobs:
7271
with:
7372
role-to-assume: ${{ env.aws-role }}
7473
aws-region: eu-west-2
75-
- name: Get image digest from ECR
76-
id: get-image-digest
77-
run: |
78-
# Get AWS account ID and construct repository URI
79-
AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
80-
REPOSITORY_URI="${AWS_ACCOUNT_ID}.dkr.ecr.eu-west-2.amazonaws.com/mavis/webapp"
81-
82-
# Get the image digest for the git SHA
83-
IMAGE_DIGEST=$(aws ecr describe-images \
84-
--repository-name mavis/webapp \
85-
--image-ids imageTag=${{ inputs.git_sha_to_deploy || github.sha }} \
86-
--query 'imageDetails[0].imageDigest' \
87-
--output text)
88-
89-
NEW_IMAGE_URI="${REPOSITORY_URI}@${IMAGE_DIGEST}"
90-
echo "new-image-uri=${NEW_IMAGE_URI}" >> $GITHUB_OUTPUT
91-
echo "New image URI: ${NEW_IMAGE_URI}"
74+
- name: Setup python
75+
uses: actions/setup-python@v4
76+
with:
77+
python-version: 3.12.3
78+
cache: pip
79+
- name: Install Python dependencies
80+
run: python3 -m pip install -r script/requirements.txt
9281
- name: Populate web task definition
9382
if: inputs.server_types == 'web' || inputs.server_types == 'all'
9483
id: render-web-task-definition
9584
run: |
96-
./script/populate_task_definition.sh ${{ inputs.environment }} web \
97-
-i "${{ steps.get-image-digest.outputs.new-image-uri }}" \
85+
python3 script/populate_task_definition.py ${{ inputs.environment }} web \
86+
-i "${{ inputs.git_sha_to_deploy || github.sha }}" \
9887
-o web-task-definition.json
9988
cat web-task-definition.json
10089
- name: Populate good-job task definition
10190
if: inputs.server_types == 'good-job' || inputs.server_types == 'all'
10291
id: render-good-job-task-definition
10392
run: |
104-
./script/populate_task_definition.sh ${{ inputs.environment }} good-job \
105-
-i "${{ steps.get-image-digest.outputs.new-image-uri }}" \
93+
python3 script/populate_task_definition.py ${{ inputs.environment }} good-job \
94+
-i "${{ inputs.git_sha_to_deploy || github.sha }}" \
10695
-o good-job-task-definition.json
10796
cat good-job-task-definition.json
10897
- name: Make artifact for web task definition
@@ -118,12 +107,19 @@ jobs:
118107
outputs:
119108
new-image-uri: ${{ steps.get-image-digest.outputs.new-image-uri }}
120109

110+
approve-deployments:
111+
name: Approve deployments
112+
runs-on: ubuntu-latest
113+
needs: prepare-deployment
114+
environment: ${{ inputs.environment }}
115+
steps:
116+
- run: echo "Proceeding with deployment to ${{ inputs.environment }} environment"
117+
121118
deploy-web:
122119
name: Deploy web service
123120
runs-on: ubuntu-latest
124121
if: inputs.server_types == 'web' || inputs.server_types == 'all'
125-
needs: prepare-deployment
126-
environment: ${{ inputs.environment }}
122+
needs: [ prepare-deployment, approve-deployments ]
127123
permissions:
128124
id-token: write
129125
steps:
@@ -167,8 +163,7 @@ jobs:
167163
name: Deploy good-job service
168164
runs-on: ubuntu-latest
169165
if: inputs.server_types == 'good-job' || inputs.server_types == 'all'
170-
needs: prepare-deployment
171-
environment: ${{ inputs.environment }}
166+
needs: [ prepare-deployment, approve-deployments ]
172167
permissions:
173168
id-token: write
174169
steps:

.github/workflows/deploy-mavis.yml

Lines changed: 0 additions & 243 deletions
This file was deleted.

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ terraform 1.11.4
66
tflint 0.55.1
77
pkl 0.28.1
88
hk 1.1.2
9+
python 3.12.3

0 commit comments

Comments
 (0)