Skip to content

Commit

Permalink
Infra: Adjust publish action for AWS ECR (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
yermulnik authored Jan 30, 2025
1 parent a5d34a7 commit 840a5c2
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/docker_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
registry: [ 'docker.io', 'ghcr.io', 'ecr' ]
registry: [ 'docker.io', 'ghcr.io', 'public.ecr.aws' ]

runs-on: ubuntu-latest
steps:
Expand All @@ -31,7 +31,8 @@ jobs:
name: image
path: /tmp

# setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations
# setup containerd to preserve provenance attestations:
# https://docs.docker.com/build/attestations/#creating-attestations
- name: Setup docker with containerd
uses: crazy-max/ghaction-setup-docker@v3
with:
Expand Down Expand Up @@ -63,33 +64,33 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Login to public ECR
if: matrix.registry == 'ecr'
if: matrix.registry == 'public.ecr.aws'
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public

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

0 comments on commit 840a5c2

Please sign in to comment.