docker-publish.yml•2.34 kB
name: Docker Publish
on:
workflow_dispatch:
push:
branches:
- main
tags:
- 'v*'
paths:
- 'cmd/**'
- 'internal/**'
- 'go.mod'
- 'go.sum'
- 'Dockerfile'
- '.github/workflows/docker-publish.yml'
jobs:
build-and-publish:
runs-on: ubuntu-latest
timeout-minutes: 25
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
- 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 the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up cache configuration
id: cache
run: |
{
echo "cache_from<<EOF"
echo "type=gha"
[ "${{ github.event_name }}" != "pull_request" ] && echo "type=registry,ref=ghcr.io/${{ github.repository }}/cache:buildcache"
echo "EOF"
echo "cache_to<<EOF"
echo "type=gha,mode=max"
[ "${{ github.event_name }}" != "pull_request" ] && echo "type=registry,ref=ghcr.io/${{ github.repository }}/cache:buildcache,mode=max"
echo "EOF"
} >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: ${{ steps.cache.outputs.cache_from }}
cache-to: ${{ steps.cache.outputs.cache_to }}
build-args: |
BUILDKIT_INLINE_CACHE=1
provenance: true
sbom: true