name: Build and Publish Docker Image
on:
push:
branches:
- main
paths:
- 'src/**'
- 'package*.json'
- 'tsconfig.json'
- 'Dockerfile'
- '.github/workflows/docker.yml'
pull_request:
branches:
- main
paths:
- 'src/**'
- 'package*.json'
- 'tsconfig.json'
- 'Dockerfile'
release:
types: [published]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
- 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: |
# For releases: use semantic version
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
# For main branch: use 'latest' and 'edge'
type=edge,branch=main
type=raw,value=latest,enable={{is_default_branch}}
# For PRs: use pr number
type=ref,event=pr
# For branches: use branch name
type=ref,event=branch
# Add commit SHA for traceability, but not for PRs
type=sha,prefix={{branch}}-,enable=${{ github.event_name != 'pull_request' }}
labels: |
org.opencontainers.image.title=XRootD MCP Server
org.opencontainers.image.description=Model Context Protocol server for XRootD file system access
org.opencontainers.image.vendor=EIC
maintainer=Wouter Deconinck
- name: Build and push Docker image
id: build
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
provenance: true
- name: Output image tags
run: |
echo "🐳 Docker images published:"
echo "${{ steps.meta.outputs.tags }}" | tr ',' '\n' | while read tag; do
echo " - $tag"
done