perf: optimize docker build#39
Conversation
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
Code Review
This pull request updates the Dockerfile to use the BuildKit syntax directive and introduces cache mounts for Go modules and Go builds to optimize build performance. The feedback recommends pinning the Dockerfile syntax to the major version (1) rather than a specific minor version to receive automatic updates, and adding unique IDs to the cache mounts to prevent cache thrashing in shared CI/CD environments.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| @@ -1,3 +1,4 @@ | |||
| # syntax=docker/dockerfile:1.7 | |||
There was a problem hiding this comment.
Using a specific minor version like 1.7 for the Dockerfile syntax directive prevents the build from automatically receiving security updates, bug fixes, and performance improvements. It is highly recommended to use # syntax=docker/dockerfile:1 to pin to the major version 1, which automatically resolves to the latest stable minor release while maintaining backward compatibility.
# syntax=docker/dockerfile:1
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| go mod download |
There was a problem hiding this comment.
When using --mount=type=cache without a unique id, the cache is shared globally across all builds on the same runner that use the same target path. In a shared CI/CD environment with multiple Go projects, this can lead to cache thrashing and frequent evictions. Specifying a unique id (e.g., id=mpa-service-go-mod) ensures that this project's module cache is isolated and preserved.
RUN --mount=type=cache,id=mpa-service-go-mod,target=/go/pkg/mod \
go mod download
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| CGO_ENABLED=0 \ |
There was a problem hiding this comment.
To ensure cache isolation and prevent cache thrashing in shared CI/CD environments, specify unique ids for both the Go module cache and the Go build cache mounts. This ensures that the caches are dedicated to this project and not overwritten or evicted by other Go builds on the same runner.
RUN --mount=type=cache,id=mpa-service-go-mod,target=/go/pkg/mod \
--mount=type=cache,id=mpa-service-go-build,target=/root/.cache/go-build \
CGO_ENABLED=0 \
What?
Why?
How?
Testing?
Anything Else?