Skip to content

Infra: Adjust publish action for AWS ECR #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading