From 64be8602482c798229892dae2719f1be9683e2f3 Mon Sep 17 00:00:00 2001 From: "George L. Yermulnik" Date: Tue, 21 Jan 2025 16:59:41 +0200 Subject: [PATCH] infra(docker_publish): public.ecr.aws improvements Ref: #242 Improve publishig to Public AWS ECR by trimming repo owner from repo name so that Public ERC repo url has no duplcates. Before: `public.ecr.aws/kafbat/kafbat/kafka-ui` After: `public.ecr.aws/kafbat/kafka-ui` --- .github/workflows/docker_publish.yml | 31 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/docker_publish.yml b/.github/workflows/docker_publish.yml index e359ea740..1806dc017 100644 --- a/.github/workflows/docker_publish.yml +++ b/.github/workflows/docker_publish.yml @@ -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: @@ -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: @@ -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/` 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//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 }}