|
| 1 | +name: "Docker publish" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + generic_tag: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +permissions: |
| 14 | + packages: write |
| 15 | + id-token: write # Required to authenticate with OIDC for AWS |
| 16 | + |
| 17 | +jobs: |
| 18 | + deploy: |
| 19 | + continue-on-error: true |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + registry: [ 'docker.io', 'ghcr.io', 'ecr' ] |
| 24 | + |
| 25 | + runs-on: ubuntu-latest |
| 26 | + steps: |
| 27 | + |
| 28 | + - name: Download docker image |
| 29 | + uses: actions/download-artifact@v4 |
| 30 | + with: |
| 31 | + name: image |
| 32 | + path: /tmp |
| 33 | + |
| 34 | + # setup containerd to preserve provenance attestations :https://docs.docker.com/build/attestations/#creating-attestations |
| 35 | + - name: Setup docker with containerd |
| 36 | + uses: crazy-max/ghaction-setup-docker@v3 |
| 37 | + with: |
| 38 | + daemon-config: | |
| 39 | + { |
| 40 | + "features": { |
| 41 | + "containerd-snapshotter": true |
| 42 | + } |
| 43 | + } |
| 44 | +
|
| 45 | + - name: Load docker image into daemon |
| 46 | + run: | |
| 47 | + docker load --input /tmp/image.tar |
| 48 | +
|
| 49 | + - name: Login to docker.io |
| 50 | + if: matrix.registry == 'docker.io' |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + registry: ${{ matrix.registry }} |
| 54 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 55 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 56 | + |
| 57 | + - name: Login to ghcr.io |
| 58 | + if: matrix.registry == 'ghcr.io' |
| 59 | + uses: docker/login-action@v3 |
| 60 | + with: |
| 61 | + registry: ${{ matrix.registry }} |
| 62 | + username: ${{ github.actor }} |
| 63 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 64 | + |
| 65 | + - name: Configure AWS credentials |
| 66 | + if: matrix.registry == 'ecr' |
| 67 | + uses: aws-actions/configure-aws-credentials@v4 |
| 68 | + with: |
| 69 | + aws-region: us-east-1 # This region only for public ECR |
| 70 | + role-to-assume: ${{ secrets.AWS_ROLE }} |
| 71 | + |
| 72 | + - name: Login to public ECR |
| 73 | + if: matrix.registry == 'ecr' |
| 74 | + id: login-ecr-public |
| 75 | + uses: aws-actions/amazon-ecr-login@v2 |
| 76 | + with: |
| 77 | + registry-type: public |
| 78 | + |
| 79 | + - name: define env vars |
| 80 | + 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 |
| 88 | + echo "REGISTRY=${{ steps.login-ecr-public.outputs.registry }}" >> $GITHUB_ENV |
| 89 | + echo "REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV |
| 90 | + else |
| 91 | + echo "REGISTRY=" >> $GITHUB_ENV |
| 92 | + echo "REPOSITORY=notworking" >> $GITHUB_ENV |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Push images to ${{ matrix.registry }} |
| 96 | + run: | |
| 97 | + docker tag kafka-ui:temp ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.generic_tag }} |
| 98 | + docker tag kafka-ui:temp ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.version }} |
| 99 | + docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.generic_tag }} |
| 100 | + docker push ${{ env.REGISTRY }}/${{ env.REPOSITORY }}:${{ inputs.version }} |
0 commit comments