From c18c8ab73fecd77236dd15fdb57d42faf37e7ffc Mon Sep 17 00:00:00 2001 From: Till Rohrmann Date: Mon, 27 Nov 2023 21:57:04 +0100 Subject: [PATCH] Update docker.yml to optionally upload to DockerHub --- .github/workflows/docker.yml | 38 +++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 979abd564a..7238b1c259 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -18,6 +18,11 @@ on: required: false default: false type: boolean + uploadToDockerHub: + description: 'upload image to DockerHub' + required: false + default: false + type: boolean workflow_dispatch: inputs: @@ -26,12 +31,17 @@ on: required: false default: false type: boolean + uploadToDockerHub: + description: 'upload image to DockerHub' + required: false + default: false + type: boolean env: - REGISTRY: 'ghcr.io' - REPOSITORY: ${{ github.repository_owner }} - REGISTRY_USERNAME: ${{ github.actor }} - REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GHCR_REGISTRY: 'ghcr.io' + REPOSITORY_OWNER: ${{ github.repository_owner }} + GHCR_REGISTRY_USERNAME: ${{ github.actor }} + GHCR_REGISTRY_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: build-and-push-image: @@ -49,12 +59,19 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 - - name: Log in to the Container registry + - name: Log into GitHub container registry uses: docker/login-action@v2 with: - registry: ${{ env.REGISTRY }} - username: ${{ env.REGISTRY_USERNAME }} - password: ${{ env.REGISTRY_TOKEN }} + registry: ${{ env.GHCR_REGISTRY }} + username: ${{ env.GHCR_REGISTRY_USERNAME }} + password: ${{ env.GHCR_REGISTRY_TOKEN }} + + - name: Log into DockerHub + if: ${{ inputs.uploadToDockerHub }} + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - name: Extract image name # Set repository name as image name @@ -65,7 +82,10 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.REPOSITORY }}/${{ env.IMAGE_NAME }} + images: | + ${{ env.GHCR_REGISTRY }}/${{ env.REPOSITORY_OWNER }}/${{ env.IMAGE_NAME }} + ${{ inputs.uploadToDockerHub && format('{0}/{1}', env.REPOSITORY_OWNER, env.IMAGE_NAME) || '' }} + # Note: We need this to generate the latest tag until we have a first stable release. # Check https://github.com/docker/metadata-action/issues/34 flavor: |