From f056315e6c9febeb90b5bc105cc694653b4b4867 Mon Sep 17 00:00:00 2001 From: Hleb Kanonik Date: Mon, 2 Oct 2023 13:09:52 +0200 Subject: [PATCH 1/4] Create dockerhub-release.yaml --- .github/workflows/dockerhub-release.yaml | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 .github/workflows/dockerhub-release.yaml diff --git a/.github/workflows/dockerhub-release.yaml b/.github/workflows/dockerhub-release.yaml new file mode 100644 index 0000000000..127df9b298 --- /dev/null +++ b/.github/workflows/dockerhub-release.yaml @@ -0,0 +1,69 @@ +name: Retag RC Docker image + +on: + pull_request_review: + types: [submitted] + +env: + AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name + PLATFORMS: ${{ vars.BUILD_PLATFORMS }} # set target build platforms. By default linux/amd64 + RELEASE_MODE: ${{ vars.RELEASE_MODE }} + +jobs: + retag-image: + name: Retag and push image + runs-on: ubuntu-latest + environment: rc + if: github.base_ref == 'master' || github.base_ref == 'main' + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + # role-to-assume: arn:aws:iam::123456789012:role/my-github-actions-role + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ env.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + with: + mask-password: 'true' + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Create variables + id: vars + run: | + echo "tag=$(echo '${{ github.event.pull_request.title }}' | sed -nE 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')" >> $GITHUB_OUTPUT + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Retag and Push Docker Image + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ steps.vars.outputs.tag }} + run: | + docker buildx imagetools create $ECR_REGISTRY/$ECR_REPOSITORY:latest --tag $DOCKERHUB_REGISTRY/$DOCKERHUB_REPOSITORY:$IMAGE_TAG --tag $DOCKERHUB_REGISTRY/$DOCKERHUB_REPOSITORY:latest + + - name: Summarize + env: + ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + IMAGE_TAG: ${{ steps.vars.outputs.tag }} + run: | + echo "## General information about the build:" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- :whale: Docker image: $DOCKERHUB_REGISTRY/$DOCKERHUB_REPOSITORY:$IMAGE_TAG" >> $GITHUB_STEP_SUMMARY + echo "- :octocat: The commit SHA from which the build was performed: [$GITHUB_SHA](https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA)" >> $GITHUB_STEP_SUMMARY From e25059f54be4aa6557cc676d8a06025ffe6fb528 Mon Sep 17 00:00:00 2001 From: hlebkanonik Date: Mon, 2 Oct 2023 13:44:01 +0200 Subject: [PATCH 2/4] github.event.pull_request.base.ref --- .github/workflows/dockerhub-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dockerhub-release.yaml b/.github/workflows/dockerhub-release.yaml index 127df9b298..827768c052 100644 --- a/.github/workflows/dockerhub-release.yaml +++ b/.github/workflows/dockerhub-release.yaml @@ -15,7 +15,7 @@ jobs: name: Retag and push image runs-on: ubuntu-latest environment: rc - if: github.base_ref == 'master' || github.base_ref == 'main' + if: github.event.pull_request.base.ref == 'master' || github.event.pull_request.base.ref == 'main' steps: - name: Checkout uses: actions/checkout@v3 From f88d8abae9a58fe11ca761aa7dffe875a32203b5 Mon Sep 17 00:00:00 2001 From: hlebkanonik Date: Mon, 2 Oct 2023 14:21:45 +0200 Subject: [PATCH 3/4] rewrite target regestry envs --- .github/workflows/dockerhub-release.yaml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/dockerhub-release.yaml b/.github/workflows/dockerhub-release.yaml index 827768c052..bebe70f7fa 100644 --- a/.github/workflows/dockerhub-release.yaml +++ b/.github/workflows/dockerhub-release.yaml @@ -5,9 +5,11 @@ on: types: [submitted] env: - AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 - ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name - PLATFORMS: ${{ vars.BUILD_PLATFORMS }} # set target build platforms. By default linux/amd64 + AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name + TARGET_REGISTRY: ${{ vars.TARGET_REGISTRY }} # set to target regestry (DockerHub, GitHub & etc) + TARGET_REPOSITORY: ${{ vars.TARGET_REPOSITORY }} # set to target repository + PLATFORMS: ${{ vars.BUILD_PLATFORMS }} # set target build platforms. By default linux/amd64 RELEASE_MODE: ${{ vars.RELEASE_MODE }} jobs: @@ -37,8 +39,8 @@ jobs: - name: Log in to Docker Hub uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} + username: ${{ secrets.REGESTRY_USERNAME }} + password: ${{ secrets.REGESTRY_PASSWORD }} - name: Create variables id: vars @@ -56,7 +58,7 @@ jobs: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} IMAGE_TAG: ${{ steps.vars.outputs.tag }} run: | - docker buildx imagetools create $ECR_REGISTRY/$ECR_REPOSITORY:latest --tag $DOCKERHUB_REGISTRY/$DOCKERHUB_REPOSITORY:$IMAGE_TAG --tag $DOCKERHUB_REGISTRY/$DOCKERHUB_REPOSITORY:latest + docker buildx imagetools create $ECR_REGISTRY/$ECR_REPOSITORY:latest --tag $TARGET_REGISTRY/$TARGET_REPOSITORY:$IMAGE_TAG --tag $TARGET_REGISTRY/$TARGET_REPOSITORY:latest - name: Summarize env: @@ -65,5 +67,5 @@ jobs: run: | echo "## General information about the build:" >> $GITHUB_STEP_SUMMARY echo "" >> $GITHUB_STEP_SUMMARY - echo "- :whale: Docker image: $DOCKERHUB_REGISTRY/$DOCKERHUB_REPOSITORY:$IMAGE_TAG" >> $GITHUB_STEP_SUMMARY + echo "- :whale: Docker image: $TARGET_REGISTRY/$TARGET_REPOSITORY:$IMAGE_TAG" >> $GITHUB_STEP_SUMMARY echo "- :octocat: The commit SHA from which the build was performed: [$GITHUB_SHA](https://github.com/$GITHUB_REPOSITORY/commit/$GITHUB_SHA)" >> $GITHUB_STEP_SUMMARY From 13d6e1697792b620def74b45da35160d4525836c Mon Sep 17 00:00:00 2001 From: hlebkanonik Date: Mon, 2 Oct 2023 14:22:50 +0200 Subject: [PATCH 4/4] modified: .github/workflows/dockerhub-release.yaml --- .github/workflows/dockerhub-release.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dockerhub-release.yaml b/.github/workflows/dockerhub-release.yaml index bebe70f7fa..f874986a45 100644 --- a/.github/workflows/dockerhub-release.yaml +++ b/.github/workflows/dockerhub-release.yaml @@ -5,11 +5,11 @@ on: types: [submitted] env: - AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 - ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name + AWS_REGION: ${{ vars.AWS_REGION }} # set this to your preferred AWS region, e.g. us-west-1 + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} # set this to your Amazon ECR repository name TARGET_REGISTRY: ${{ vars.TARGET_REGISTRY }} # set to target regestry (DockerHub, GitHub & etc) TARGET_REPOSITORY: ${{ vars.TARGET_REPOSITORY }} # set to target repository - PLATFORMS: ${{ vars.BUILD_PLATFORMS }} # set target build platforms. By default linux/amd64 + PLATFORMS: ${{ vars.BUILD_PLATFORMS }} # set target build platforms. By default linux/amd64 RELEASE_MODE: ${{ vars.RELEASE_MODE }} jobs: