Skip to content

Commit 2d2c53e

Browse files
author
Madan Shah
committed
refactor(ci): clean up workflow — upfront auth, no silent failures, updated actions
- Remove push trigger on feature branch; workflow_dispatch only - Remove hardcoded DEFAULT_BUILD_REF; fall back to github.sha - Login to both private and public ECR upfront before build so credentials are stable throughout — eliminates mid-workflow credential swap - Remove continue-on-error from public ECR steps; failures are now fatal - Remove redundant Reconfigure + Login to ECR for follow-up steps - Bump timeout from 180m to 30m - Upgrade actions to Node.js 24 compatible versions: configure-aws-credentials v4.0.2 -> v6.1.0 setup-buildx-action v3.12.0 -> v4.0.0 upload-artifact v4.6.2 -> v7.0.1
1 parent f578df5 commit 2d2c53e

1 file changed

Lines changed: 25 additions & 37 deletions

File tree

.github/workflows/docker-publish-ecr.yml

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
name: Docker Publish to ECR
22

33
on:
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:
@@ -23,7 +20,6 @@ env:
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

2925
permissions:
@@ -41,7 +37,7 @@ jobs:
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:
@@ -76,7 +72,7 @@ jobs:
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
@@ -88,7 +84,7 @@ jobs:
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

Comments
 (0)