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 f6004be
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 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 @@ -52,20 +62,27 @@ jobs:
- name: Log in to the 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: Extract image name
# Set repository name as image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Print image names
run: |
echo ${{ inputs.uploadToDockerHub && format('restatedev/{0}', env.IMAGE_NAME) || '' }}
- name: Extract metadata (tags, labels) for Docker
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 f6004be

Please sign in to comment.