This repository includes several GitHub Actions workflows for building, testing, and publishing Docker images.
- Triggers: Push to
main
/develop
branches, Pull Requests tomain
- Purpose: Build and test Docker image without publishing
- Features:
- Builds Docker image with
load: true
to make it available for testing - Runs health checks
- Tests API endpoints
- Tests timezone functionality
- Security scanning with Trivy (non-blocking)
- Builds Docker image with
- Triggers: Push to
main
/develop
branches, Tags starting withv
- Purpose: Build and publish to Docker Hub
- Features:
- Multi-platform builds (AMD64, ARM64)
- Automatic tagging based on branch/tag
- Security scanning
- Staging and production deployment hooks
- Triggers: Push to
main
branch, Tags starting withv
- Purpose: Build and publish to GitHub Container Registry
- Features:
- Multi-platform builds
- Automatic tagging
- Security scanning
- Uses GitHub token for authentication
- Triggers: Weekly schedule, Manual dispatch
- Purpose: Comprehensive security scanning
- Features:
- Vulnerability scanning with Trivy
- Results uploaded to GitHub Security tab
- Non-blocking (won't fail the workflow)
Note: Your GitHub username and Docker Hub username can be different. The workflows are configured to use andystevko
as the Docker Hub username.
-
Create Docker Hub Account: Sign up at hub.docker.com
-
Create Access Token:
- Go to Docker Hub → Account Settings → Security
- Create a new access token
- Copy the token
-
Add Secrets to GitHub Repository:
- Go to your GitHub repository → Settings → Secrets and variables → Actions
- Add the following secrets:
DOCKER_USERNAME
:andystevko
(your Docker Hub username)DOCKER_TOKEN
: Your Docker Hub access token
No additional setup required! The workflow uses the built-in GITHUB_TOKEN
.
The workflows automatically create tags based on:
- Branch pushes:
main
,develop
- Pull requests:
pr-123
- Tags:
v1.0.0
,v1.0
,v1
,latest
(for main branch)
- Trivy Security Scanning: Scans for vulnerabilities
- Multi-platform builds: Supports AMD64 and ARM64
- Cache optimization: Uses GitHub Actions cache for faster builds
- Permission controls: Minimal required permissions
Docker Hub:
docker pull andystevko/htmx-fastapi-service:latest
docker pull andystevko/htmx-fastapi-service:v1.0.0
GitHub Container Registry:
docker pull ghcr.io/astevko/htmx-fastapi-service:latest
docker pull ghcr.io/astevko/htmx-fastapi-service:v1.0.0
# Run with default settings (Docker Hub)
docker run -p 8000:8000 andystevko/htmx-fastapi-service:latest
# Run with default settings (GitHub Container Registry)
docker run -p 8000:8000 ghcr.io/astevko/htmx-fastapi-service:latest
# Run with environment variables
docker run -p 8000:8000 -e PYTHONPATH=/app andystevko/htmx-fastapi-service:latest
- Build Failures: Check the Actions logs for specific error messages
- Authentication Errors: Verify Docker Hub credentials are correct
- Permission Errors: Ensure repository has proper permissions for packages
If you see "Resource not accessible by integration" errors with SARIF uploads:
- Enable Code Scanning: Go to repository Settings → Security → Code scanning → Set up code scanning
- Check Permissions: Ensure the workflow has
security-events: write
permission - Alternative: Use the dedicated
security-scan.yml
workflow for comprehensive scanning
The security scanning is set to continue-on-error: true
so it won't block your Docker builds.
If you see "pull access denied" or "repository does not exist" errors in the test workflow:
- Image Availability: The workflow uses
load: true
to make the built image available for testing - Step Context: Each step runs in the same runner, so the image persists between steps
- Cache: Uses GitHub Actions cache for faster builds
This ensures the Docker image built in one step is available for testing in subsequent steps.
You can test the Docker image locally:
# Build the image
docker build -t htmx-fastapi-service .
# Run the container
docker run -p 8000:8000 htmx-fastapi-service
# Test the endpoints
curl http://localhost:8000/
curl http://localhost:8000/api/messages
When contributing to this repository:
- Create a feature branch
- Make your changes
- Create a pull request
- The workflows will automatically test your changes
- Once merged, images will be automatically built and published