Publishing Docker Images with GitHub Actions
This document explains how automatic publishing of Docker images to GitHub Container Registry (GHCR) works.
π Publishing Process
Automatic with Script (Recommended)
Use the included PowerShell script to safely create and publish new versions:
# From the repository root
# Production release
.\scripts\publish-version.ps1 -Version "1.0.0"
# Pre-release (beta, rc, alpha)
.\scripts\publish-version.ps1 -Version "1.0.0-beta1"
.\scripts\publish-version.ps1 -Version "2.0.0-rc2"
.\scripts\publish-version.ps1 -Version "1.0.0-alpha1"
# Preview what would happen without executing it (dry run)
.\scripts\publish-version.ps1 -Version "1.0.0" -DryRun
The script automatically verifies:
- β
Correct version format (
X.Y.ZorX.Y.Z-prerelease) - β No uncommitted changes
- β Your local branch is up to date with the remote
- β The tag does not already exist
Manual
You can also create tags manually:
# Create a production release tag
git tag v1.0.0
# Create a pre-release tag
git tag v1.0.0-beta1
# Push the tag to GitHub
git push origin v1.0.0
# or
git push origin v1.0.0-beta1
What Happens Automatically
This triggers the GitHub Actions workflow, which will:
- Build the Docker images for the API and Frontend.
- Tag them with multiple Docker image tags (note: image tags never use the
vprefix):1.0.0(full version)1.0(major.minor)1(major)latest(stable releases only)sha-<sha>(short commit SHA)
- Publish them to
ghcr.io/evaristocuesta/clovance/. - Generate a provenance attestation.
The Git tag (v1.0.0) is the only Git tag created; the tags above belong to the Docker images.
Published Images
- API:
ghcr.io/evaristocuesta/clovance/clovance-api:1.0.0 - Frontend:
ghcr.io/evaristocuesta/clovance/clovance-frontend:1.0.0
π¦ Tag Structure
The workflow automatically generates multiple tags for each version.
Production Releases
Git tag v1.2.3 β Docker image tags generated:
- 1.2.3 (full version)
- 1.2 (major.minor)
- 1 (major)
- latest (stable releases only)
- sha-abc1234 (short commit SHA)
Pre-releases (beta, rc, alpha)
Git tag v1.2.3-beta1 β Docker image tags generated:
- 1.2.3-beta1 (full version)
- sha-abc1234 (short commit SHA)
β οΈ Pre-releases DO NOT update:
- major.minor (1.2)
- major (1)
- latest
This ensures that preview releases do not overwrite stable production releases.
π§ Local Development with Aspire
Local Development
To run the application locally with Aspire:
cd api/aspire/Clovance.AppHost
dotnet run
This uses appsettings.Development.json and does not attempt to publish containers.
Generate Deployment Manifests
Aspire can generate deployment artifacts from the application model (Docker Compose, Kubernetes, etc.) that reference the images published to GHCR. Starting with Aspire 17, publishing goes through the Aspire CLI; dotnet run --operation publish is rejected:
# Generate deployment artifacts (writes to ./aspire-output)
cd api/aspire/Clovance.AppHost
aspire publish -e Production
# Or choose a different output directory
aspire publish -e Production -o ./manifests
This generates deployment files ready to use with the images published in GHCR.
π³ Test Local Builds
API Service
# From the repository root
docker build -t clovance-api:local -f api/src/Clovance.ApiService/Dockerfile .
docker run -p 8080:8080 clovance-api:local
Frontend
# From the frontend directory
cd frontend
docker build -t clovance-frontend:local .
docker run -p 8000:8000 clovance-frontend:local
π GHCR Permissions
Images are published as public by default. To change their visibility:
- Go to https://github.com/evaristocuesta?tab=packages
- Find the package (
clovance-apiorclovance-frontend) - Open Package settings
- Change the visibility to Public or Private
π Workflow Requirements
The workflow requires the following permissions (already configured):
contents: read- To clone the repositorypackages: write- To publish to GHCR
It automatically uses ${{ secrets.GITHUB_TOKEN }}, which GitHub generates for every workflow run.
π Semantic Versioning
It is recommended to follow Semantic Versioning:
- MAJOR (
v1.0.0βv2.0.0): Breaking API changes - MINOR (
v1.0.0βv1.1.0): New backward-compatible functionality - PATCH (
v1.0.0βv1.0.1): Bug fixes - PRE-RELEASE (
v1.0.0-beta1): Preview versions before the official release
Versioning Examples
# Development and testing
git tag v1.0.0-alpha && git push origin v1.0.0-alpha # Very early version
git tag v1.0.0-beta1 && git push origin v1.0.0-beta1 # First beta
git tag v1.0.0-beta2 && git push origin v1.0.0-beta2 # Second beta
git tag v1.0.0-rc1 && git push origin v1.0.0-rc1 # Release candidate
# Production
git tag v1.0.0 && git push origin v1.0.0 # Initial release
git tag v1.0.1 && git push origin v1.0.1 # Bug fix
git tag v1.1.0 && git push origin v1.1.0 # New feature
git tag v2.0.0 && git push origin v2.0.0 # Breaking change
π¨ Troubleshooting
When Should I Use Pre-releases?
Use pre-releases for:
- β Testing new features before release
- β Public beta versions for early adopters
- β Release candidates before a final release
- β Alpha versions during early development
Do NOT use pre-releases for:
- β Stable production releases
- β Urgent hotfixes (use production releases instead)
Using a Pre-release in Production
If you need to use a specific pre-release:
# docker-compose.yml
services:
api:
image: ghcr.io/evaristocuesta/clovance/clovance-api:1.0.0-beta1
# Docker pull
docker pull ghcr.io/evaristocuesta/clovance/clovance-api:1.0.0-beta1
The Workflow Fails with βpermission deniedβ
Verify that the repository has Read and write permissions enabled for GitHub Actions:
- Settings β Actions β General
- Workflow permissions β Read and write permissions
Images Do Not Appear in GHCR
It may take a few minutes for the images to appear. Check:
- The workflow completed successfully: https://github.com/evaristocuesta/clovance/actions
- The packages are available at: https://github.com/evaristocuesta?tab=packages
I Want to Change the Registry
Edit .github/workflows/publish-images.yml and change:
env:
REGISTRY: ghcr.io # Change to docker.io, quay.io, etc.
Also update appsettings.Production.json:
{
"Parameters": {
"container-registry": "docker.io/your-username/clovance"
}
}