Skip to content

Commit 8fbea69

Browse files
committed
Add input for git tag to deployment pipelines
* We want to restrict the IAM role used by the Github workflows such that it can only be assumed from the main and release branches. * This causes the problem that deployment workflows run from tags could not assume the role anymore * To mitigate this issue, this PR allows to specify the git tag that shall be deployed in a dedicated field. While the workflow can be run from main or release, this still allows to deploy a specific git tag. If no value is set, it defaults to the regular behaviour.
1 parent 4d87d25 commit 8fbea69

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

.github/workflows/build-and-push-image.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ name: Build and push image
33
on:
44
workflow_dispatch:
55
workflow_call:
6+
inputs:
7+
git-sha:
8+
description: The git commit sha to build the image from.
9+
type: string
610

711
concurrency:
8-
group: build-and-push-image-${{ github.sha }}
12+
group: build-and-push-image-${{ inputs.git-sha || github.sha }}
913

1014
jobs:
1115
check-image-presence:
@@ -23,7 +27,7 @@ jobs:
2327
aws-region: eu-west-2
2428
- name: Check if dev image exists
2529
run: |
26-
if aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag=${{ github.sha }} > /dev/null 2>&1; then
30+
if aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag=${{ inputs.git-sha || github.sha }} > /dev/null 2>&1; then
2731
echo "Dev image with given tag already exists"
2832
else
2933
echo "Dev image does not exist. Build needed"
@@ -37,7 +41,7 @@ jobs:
3741
- name: Check if production image exists
3842
id: check-image
3943
run: |
40-
if [ -e $BUILD_NEEDED ] && aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag=${{ github.sha }} > /dev/null 2>&1; then
44+
if [ -e $BUILD_NEEDED ] && aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag=${{ inputs.git-sha || github.sha }} > /dev/null 2>&1; then
4145
echo "Production and dev images with given tag already exist. No build needed"
4246
else
4347
echo "At least one image does not exist. Build needed"

.github/workflows/deploy-application.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ jobs:
5959
steps:
6060
- name: Checkout code
6161
uses: actions/checkout@v4
62+
with:
63+
ref: ${{ inputs.image_tag || github.sha }}
6264
- name: Configure AWS Credentials
6365
uses: aws-actions/configure-aws-credentials@v4
6466
with:

.github/workflows/deploy-infrastructure.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ run-name: Deploy infrastructure for ${{ inputs.environment }}
44
on:
55
workflow_dispatch:
66
inputs:
7+
git-sha:
8+
description: The git commit sha of the commit to deploy.
9+
type: string
710
environment:
811
description: Deployment environment
912
required: true
@@ -22,6 +25,9 @@ on:
2225
type: string
2326
workflow_call:
2427
inputs:
28+
git-sha:
29+
description: The git commit sha of the commit to deploy.
30+
type: string
2531
environment:
2632
description: Deployment environment
2733
required: true
@@ -48,6 +54,8 @@ jobs:
4854
steps:
4955
- name: Checkout code
5056
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ inputs.git_sha || github.sha }}
5159
- name: Configure AWS Credentials
5260
uses: aws-actions/configure-aws-credentials@v4
5361
with:

.github/workflows/deploy.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,41 @@ on:
3636
- web
3737
- good-job
3838
default: all
39+
git_tag:
40+
description: Git tag to deploy
41+
required: false
42+
type: string
3943

4044
jobs:
45+
determine-git-sha:
46+
runs-on: ubuntu-latest
47+
outputs:
48+
git-sha: ${{ steps.get-git-sha.outputs.git-sha }}
49+
steps:
50+
- name: Get git sha
51+
id: get-git-sha
52+
run: |
53+
if [ -z "${{ inputs.git_tag }}" ]; then
54+
echo "No git tag provided. Using the latest commit sha"
55+
echo "git-sha=${{ github.sha }}" >> $GITHUB_OUTPUT
56+
else
57+
echo "Git tag provided. Using the sha of the tagged commit"
58+
echo "git-sha=$(git rev-parse ${{ inputs.git_tag }})" >> $GITHUB_OUTPUT
59+
fi
4160
build-and-push-image:
4261
uses: ./.github/workflows/build-and-push-image.yml
62+
with:
63+
git-sha: ${{ determine-git-sha.outputs.git-sha || github.sha }}
4364
deploy-infrastructure:
4465
needs: build-and-push-image
4566
uses: ./.github/workflows/deploy-infrastructure.yml
4667
with:
4768
environment: ${{ inputs.environment }}
69+
git-sha: ${{ determine-git-sha.outputs.git-sha || github.sha }}
4870
deploy-application:
4971
needs: deploy-infrastructure
5072
uses: ./.github/workflows/deploy-application.yml
5173
with:
5274
environment: ${{ inputs.environment }}
53-
image_tag: ${{ github.sha }}
75+
image_tag: ${{ determine-git-sha.outputs.git-sha || github.sha }}
5476
server_types: ${{ inputs.server_types }}

0 commit comments

Comments
 (0)