Skip to content

Commit 9103dff

Browse files
authored
Merge pull request #22388 from Juneezee/go-mod-mounts
docs: use bind mounts in Go Dockerfile examples
1 parent 814047f commit 9103dff

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

content/manuals/build/cache/optimize.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ tool you're using. Here are a few examples:
225225

226226
```dockerfile
227227
RUN --mount=type=cache,target=/go/pkg/mod \
228+
--mount=type=cache,target=/root/.cache/go-build \
228229
go build -o /app/hello
229230
```
230231

content/manuals/build/ci/github-actions/cache.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,16 @@ Example Dockerfile in `build/package/Dockerfile`
197197
FROM golang:1.21.1-alpine as base-build
198198
199199
WORKDIR /build
200-
RUN go env -w GOMODCACHE=/root/.cache/go-build
201200
202-
COPY go.mod go.sum ./
203-
RUN --mount=type=cache,target=/root/.cache/go-build go mod download
201+
RUN --mount=type=cache,target=/go/pkg/mod \
202+
--mount=type=bind,source=go.mod,target=go.mod \
203+
--mount=type=bind,source=go.sum,target=go.sum \
204+
go mod download
204205
205-
COPY ./src ./
206-
RUN --mount=type=cache,target=/root/.cache/go-build go build -o /bin/app /build/src
206+
RUN --mount=type=cache,target=/go/pkg/mod \
207+
--mount=type=cache,target=/root/.cache/go-build \
208+
--mount=type=bind,target=. \
209+
go build -o /bin/app ./src
207210
...
208211
```
209212

content/manuals/extensions/extensions-sdk/build/backend-extension-tutorial.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,9 @@ FROM node:17.7-alpine3.14 AS client-builder
190190
FROM golang:1.17-alpine AS builder
191191
ENV CGO_ENABLED=0
192192
WORKDIR /backend
193-
COPY vm/go.* .
194-
RUN --mount=type=cache,target=/go/pkg/mod \
195-
--mount=type=cache,target=/root/.cache/go-build \
196-
go mod download
197-
COPY vm/. .
198193
RUN --mount=type=cache,target=/go/pkg/mod \
199194
--mount=type=cache,target=/root/.cache/go-build \
195+
--mount=type=bind,source=vm/.,target=. \
200196
go build -trimpath -ldflags="-s -w" -o bin/service
201197

202198
FROM alpine:3.15

hack/releaser/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ FROM golang:${GO_VERSION}-alpine AS base
88
RUN apk add --no-cache openssl
99
ENV CGO_ENABLED=0
1010
WORKDIR /src
11-
COPY go.mod go.sum ./
12-
RUN --mount=type=cache,target=/go/pkg/mod \
13-
go mod download
1411

1512
FROM base AS releaser
1613
RUN --mount=type=bind,target=. \

0 commit comments

Comments
 (0)