Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ Before setting up build workflows, note the following:
- If your project needs different images for dev and prod (e.g. statically replaced variables, build-time validation that requires environment-specific values), use a [matrix strategy](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow) so dev and prod builds run in parallel.
- If you have a **monorepo**, use separate jobs per image so they build concurrently on tag push.
- **Validate your Dockerfile layer caching.** Check each layer for cache-busting pitfalls: changing commit SHAs baked into build args, rotating secrets passed as build args instead of `--mount=type=secret`, non-deterministic package installs (missing lockfiles), timestamps in generated files, and `COPY . .` placed before dependency installation layers.
- **Only enable `push-cache` for images you intend to push to ECR.** The build action reads from the registry cache by default, but only writes back to it when `push-cache: "true"` is set. Enable this on builds that will be pushed so the cache stays up to date; leave it off for local-only or throwaway builds to avoid polluting the cache.
18 changes: 6 additions & 12 deletions build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ inputs:
description: "Newline-separated list of Docker build secrets (id=value)"
required: false
default: ""
image-tag:
description: "Image tag override (defaults to tag from git ref)"
push-cache:
description: "Push layer cache to registry (set to 'true' to enable)"
required: false
default: ""

default: "false"
outputs:
image-tag:
description: "Resolved image tag"
description: "Resolved image tag (first 6 chars of commit SHA)"
value: ${{ steps.resolve-tag.outputs.image-tag }}

runs:
Expand All @@ -47,12 +46,7 @@ runs:
id: resolve-tag
shell: bash
run: |
if [[ -n "${{ inputs.image-tag }}" ]]; then
IMAGE_TAG="${{ inputs.image-tag }}"
else
TAG_NAME=${GITHUB_REF##*/}
IMAGE_TAG=$(echo $TAG_NAME | sed 's/^v//')
fi
IMAGE_TAG="${GITHUB_SHA:0:6}"
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "image-tag=$IMAGE_TAG" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -85,4 +79,4 @@ runs:
build-args: ${{ inputs.build-args }}
secrets: ${{ inputs.secrets }}
cache-from: type=registry,ref=${{ env.IMAGE_REGISTRY }}/${{ inputs.image-repo }}:cache
cache-to: type=registry,ref=${{ env.IMAGE_REGISTRY }}/${{ inputs.image-repo }}:cache,mode=max
cache-to: ${{ inputs.push-cache == 'true' && format('type=registry,ref={0}/{1}:cache,mode=max', env.IMAGE_REGISTRY, inputs.image-repo) || '' }}