File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,9 +3,13 @@ name: Build and push image
33on :
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
711concurrency :
8- group : build-and-push-image-${{ github.sha }}
12+ group : build-and-push-image-${{ inputs.git-sha || github.sha }}
913
1014jobs :
1115 check-image-presence :
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"
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"
Original file line number Diff line number Diff line change 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 :
Original file line number Diff line number Diff line change @@ -4,6 +4,9 @@ run-name: Deploy infrastructure for ${{ inputs.environment }}
44on :
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
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
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 :
Original file line number Diff line number Diff line change 3636 - web
3737 - good-job
3838 default : all
39+ git_tag :
40+ description : Git tag to deploy
41+ required : false
42+ type : string
3943
4044jobs :
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 }}
You can’t perform that action at this time.
0 commit comments