Skip to content

Commit

Permalink
Update docker.yml to optionally upload to DockerHub
Browse files Browse the repository at this point in the history
  • Loading branch information
tillrohrmann committed Nov 27, 2023
1 parent bf04449 commit c18c8ab
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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: |
Expand Down

0 comments on commit c18c8ab

Please sign in to comment.