Reusable workflow for building and pushing Docker images to container registries. Supports monorepo architectures with automatic change detection and multi-platform builds.
- Monorepo support: Automatic detection of changed components via filter_paths
- Multi-registry: Push to DockerHub and/or GitHub Container Registry (GHCR)
- Smart platform builds: Beta/RC tags build amd64 only (unless
force_multiplatformis enabled), release tags build amd64+arm64 - Semantic versioning: Automatic tag extraction and Docker metadata
- GitOps integration: Upload artifacts for downstream gitops-update workflow
- Slack notifications: Automatic success/failure notifications
name: Build
on:
push:
tags:
- '**'
jobs:
build:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/build.yml@v1.0.0
with:
runner_type: "firmino-lxc-runners"
enable_dockerhub: true
enable_ghcr: true
dockerhub_org: lerianstudio
secrets: inheritname: Build
on:
push:
tags:
- '**'
jobs:
build:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/build.yml@v1.0.0
with:
runner_type: "firmino-lxc-runners"
filter_paths: |-
components/onboarding
components/transaction
components/console
path_level: 2
app_name_prefix: "midaz"
enable_dockerhub: true
enable_ghcr: true
dockerhub_org: lerianstudio
enable_gitops_artifacts: true
secrets: inheritname: Build
on:
push:
tags:
- '**'
jobs:
build:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/build.yml@v1.0.0
with:
filter_paths: |-
components/api
components/worker
path_level: 2
app_name_prefix: "myapp"
enable_gitops_artifacts: true
secrets: inherit
update_gitops:
needs: [build]
if: contains(github.ref, '-beta') || contains(github.ref, '-rc')
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/gitops-update.yml@v1.0.0
with:
gitops_repository: "MyOrg/gitops-repo"
artifact_pattern: "gitops-tags-myapp-*"
secrets: inherit| Input | Type | Default | Description |
|---|---|---|---|
runner_type |
string | firmino-lxc-runners |
GitHub runner type |
filter_paths |
string | '' |
Newline-separated list of path prefixes. If empty, builds from root (single-app mode) |
path_level |
string | 2 |
Directory depth for app name extraction |
enable_dockerhub |
boolean | true |
Enable pushing to DockerHub |
enable_ghcr |
boolean | false |
Enable pushing to GitHub Container Registry |
dockerhub_org |
string | lerianstudio |
DockerHub organization name |
ghcr_org |
string | '' |
GHCR organization (defaults to repository owner) |
dockerfile_name |
string | Dockerfile |
Name of the Dockerfile |
app_name_prefix |
string | '' |
Prefix for app names in monorepo |
build_context |
string | . |
Docker build context |
enable_gitops_artifacts |
boolean | false |
Upload artifacts for gitops-update workflow |
force_multiplatform |
boolean | false |
Force multi-platform build (amd64+arm64) even for beta/rc tags |
enable_cosign_sign |
boolean | true |
Sign images with cosign keyless (OIDC) signing. Requires id-token: write in caller |
Uses secrets: inherit pattern. Required secrets:
| Secret | Description | Required When |
|---|---|---|
DOCKER_USERNAME |
DockerHub username | enable_dockerhub: true |
DOCKER_PASSWORD |
DockerHub password/token | enable_dockerhub: true |
MANAGE_TOKEN |
GitHub token for GHCR | enable_ghcr: true |
SLACK_WEBHOOK_URL |
Slack webhook for notifications | Optional |
The workflow automatically selects platforms based on the tag type:
| Tag Type | force_multiplatform |
Platforms | Rationale |
|---|---|---|---|
| Beta | false (default) |
linux/amd64 |
Faster CI for development |
| Beta | true |
linux/amd64,linux/arm64 |
Multi-arch needed in dev |
| RC | false (default) |
linux/amd64 |
Faster CI for staging |
| RC | true |
linux/amd64,linux/arm64 |
Multi-arch needed in staging |
| Release | N/A | linux/amd64,linux/arm64 |
Always full multi-arch support |
Generated tags based on semantic versioning:
| Tag Pattern | Example | When Applied |
|---|---|---|
{{version}} |
1.0.0-beta.1 |
Always |
{{major}} |
1 |
Release tags only |
When filter_paths is provided, the workflow:
- Detects which components have changes in the tagged commit
- Builds only the changed components
- Names images using the pattern:
{app_name_prefix}-{component_name}
Example:
filter_paths: |-
components/api
components/worker
app_name_prefix: "myapp"Changed files in components/api/ → Builds myapp-api image
Changed files in components/worker/ → Builds myapp-worker image
When enable_gitops_artifacts: true:
- Creates artifact files with version tags (without
vprefix) - Uploads as GitHub Actions artifacts
- Can be consumed by
gitops-update.ymlworkflow
Artifact pattern: gitops-tags-{app_name}
Automatically sends notifications on completion:
- ✅ Success: Green notification with workflow details
- ❌ Failure: Red notification with failed job names
- Skipped if
SLACK_WEBHOOK_URLsecret is not configured
- Detects changed paths (monorepo) or sets single-app mode
- Determines build platforms based on tag type
- Outputs matrix for build job
- Runs for each component in the matrix
- Builds and pushes Docker images
- Creates GitOps artifacts if enabled
- Sends Slack notification on completion
Container images are signed by default using Sigstore cosign with keyless (OIDC) signing. The GitHub Actions identity is used as proof of provenance — no private keys are needed.
Callers must grant id-token: write for signing to work:
permissions:
contents: read
packages: write
id-token: write # required for cosign keyless signingjobs:
build:
uses: LerianStudio/github-actions-shared-workflows/.github/workflows/build.yml@v1.0.0
with:
enable_cosign_sign: false
secrets: inheritcosign verify \
--certificate-identity-regexp="^https://github\.com/LerianStudio/.+/.github/workflows/.+@refs/(heads|tags)/.+$" \
--certificate-oidc-issuer="https://token.actions.githubusercontent.com" \
docker.io/lerianstudio/my-app@sha256:abc123...- Use semantic versioning tags:
v1.0.0,v1.0.0-beta.1,v1.0.0-rc.1 - Enable both registries: DockerHub for public access, GHCR for GitHub integration
- Use GitOps artifacts: For automated deployment pipelines
- Configure Slack: For build notifications to your team channel
Issue: Workflow runs but no images are built
Solution:
- For monorepo: Ensure changed files are within
filter_paths - Check tag format matches expected pattern
Issue: Cannot push to GitHub Container Registry
Solution:
- Ensure
MANAGE_TOKENhaspackages: writepermission - Check repository visibility settings
Issue: ARM64 builds take too long
Solution: ARM64 builds only run on release tags by default. Beta/RC tags build amd64 only for faster CI. If you need ARM64 on beta/rc, use force_multiplatform: true and be aware of the longer build times.
- GitOps Update - Update deployments after build
- Release - Create releases that trigger builds
- Slack Notify - Notification system
Last Updated: 2025-12-09 Version: 1.0.0