@@ -29,12 +29,16 @@ jobs:
2929 strategy :
3030 fail-fast : true
3131 matrix :
32- image_type : [" webapp", " ops" ]
32+ image_type : [webapp, ops]
3333 permissions :
3434 id-token : write
3535 outputs :
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 }}
36+ webapp-build-needed : >-
37+ ${{ steps.check-dev-image.outputs.webapp-build-needed ||
38+ steps.check-prod-image.outputs.webapp-build-needed }}
39+ ops-build-needed : >-
40+ ${{ steps.check-dev-image.outputs.ops-build-needed ||
41+ steps.check-prod-image.outputs.ops-build-needed }}
3842 steps :
3943 - name : Configure AWS Dev Credentials
4044 uses : aws-actions/configure-aws-credentials@v6
4448 - name : Check if dev image exists
4549 id : check-dev-image
4650 run : |
47- if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids "imageTag=$git_ref" > /dev/null 2>&1; then
51+ if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} \
52+ --image-ids "imageTag=$git_ref" > /dev/null 2>&1; then
4853 echo "Dev image with given tag already exists"
4954 else
5055 echo "Dev image does not exist. Build needed"
6065 if : env.PUSH_IMAGE_TO_PRODUCTION == 'true'
6166 id : check-prod-image
6267 run : |
63- if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} --image-ids "imageTag=$git_ref" > /dev/null 2>&1; then
68+ if aws ecr describe-images --repository-name mavis/${{ matrix.image_type }} \
69+ --image-ids "imageTag=$git_ref" > /dev/null 2>&1; then
6470 echo "Production image with given tag already exists"
6571 else
6672 echo "Production image does not exist. Build needed"
@@ -75,57 +81,32 @@ jobs:
7581 steps :
7682 - name : Set aws roles
7783 id : determine-aws-roles
84+ # yamllint disable rule:line-length
7885 run : |
7986 if [ "$PUSH_IMAGE_TO_PRODUCTION" = "true" ]; then
8087 echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure", "arn:aws:iam::820242920762:role/GithubDeployMavisAndInfrastructure"]' >> "$GITHUB_OUTPUT"
8188 else
8289 echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure"]' >> "$GITHUB_OUTPUT"
8390 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'
91+ # yamllint enable rule:line-length
92+ build-and-push :
93+ needs : [check-image-presence, define-matrix]
94+ if : >-
95+ needs.check-image-presence.outputs.webapp-build-needed == 'true' ||
96+ needs.check-image-presence.outputs.ops-build-needed == 'true'
8797 runs-on : ubuntu-latest
8898 permissions :
8999 id-token : write
100+ strategy :
101+ matrix :
102+ aws-role : ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
90103 steps :
91104 - name : Checkout code
92105 uses : actions/checkout@v6
93106 with :
94107 ref : ${{ env.git_ref }}
95108 - name : Write build SHA
96109 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@v7
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@v7
112- with :
113- name : ops-image
114- path : image.tar
115- push :
116- runs-on : ubuntu-latest
117- needs : [build, define-matrix]
118- permissions :
119- id-token : write
120- strategy :
121- matrix :
122- aws-role : ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
123- image_type : ["webapp", "ops"]
124- steps :
125- - name : Download Docker image
126- uses : actions/download-artifact@v8
127- with :
128- name : ${{ matrix.image_type }}-image
129110 - name : Configure AWS Credentials
130111 uses : aws-actions/configure-aws-credentials@v6
131112 with :
@@ -134,9 +115,34 @@ jobs:
134115 - name : Login to ECR
135116 id : login-ecr
136117 uses : aws-actions/amazon-ecr-login@v2
137- - name : Load Docker image
138- run : docker load -i image.tar
139- - name : Tag Docker image
140- run : docker tag mavis-${{ matrix.image_type }}:latest "${{ steps.login-ecr.outputs.registry }}/mavis/${{ matrix.image_type }}":"$git_ref"
141- - name : Push Docker image
142- run : docker push "${{ steps.login-ecr.outputs.registry }}/mavis/${{ matrix.image_type }}":"$git_ref"
118+ - name : Set up Docker Buildx
119+ uses : docker/setup-buildx-action@v4
120+ # yamllint disable rule:line-length
121+ - name : Build and push webapp image
122+ if : needs.check-image-presence.outputs.webapp-build-needed == 'true'
123+ uses : docker/build-push-action@v7
124+ with :
125+ context : .
126+ push : true
127+ tags : ${{ steps.login-ecr.outputs.registry }}/mavis/webapp:${{ env.git_ref }}
128+ cache-from :
129+ type=registry,ref=${{ steps.login-ecr.outputs.registry }}/mavis/webapp:buildcache
130+ cache-to :
131+ type=registry,ref=${{ steps.login-ecr.outputs.registry
132+ }}/mavis/webapp:buildcache,mode=max,image-manifest=true,oci-mediatypes=true
133+ - name : Build and push ops image
134+ if : needs.check-image-presence.outputs.ops-build-needed == 'true'
135+ uses : docker/build-push-action@v7
136+ with :
137+ context : .
138+ file : ops.Dockerfile
139+ push : true
140+ tags : ${{ steps.login-ecr.outputs.registry }}/mavis/ops:${{ env.git_ref }}
141+ build-args : |
142+ REPOSITORY=${{ steps.login-ecr.outputs.registry }}/mavis/webapp
143+ IMAGE_TAG=${{ env.git_ref }}
144+ cache-from : type=registry,ref=${{ steps.login-ecr.outputs.registry }}/mavis/ops:buildcache
145+ cache-to :
146+ type=registry,ref=${{ steps.login-ecr.outputs.registry
147+ }}/mavis/ops:buildcache,mode=max,image-manifest=true,oci-mediatypes=true
148+ # yamllint enable rule:line-length
0 commit comments