@@ -89,53 +89,24 @@ jobs:
8989 echo 'aws-roles=["arn:aws:iam::393416225559:role/GithubDeployMavisAndInfrastructure"]' >> "$GITHUB_OUTPUT"
9090 fi
9191 # yamllint enable rule:line-length
92- build :
93- needs : check-image-presence
92+ build-and-push :
93+ needs : [ check-image-presence, define-matrix]
9494 if : >-
9595 needs.check-image-presence.outputs.webapp-build-needed == 'true' ||
96- needs.check-image-presence.outputs.ops-build-needed == 'true'
96+ needs.check-image-presence.outputs.ops-build-needed == 'true'
9797 runs-on : ubuntu-latest
9898 permissions :
9999 id-token : write
100+ strategy :
101+ matrix :
102+ aws-role : ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
100103 steps :
101104 - name : Checkout code
102105 uses : actions/checkout@v6
103106 with :
104107 ref : ${{ env.git_ref }}
105108 - name : Write build SHA
106109 run : git rev-parse HEAD > public/sha
107- - name : Build webapp docker image
108- run : docker build -t "mavis-webapp:latest" .
109- - name : Save web image
110- run : docker save -o image.tar mavis-webapp:latest
111- - name : Upload web image
112- uses : actions/upload-artifact@v7
113- with :
114- name : webapp-image
115- path : image.tar
116- - name : Build ops docker image
117- run : docker build -f ops.Dockerfile -t "mavis-ops:latest" .
118- - name : Save ops image
119- run : docker save -o image.tar mavis-ops:latest
120- - name : Upload ops image
121- uses : actions/upload-artifact@v7
122- with :
123- name : ops-image
124- path : image.tar
125- push :
126- runs-on : ubuntu-latest
127- needs : [build, define-matrix]
128- permissions :
129- id-token : write
130- strategy :
131- matrix :
132- aws-role : ${{ fromJSON(needs.define-matrix.outputs.aws-roles) }}
133- image_type : ["webapp", "ops"]
134- steps :
135- - name : Download Docker image
136- uses : actions/download-artifact@v8
137- with :
138- name : ${{ matrix.image_type }}-image
139110 - name : Configure AWS Credentials
140111 uses : aws-actions/configure-aws-credentials@v6
141112 with :
@@ -144,13 +115,34 @@ jobs:
144115 - name : Login to ECR
145116 id : login-ecr
146117 uses : aws-actions/amazon-ecr-login@v2
147- - name : Load Docker image
148- run : docker load -i image.tar
149- - name : Tag Docker image
150- run : >-
151- docker tag mavis-${{ matrix.image_type }}:latest "${{ steps.login-ecr.outputs.registry
152- }}/mavis/${{ matrix.image_type }}":"$git_ref"
153- - name : Push Docker image
154- run : >-
155- docker push "${{ steps.login-ecr.outputs.registry }}/mavis/${{ matrix.image_type
156- }}":"$git_ref"
118+ - name : Set up Docker Buildx
119+ uses : docker/setup-buildx-action@v3
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@v6
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@v6
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