11name : Docker Publish to ECR
22
33on :
4- push :
5- branches :
6- - feat/str-3103-mosaic-ci
74 workflow_dispatch :
85 inputs :
96 ref :
10- description : Git branch, tag, or commit SHA to build. Defaults to the selected branch in the UI.
7+ description : Git branch, tag, or commit SHA to build. Defaults to the branch HEAD selected in the UI.
118 required : false
129 type : string
1310 image_tag :
2320 PUBLIC_ECR_NAMESPACE : z5c7y9u9
2421 PUBLIC_ECR_REPOSITORY : mosaic
2522 PUBLIC_ECR_REGION : us-east-1
26- DEFAULT_BUILD_REF : bae62a54b7137e811653d5dd89975e10f0e71676
2723 DOCKER_PLATFORMS : linux/amd64
2824
2925permissions :
4137 permissions :
4238 contents : read
4339 id-token : write
44- timeout-minutes : 180
40+ timeout-minutes : 30
4541 steps :
4642 - name : Validate manual inputs
4743 env :
7672 uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
7773 with :
7874 persist-credentials : false
79- ref : ${{ inputs.ref || env.DEFAULT_BUILD_REF }}
75+ ref : ${{ inputs.ref || github.sha }}
8076 fetch-depth : 0
8177
8278 - name : Resolve build metadata
8884
8985 resolved_sha="$(git rev-parse HEAD)"
9086 short_sha="$(git rev-parse --short=8 HEAD)"
91- checkout_ref="${INPUT_REF:-${DEFAULT_BUILD_REF }}"
87+ checkout_ref="${INPUT_REF:-${GITHUB_SHA }}"
9288 image_tag="${INPUT_IMAGE_TAG:-${short_sha}}"
9389 image_ref="${ECR_REGISTRY}/${ECR_REPOSITORY}:${image_tag}"
9490 public_image_ref="${PUBLIC_ECR_REGISTRY}/${PUBLIC_ECR_NAMESPACE}/${PUBLIC_ECR_REPOSITORY}:${image_tag}"
@@ -118,8 +114,8 @@ jobs:
118114 exit 1
119115 fi
120116
121- - name : Configure AWS credentials
122- uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
117+ - name : Configure private AWS credentials
118+ uses : aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0
123119 with :
124120 role-to-assume : ${{ vars.AWS_ROLE_TO_ASSUME }}
125121 aws-region : ${{ env.AWS_REGION }}
@@ -129,8 +125,25 @@ jobs:
129125 aws ecr get-login-password --region "${AWS_REGION}" \
130126 | docker login --username AWS --password-stdin "${ECR_REGISTRY}"
131127
128+ - name : Configure public ECR credentials
129+ uses : aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0
130+ with :
131+ role-to-assume : ${{ vars.PUBLIC_AWS_ROLE_TO_ASSUME }}
132+ aws-region : ${{ env.PUBLIC_ECR_REGION }}
133+
134+ - name : Login to public ECR
135+ run : |
136+ aws ecr-public get-login-password --region "${PUBLIC_ECR_REGION}" \
137+ | docker login --username AWS --password-stdin "${PUBLIC_ECR_REGISTRY}"
138+
139+ - name : Restore private AWS credentials
140+ uses : aws-actions/configure-aws-credentials@ec61189d14ec14c8efccab744f656cffd0e33f37 # v6.1.0
141+ with :
142+ role-to-assume : ${{ vars.AWS_ROLE_TO_ASSUME }}
143+ aws-region : ${{ env.AWS_REGION }}
144+
132145 - name : Set up Docker Buildx
133- uses : docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12 .0
146+ uses : docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0 .0
134147
135148 - name : Build and push Mosaic image to private ECR
136149 run : |
@@ -144,38 +157,13 @@ jobs:
144157 --push \
145158 .
146159
147- - name : Configure public ECR credentials
148- continue-on-error : true
149- uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
150- with :
151- role-to-assume : ${{ vars.PUBLIC_AWS_ROLE_TO_ASSUME }}
152- aws-region : ${{ env.PUBLIC_ECR_REGION }}
153-
154- - name : Login to public ECR
155- continue-on-error : true
156- run : |
157- aws ecr-public get-login-password --region "${PUBLIC_ECR_REGION}" \
158- | docker login --username AWS --password-stdin "${PUBLIC_ECR_REGISTRY}"
159-
160160 - name : Copy image to public ECR
161- continue-on-error : true
162161 run : |
163162 set -euo pipefail
164163 docker buildx imagetools create \
165164 --tag "${PUBLIC_IMAGE_REF}" \
166165 "${IMAGE_REF}"
167166
168- - name : Reconfigure private AWS credentials
169- uses : aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
170- with :
171- role-to-assume : ${{ vars.AWS_ROLE_TO_ASSUME }}
172- aws-region : ${{ env.AWS_REGION }}
173-
174- - name : Login to ECR for follow-up checks
175- run : |
176- aws ecr get-login-password --region "${AWS_REGION}" \
177- | docker login --username AWS --password-stdin "${ECR_REGISTRY}"
178-
179167 - name : Resolve pushed image digest
180168 id : digest
181169 run : |
@@ -207,7 +195,7 @@ jobs:
207195
208196 - name : Upload Trivy results artifact
209197 if : always()
210- uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
198+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
211199 with :
212200 name : trivy-mosaic-${{ env.IMAGE_TAG }}
213201 path : trivy-results/mosaic.txt
0 commit comments