Skip to content

Commit 8346a2e

Browse files
author
Madan Shah
committed
fix(ci): login to both registries before build, push both tags in one step
imagetools create failed because AWS env vars were pointing at the public ECR role when it tried to pull from private ECR. Fix by authenticating to both registries upfront (docker login creds persist in config.json regardless of AWS env var changes), then pass both --tag flags to the single buildx build so private and public ECR are written in one push.
1 parent 46ada3c commit 8346a2e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

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

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

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

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-
147130
- name: Configure public ECR credentials
148131
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2
149132
with:
@@ -155,12 +138,29 @@ jobs:
155138
aws ecr-public get-login-password --region "${PUBLIC_ECR_REGION}" \
156139
| docker login --username AWS --password-stdin "${PUBLIC_ECR_REGISTRY}"
157140
158-
- name: Push Mosaic image to public ECR
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
159153
run: |
160154
set -euo pipefail
161-
docker buildx imagetools create \
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}" \
162161
--tag "${PUBLIC_IMAGE_REF}" \
163-
"${IMAGE_REF}"
162+
--push \
163+
.
164164
165165
- name: Reconfigure private AWS credentials
166166
uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2

0 commit comments

Comments
 (0)