-
Notifications
You must be signed in to change notification settings - Fork 8.1k
docs: use bind mounts in Go Dockerfile examples #22388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
ca688ad
cf728b4
9783174
5ed1d65
a391c8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -197,13 +197,11 @@ Example Dockerfile in `build/package/Dockerfile` | |
| FROM golang:1.21.1-alpine as base-build | ||
|
|
||
| WORKDIR /build | ||
| RUN go env -w GOMODCACHE=/root/.cache/go-build | ||
|
|
||
| COPY go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/root/.cache/go-build go mod download | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps @crazy-max or @tonistiigi have ideas on this part; yes, it looks like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For projects that don't vendor the dependencies this command is still useful so we should keep it imo.
For multi-stage but also if doing a multiplatform build it will download it once similar to https://github.com/docker/compose/blob/6a2d16bd106bd84065e790b5c2b111509e8a6fd9/Dockerfile#L50-L54 |
||
|
|
||
| COPY ./src ./ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also double-checking with @crazy-max and @tonistiigi on this one; i.e., if copying the source was intentional here (restoring cache or otherwise?). These are always tricky as there's no "single" rule, some bits may depend on your situation. |
||
| RUN --mount=type=cache,target=/root/.cache/go-build go build -o /bin/app /build/src | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| --mount=type=bind,target=. \ | ||
Juneezee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| go build -o /bin/app /build/src | ||
Juneezee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ... | ||
| ``` | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this one would still be useful; the default would be
~/.cache/go-build, but as the mounts are hard-coded to a location, it could be useful to explicitly configure go to use a location (for the mounts).Possibly it could be a custom path so that the cache-directory can be set up to a predictable location for situations where you want to run the build as a user (
USER) that's notroot🤔