Skip to content

ci: add GHCR Docker publish workflow #1

ci: add GHCR Docker publish workflow

ci: add GHCR Docker publish workflow #1

Workflow file for this run

name: Publish Docker Image
on:
workflow_dispatch:
inputs:
push:
description: Push image to GHCR
type: boolean
required: true
default: true
platforms:
description: Target platforms
type: string
required: true
default: linux/amd64,linux/arm64
push:
branches:
- main
tags:
- "v*"
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare image metadata
id: prep
shell: bash
run: |
image="${REGISTRY}/${GITHUB_REPOSITORY}"
image="$(echo "${image}" | tr '[:upper:]' '[:lower:]')"
echo "image=${image}" >> "${GITHUB_OUTPUT}"
should_push=true
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && "${{ inputs.push }}" != "true" ]]; then
should_push=false
fi
echo "push=${should_push}" >> "${GITHUB_OUTPUT}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
if: steps.prep.outputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker tags
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.prep.outputs.image }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and publish image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
platforms: ${{ github.event_name == 'workflow_dispatch' && inputs.platforms || 'linux/amd64,linux/arm64' }}
push: ${{ steps.prep.outputs.push == 'true' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max