Workflow: .github/workflows/docker-image-build.yml
This workflow builds Docker images with optimized caching for faster builds. It supports multi-architecture builds for both linux/amd64 and linux/arm64 platforms using the "image" exporter type which properly handles manifest lists required for multi-architecture images.
image: name of the docker image, e.g.ghcr.io/requirecloud/some-imageregistry: Docker Registry where to push the image. Default value:ghcr.iopush: Should the image actually be pushed to Registry. Default value:true
The workflow uses two types of caching to speed up builds:
-
GitHub Actions Cache: Always enabled, persists between workflow runs
- Repository-wide cache: Shared across all branches
- Branch-specific cache: Optimized for the current branch
-
Registry Cache: Enabled when
pushis set totrue, stores cache in the registry with abuildcachetag
These caching mechanisms significantly reduce build times by reusing layers from previous builds.
For best caching results:
-
Structure your Dockerfile efficiently:
- Place infrequently changing layers (e.g., base image, dependencies) at the beginning
- Place frequently changing layers (e.g., application code) at the end
-
Use .dockerignore file to exclude unnecessary files from the build context
-
Ensure consistent build environments across different workflows that use the same image
-
Be patient with initial builds - caching benefits become apparent after the first few builds
name: Build my Docker image
on:
push:
workflow_dispatch:
jobs:
docker-image-build:
uses: requirecloud/gha-workflows/.github/workflows/docker-image-build.yml@main
with:
image: ghcr.io/requirecloud/some-image
secrets: inherit