Skip to content

Publish Docker Image to DockerHub #705

Publish Docker Image to DockerHub

Publish Docker Image to DockerHub #705

name: Publish Docker Image to DockerHub
on:
release:
types:
- published
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
wants_production_build:
description: "Production build instead of nightly?"
required: false
default: false
type: boolean
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
REGISTRY: docker.io
IMAGE_NAME: ${{ github.repository }}
jobs:
publish:
name: Publish Docker Image to DockerHub
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout dev branch for nightly build
uses: actions/checkout@v3
if: ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && !inputs.wants_production_build) }}
with:
ref: "refs/heads/dev"
- name: Checkout main branch for production build
uses: actions/checkout@v3
if: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.wants_production_build) }}
with:
ref: "refs/heads/master"
- name: Extract metadata (tags, labels) for Docker tags & labels
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,priority=100,enable=${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.wants_production_build) }}
type=semver,priority=200,pattern={{raw}},enable=${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && inputs.wants_production_build) }}
type=raw,value=nightly,priority=300,enable=${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch' && !inputs.wants_production_build) }}
- name: Set up QEMU for multi-arch builds
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx for multi-arch builds
id: buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Build and push Docker image to DockerHub
uses: docker/build-push-action@v3
with:
context: .
push: true
platforms: linux/amd64, linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}