Skip to content

Build and Publish image to Docker Hub #69

Build and Publish image to Docker Hub

Build and Publish image to Docker Hub #69

Workflow file for this run

name: Build and Publish image to Docker Hub
on:
workflow_dispatch:
push:
tags:
- "v*" # Only triggers on versioned tags, e.g., v1.0, v20.15.10
env:
# Use ghcr.io
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
packages: write
jobs:
publish_images:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true
# Login to GHCR (or other registry) except on PR
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
- name: Extract Docker metadata (${{ env.IMAGE_NAME }})
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image for multiple platforms
- name: Build and push Docker image (${{ env.IMAGE_NAME }})
uses: docker/build-push-action@v6
with:
context: .
target: final
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}