1- name : Build and push image
2- run-name : Build and push image for ${{ inputs.git-sha || github.sha }}
1+ name : Build and push images
2+ run-name : Build and push images for ${{ inputs.git-sha || github.sha }}
33
44on :
55 workflow_dispatch :
@@ -26,10 +26,15 @@ jobs:
2626 check-image-presence :
2727 name : Check if images already exist
2828 runs-on : ubuntu-latest
29+ strategy :
30+ fail-fast : true
31+ matrix :
32+ image_type : ["webapp", "ops"]
2933 permissions :
3034 id-token : write
3135 outputs :
32- build-needed : ${{ steps.check-dev-image.outputs.build-needed || steps.check-prod-image.outputs.build-needed }}
36+ webapp-build-needed : ${{ steps.check-dev-image.outputs.webapp-build-needed || steps.check-prod-image.outputs.webapp-build-needed }}
37+ ops-build-needed : ${{ steps.check-dev-image.outputs.ops-build-needed || steps.check-prod-image.outputs.ops-build-needed }}
3338 steps :
3439 - name : Configure AWS Dev Credentials
3540 uses : aws-actions/configure-aws-credentials@v5
@@ -39,11 +44,11 @@ jobs:
3944 - name : Check if dev image exists
4045 id : check-dev-image
4146 run : |
42- if aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag=$git_ref > /dev/null 2>&1; then
47+ if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids imageTag=$git_ref > /dev/null 2>&1; then
4348 echo "Dev image with given tag already exists"
4449 else
4550 echo "Dev image does not exist. Build needed"
46- echo "build-needed=true" >> $GITHUB_OUTPUT
51+ echo "${{ matrix.image_type }}- build-needed=true" >> $GITHUB_OUTPUT
4752 fi
4853 - name : Configure AWS Production credentials
4954 if : env.PUSH_IMAGE_TO_PRODUCTION == 'true'
@@ -55,33 +60,12 @@ jobs:
5560 if : env.PUSH_IMAGE_TO_PRODUCTION == 'true'
5661 id : check-prod-image
5762 run : |
58- if aws ecr describe-images --repository-name mavis/webapp --image-ids imageTag=$git_ref > /dev/null 2>&1; then
63+ if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids imageTag=$git_ref > /dev/null 2>&1; then
5964 echo "Production image with given tag already exists"
6065 else
6166 echo "Production image does not exist. Build needed"
62- echo "build-needed=true" >> $GITHUB_OUTPUT
67+ echo "${{ matrix.image_type }}- build-needed=true" >> $GITHUB_OUTPUT
6368 fi
64-
65- build :
66- needs : check-image-presence
67- if : needs.check-image-presence.outputs.build-needed == 'true'
68- runs-on : ubuntu-latest
69- steps :
70- - name : Checkout code
71- uses : actions/checkout@v5
72- with :
73- ref : ${{ env.git_ref }}
74- - name : Write build SHA
75- run : git rev-parse HEAD > public/sha
76- - name : Build Docker image
77- run : docker build -t "mavis:latest" .
78- - name : Save Docker image
79- run : docker save -o image.tar mavis:latest
80- - name : Upload Docker image
81- uses : actions/upload-artifact@v4
82- with :
83- name : image
84- path : image.tar
8569 define-matrix :
8670 name : Determine AWS roles to push the image
8771 runs-on : ubuntu-latest
9781 else
9882 echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure"]' >> $GITHUB_OUTPUT
9983 fi
84+ build :
85+ needs : check-image-presence
86+ if : needs.check-image-presence.outputs.webapp-build-needed == 'true' || needs.check-image-presence.outputs.ops-build-needed == 'true'
87+ runs-on : ubuntu-latest
88+ permissions :
89+ id-token : write
90+ steps :
91+ - name : Checkout code
92+ uses : actions/checkout@v5
93+ with :
94+ ref : ${{ env.git_ref }}
95+ - name : Write build SHA
96+ run : git rev-parse HEAD > public/sha
97+ - name : Build webapp docker image
98+ run : docker build -t "mavis-webapp:latest" .
99+ - name : Save web image
100+ run : docker save -o image.tar mavis-webapp:latest
101+ - name : Upload web image
102+ uses : actions/upload-artifact@v4
103+ with :
104+ name : webapp-image
105+ path : image.tar
106+ - name : Build ops docker image
107+ run : docker build -f ops.Dockerfile -t "mavis-ops:latest" .
108+ - name : Save ops image
109+ run : docker save -o image.tar mavis-ops:latest
110+ - name : Upload ops image
111+ uses : actions/upload-artifact@v4
112+ with :
113+ name : ops-image
114+ path : image.tar
100115 push :
101116 runs-on : ubuntu-latest
102117 needs : [build, define-matrix]
@@ -105,11 +120,12 @@ jobs:
105120 strategy :
106121 matrix :
107122 aws-role : ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
123+ image_type : ["webapp", "ops"]
108124 steps :
109125 - name : Download Docker image
110126 uses : actions/download-artifact@v5
111127 with :
112- name : image
128+ name : ${{ matrix.image_type }}- image
113129 - name : Configure AWS Credentials
114130 uses : aws-actions/configure-aws-credentials@v5
115131 with :
@@ -121,6 +137,6 @@ jobs:
121137 - name : Load Docker image
122138 run : docker load -i image.tar
123139 - name : Tag Docker image
124- run : docker tag mavis:latest "${{ steps.login-ecr.outputs.registry }}/mavis/webapp ":"$git_ref"
140+ run : docker tag mavis-${{ matrix.image_type }} :latest "${{ steps.login-ecr.outputs.registry }}/mavis/${{ matrix.image_type }} ":"$git_ref"
125141 - name : Push Docker image
126- run : docker push "${{ steps.login-ecr.outputs.registry }}/mavis/webapp ":"$git_ref"
142+ run : docker push "${{ steps.login-ecr.outputs.registry }}/mavis/${{ matrix.image_type }} ":"$git_ref"
0 commit comments