Skip to content
Merged
Changes from 2 commits
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
101 changes: 101 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Docker Build - Build and push image to GitHub Container Registry
#
# This workflow builds the Docker image on every push to main
# and pushes it to GitHub Container Registry (ghcr.io).
#
# Usage:
# - Image is tagged with: latest, commit SHA, and Git tag (if present)
# - Access packages at: https://github.com/OWNER/REPOSITORY/pkgs/container/REPO_NAME
#
# Required secrets:
# - GITHUB_TOKEN (auto-provided): Used to authenticate with GHCR

name: Docker Build

on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
paths:
- Dockerfile
- requirements.txt
- "**.py"
workflow_dispatch:
inputs:
tag:
description: "Custom tag for the image (optional)"
required: false
default: ""

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=,suffix=,format=short
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ inputs.tag }},enable=${{ inputs.tag != '' }}

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64,linux/arm64

- name: Generate artifact attestation
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v2
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true

- name: Print image digest
if: github.event_name != 'pull_request'
run: |
echo "✅ Image pushed successfully!"
echo "📦 Digest: ${{ steps.push.outputs.digest }}"
echo "🐳 Tags:"
echo "${{ steps.meta.outputs.tags }}"