Skip to content

Commit ad5ded2

Browse files
committed
Remove go mod download step
`go build` will automatically download module dependencies. In many cases, that is a much smaller set of modules than what is downloaded by `go mod download`. Using the https://github.com/github/github-mcp-server Go application as an example below. Size of GOMODCACHE with `go mod download`: $ go clean -i -r -cache -modcache $ go mod download $ du -sh ~/go/pkg/mod 186M /home/jun/go/pkg/mod Size of GOMODCACHE with `go build`: $ go clean -i -r -cache -modcache $ CGO_ENABLED=0 go build -ldflags="-s -w" cmd/github-mcp-server/main.go go: downloading github.com/spf13/viper v1.20.1 go: downloading github.com/mark3labs/mcp-go v0.18.0 go: downloading github.com/google/go-github/v69 v69.2.0 go: downloading github.com/sirupsen/logrus v1.9.3 go: downloading github.com/spf13/cobra v1.9.1 go: downloading golang.org/x/sys v0.31.0 go: downloading github.com/spf13/afero v1.14.0 go: downloading github.com/fsnotify/fsnotify v1.8.0 go: downloading github.com/spf13/cast v1.7.1 go: downloading github.com/go-viper/mapstructure/v2 v2.2.1 go: downloading github.com/subosito/gotenv v1.6.0 go: downloading gopkg.in/yaml.v3 v3.0.1 go: downloading github.com/spf13/pflag v1.0.6 go: downloading github.com/pelletier/go-toml/v2 v2.2.3 go: downloading github.com/sagikazarmark/locafero v0.9.0 go: downloading golang.org/x/text v0.23.0 go: downloading github.com/google/uuid v1.6.0 go: downloading github.com/yosida95/uritemplate/v3 v3.0.2 go: downloading github.com/sourcegraph/conc v0.3.0 go: downloading github.com/google/go-querystring v1.1.0 $ du -sh ~/go/pkg/mod 80M /home/jun/go/pkg/mod Reference: https://stackoverflow.com/a/68172023/7902371 Signed-off-by: Eng Zer Jun <[email protected]>
1 parent 9f89330 commit ad5ded2

File tree

2 files changed

+0
-9
lines changed

2 files changed

+0
-9
lines changed

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

-5
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,6 @@ FROM golang:1.21.1-alpine as base-build
198198
199199
WORKDIR /build
200200
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
205-
206201
RUN --mount=type=cache,target=/go/pkg/mod \
207202
--mount=type=cache,target=/root/.cache/go-build \
208203
--mount=type=bind,target=. \

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

-4
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,6 @@ 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-
RUN --mount=type=cache,target=/go/pkg/mod \
194-
--mount=type=bind,source=vm/go.mod,target=go.mod \
195-
--mount=type=bind,source=vm/go.sum,target=go.sum \
196-
go mod download
197193
RUN --mount=type=cache,target=/go/pkg/mod \
198194
--mount=type=cache,target=/root/.cache/go-build \
199195
--mount=type=bind,source=vm/.,target=. \

0 commit comments

Comments
 (0)