Skip to content

fix(ci): properly cache dependencies in Docker layer for GHA cache#11

Merged
MaxAnderson95 merged 1 commit into
mainfrom
fix/build-caching-final
Jan 17, 2026
Merged

fix(ci): properly cache dependencies in Docker layer for GHA cache#11
MaxAnderson95 merged 1 commit into
mainfrom
fix/build-caching-final

Conversation

@MaxAnderson95

Copy link
Copy Markdown
Owner

Summary

Fixes build caching so Maven and npm dependencies are not re-downloaded on every build.

Root Causes Fixed

  1. pom.xml was modified before Docker build - The workflow ran ./mvnw versions:set on the runner, modifying pom.xml before sending it to Docker. Since version changed each build, the Docker layer cache was invalidated every time.

  2. BuildKit cache mounts are ephemeral - The --mount=type=cache syntax only persists within the BuildKit daemon, which is destroyed after each GHA run. The type=gha cache backend caches Docker layers only, NOT cache mount contents.

Changes

  • Remove setup-java and setup-node steps (no longer needed)
  • Remove pre-build version modification steps
  • Pass VERSION as Docker build-arg instead
  • Remove BuildKit cache mounts from all Dockerfiles
  • Store dependencies in Docker layer (properly cached by GHA)
  • Change npm install to npm ci for faster CI builds

How Caching Now Works

Build 1 (v1.0.0):
  pom.xml (0.0.0-dev) → COPY → creates layer (cache miss)
  mvn dependency:go-offline → RUN → creates layer with deps (cache miss)
  src/ → COPY → creates layer
  mvn versions:set + package → RUN → builds v1.0.0

Build 2 (v1.0.1, same dependencies):
  pom.xml (0.0.0-dev) → COPY → CACHE HIT (same content!)
  mvn dependency:go-offline → RUN → CACHE HIT (no download needed!)
  src/ → COPY → HIT or MISS depending on source changes
  mvn versions:set + package → RUN → builds v1.0.1 (only this runs)

- Remove setup-java/setup-node steps (no longer run Maven/npm on runner)
- Remove pre-build version modification (was invalidating Docker cache)
- Pass VERSION as Docker build-arg instead
- Remove BuildKit cache mounts (ephemeral, not persisted by GHA)
- Store dependencies in Docker layer (cached by type=gha)
- Change npm install to npm ci for faster CI builds

The key fix: pom.xml stays at 0.0.0-dev in repo, so the dependency
download layer has a stable cache key. Version is set inside Docker
after deps are downloaded, so only the final build step runs on
subsequent builds with the same dependencies.
@MaxAnderson95 MaxAnderson95 merged commit c9a1a1c into main Jan 17, 2026
@MaxAnderson95 MaxAnderson95 deleted the fix/build-caching-final branch January 17, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant