Skip to content

Commit 9f7eb5e

Browse files
author
Madan Shah
committed
fix(ci): separate private build and public ECR copy steps
buildx --push with two --tag flags fails with 403 on public ECR because the buildx container builder does not share the host docker config where public ECR login is stored. Fix: push to private ECR only during build, then use imagetools create to copy the manifest to public ECR after authenticating with the public ECR role.
1 parent 8346a2e commit 9f7eb5e

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,26 @@ jobs:
124124
role-to-assume: ${{ vars.AWS_ROLE_TO_ASSUME }}
125125
aws-region: ${{ env.AWS_REGION }}
126126

127+
- name: Login to private ECR
128+
run: |
129+
aws ecr get-login-password --region "${AWS_REGION}" \
130+
| docker login --username AWS --password-stdin "${ECR_REGISTRY}"
131+
127132
- name: Set up Docker Buildx
128133
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
129134

135+
- name: Build and push Mosaic image to private ECR
136+
run: |
137+
set -euo pipefail
138+
docker buildx build \
139+
--platform "${DOCKER_PLATFORMS}" \
140+
--file docker/Dockerfile \
141+
--cache-from "type=gha,scope=mosaic" \
142+
--cache-to "type=gha,scope=mosaic,mode=max" \
143+
--tag "${IMAGE_REF}" \
144+
--push \
145+
.
146+
130147
- name: Configure public ECR credentials
131148
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
132149
with:
@@ -138,29 +155,14 @@ jobs:
138155
aws ecr-public get-login-password --region "${PUBLIC_ECR_REGION}" \
139156
| docker login --username AWS --password-stdin "${PUBLIC_ECR_REGISTRY}"
140157
141-
- name: Reconfigure private AWS credentials for build
142-
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
143-
with:
144-
role-to-assume: ${{ vars.AWS_ROLE_TO_ASSUME }}
145-
aws-region: ${{ env.AWS_REGION }}
146-
147-
- name: Login to private ECR for build
148-
run: |
149-
aws ecr get-login-password --region "${AWS_REGION}" \
150-
| docker login --username AWS --password-stdin "${ECR_REGISTRY}"
151-
152-
- name: Build and push Mosaic image
158+
- name: Copy image to public ECR
153159
run: |
154160
set -euo pipefail
155-
docker buildx build \
156-
--platform "${DOCKER_PLATFORMS}" \
157-
--file docker/Dockerfile \
158-
--cache-from "type=gha,scope=mosaic" \
159-
--cache-to "type=gha,scope=mosaic,mode=max" \
160-
--tag "${IMAGE_REF}" \
161+
# imagetools create copies the manifest from private ECR (docker login still valid)
162+
# to public ECR using the public ECR docker login obtained above.
163+
docker buildx imagetools create \
161164
--tag "${PUBLIC_IMAGE_REF}" \
162-
--push \
163-
.
165+
"${IMAGE_REF}"
164166
165167
- name: Reconfigure private AWS credentials
166168
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2

0 commit comments

Comments
 (0)