mirror of
https://github.com/dockersrc/go
synced 2026-06-24 14:01:08 -04:00
28f2167e82
Go is now downloaded from go.dev/dl at build time (always latest stable, never pinned). All tools are baked into /usr/local/bin so they are on PATH out of the box. Module cache and build cache live in the volumed GOPATH (/usr/local/share/go) so they persist across container restarts without re-downloading. - Dockerfile: add /usr/local/go/bin to PATH in both build and final stage - rootfs/root/docker/setup/05-custom.sh: full Go install + tool install - detects arch (amd64/arm64/armv6l/386) via uname -m - fetches latest stable version from go.dev/dl?mode=json via jq - extracts to /usr/local/go; symlinks go+gofmt to /usr/local/bin - installs with GOBIN=/usr/local/bin (baked into image, not in volume): gopls, goimports, gofumpt, stringer, golangci-lint, staticcheck, govulncheck, gotestsum, dlv, air, goreleaser, wire, mockgen (uber), ko, protoc-gen-go, protoc-gen-go-grpc - cleans modcache and build cache after install to keep layer lean - rootfs/etc/profile.d/go.sh: add /usr/local/go/bin prepend so interactive shells always find the Go distribution binaries first Volume strategy: /usr/local/share/go → GOPATH (module cache + build cache + user bins) Mount a named volume or bind-mount here to avoid re-downloading modules: docker run -v go-cache:/usr/local/share/go casjaysdevdocker/go Dockerfile rootfs/etc/profile.d/go.sh rootfs/root/docker/setup/05-custom.sh
26 lines
901 B
Bash
26 lines
901 B
Bash
# Go environment - sourced by /etc/profile for interactive login shells.
|
|
#
|
|
# All Go state lives under /usr/local/share/go (declared as a Docker
|
|
# VOLUME). The paths /go, /root/go, /root/.go, /root/.local/share/go and
|
|
# /data/go are symlinks to that location, so any of them can be used
|
|
# interchangeably and the data persists across container rebuilds when
|
|
# the volume is named.
|
|
#
|
|
# The Go distribution itself lives at /usr/local/go (baked into the image,
|
|
# not volumed). Tools installed at build time land in /usr/local/bin.
|
|
|
|
export GOPATH="${GOPATH:-/usr/local/share/go}"
|
|
export GOCACHE="${GOCACHE:-${GOPATH}/cache}"
|
|
export CGO_ENABLED="${CGO_ENABLED:-0}"
|
|
export GOTOOLCHAIN="${GOTOOLCHAIN:-auto}"
|
|
|
|
case ":${PATH}:" in
|
|
*":/usr/local/go/bin:"*) ;;
|
|
*) export PATH="/usr/local/go/bin:${PATH}" ;;
|
|
esac
|
|
|
|
case ":${PATH}:" in
|
|
*":${GOPATH}/bin:"*) ;;
|
|
*) export PATH="${GOPATH}/bin:${PATH}" ;;
|
|
esac
|