Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docker.yml to optionally push to DockerHub #911

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
pushToDockerHub:
description: 'push 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
pushToDockerHub:
description: 'push 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 }}
REPOSITORY_OWNER: 'restatedev'
GHCR_REGISTRY: 'ghcr.io'
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.pushToDockerHub }}
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 }}
tillrohrmann marked this conversation as resolved.
Show resolved Hide resolved
${{ inputs.pushToDockerHub && format('{0}/{1}', env.REPOSITORY_OWNER, env.IMAGE_NAME) || '' }}
tillrohrmann marked this conversation as resolved.
Show resolved Hide resolved

# 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
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ jobs:
name: Build release Docker image
needs: [run-tests]
uses: ./.github/workflows/docker.yml
with:
pushToDockerHub: true

create-release:
name: Create release
Expand Down
Loading