dockerfile-go-mod-download-without-cache-mount
Detects Go Dockerfiles that run go mod download without a visible BuildKit cache mount on the same instruction.
This rule looks for:
- a Docker build discovered from GitHub Actions
go.modin the build contextRUN go mod download- no
--mount=type=cacheon that Dockerfile instruction
Why it matters:
- Go module downloads populate the module cache.
- Without a BuildKit cache mount such as
/go/pkg/mod, Docker rebuilds can repeatedly download dependencies. - Depot’s optimized Go Dockerfile mounts the module cache during dependency download.
What to do:
- Add a BuildKit cache mount for
/go/pkg/modto thego mod downloadstep. - Keep
go.modandgo.sumcopied before broader source files. - Consider running
go mod verifyafter download when it fits the repository’s policy.
This rule focuses on Docker build cache behavior, not general Go module correctness.