Skip to content

Commit 840a5c2

Browse files
authored
Infra: Adjust publish action for AWS ECR (#794)
1 parent a5d34a7 commit 840a5c2

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

.github/workflows/docker_publish.yml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
registry: [ 'docker.io', 'ghcr.io', 'ecr' ]
23+
registry: [ 'docker.io', 'ghcr.io', 'public.ecr.aws' ]
2424

2525
runs-on: ubuntu-latest
2626
steps:
@@ -31,7 +31,8 @@ jobs:
3131
name: image
3232
path: /tmp
3333

34-
# setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
34+
# setup containerd to preserve provenance attestations:
35+
# https://docs.docker.com/build/attestations/#creating-attestations
3536
- name: Setup docker with containerd
3637
uses: crazy-max/ghaction-setup-docker@v3
3738
with:
@@ -63,33 +64,33 @@ jobs:
6364
password: ${{ secrets.GITHUB_TOKEN }}
6465

6566
- name: Configure AWS credentials
66-
if: matrix.registry == 'ecr'
67+
if: matrix.registry == 'public.ecr.aws'
6768
uses: aws-actions/configure-aws-credentials@v4
6869
with:
6970
aws-region: us-east-1 # This region only for public ECR
7071
role-to-assume: ${{ secrets.AWS_ROLE }}
7172

7273
- name: Login to public ECR
73-
if: matrix.registry == 'ecr'
74+
if: matrix.registry == 'public.ecr.aws'
7475
id: login-ecr-public
7576
uses: aws-actions/amazon-ecr-login@v2
7677
with:
7778
registry-type: public
7879

79-
- name: define env vars
80+
- name: Define env vars for container registry URL
8081
run: |
81-
if [ ${{matrix.registry }} == 'docker.io' ]; then
82-
echo "REGISTRY=${{ matrix.registry }}" >> $GITHUB_ENV
83-
echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV
84-
elif [ ${{ matrix.registry }} == 'ghcr.io' ]; then
85-
echo "REGISTRY=${{ matrix.registry }}" >> $GITHUB_ENV
86-
echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV
87-
elif [ ${{ matrix.registry }} == 'ecr' ]; then
82+
if [ ${{ matrix.registry }} == 'public.ecr.aws' ]; then
83+
# vars.ECR_REGISTRY value is expected to be of the `public.ecr.aws/<public_ecr_id>` form
84+
# The `public_ecr_id` must be a *default* alias associated with public regsitry (rather
85+
# than a custom alias)
8886
echo "REGISTRY=${{ vars.ECR_REGISTRY }}" >> $GITHUB_ENV
87+
# Trim GH Org name so that resulting Public ECR URL has no duplicate org name
88+
# Public ECR default alias: public.ecr.aws/<public_ecr_id>/kafka-ui
89+
# Public ECR custom alias: public.ecr.aws/kafbat/kafka-ui
90+
echo "REPOSITORY=$(basename ${{ github.repository }})" >> $GITHUB_ENV
91+
else # this covers the case of docker.io and ghcr.io
92+
echo "REGISTRY=${{ matrix.registry }}" >> $GITHUB_ENV
8993
echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV
90-
else
91-
echo "REGISTRY=" >> $GITHUB_ENV
92-
echo "REPOSITORY=notworking" >> $GITHUB_ENV
9394
fi
9495
9596
- name: Push images to ${{ matrix.registry }}

0 commit comments

Comments
 (0)