golang: Missing package in 1.18

golang:1.17.8-alpine came with the git executable - presumably to accommodate go get - but golang:1.18-alpine does not - presumably because of the breaking change to go get that accompanied the new version.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (5 by maintainers)

Commits related to this issue

Most upvoted comments

The non-Alpine (Debian-based) images do contain all the tools – they’re FROM buildpack-deps:XXX-scm, which already includes most of the SCMs from https://github.com/golang/go/wiki/GoGetTools (by design).

Quoting again from the Alpine section of https://hub.docker.com/_/golang (https://github.com/docker-library/docs/tree/0b63293e37969498f85b48a9bcb5908993052ddc/golang#golangversion-alpine):

This variant is highly experimental, and not officially supported by the Go project (see golang/go#19938 for details). … To minimize image size, additional related tools (such as git, gcc, or bash) are not included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar). See also docker-library/golang#250 (comment) for a longer explanation.

The Alpine variants exist specifically to be much smaller than the default base, not to be a full-featured 100% complete environment ready-for-use like the non-Alpine variants are.

If you really don’t need .git for your builds at all, you can add .git to .dockerignore too 👀

Here’s a simple reproduction:

docker run -it --rm golang:1.18-alpine sh -c '
  mkdir /app; cd /app
  echo "package main;func main(){}" > main.go
  go mod init example
  mkdir .git
  echo ---
  go build .'
go: creating new go.mod: module example
go: to add module requirements and sums:
        go mod tidy
---
go: missing Git command. See https://golang.org/s/gogetcmd
error obtaining VCS status: exec: "git": executable file not found in $PATH
        Use -buildvcs=false to disable VCS stamping.

As it says, running go build -buildvcs=false . fixes it. Deleting .git also fixes it.

It looks like the new VCS status embedding feature in go 1.18 requires git, and instead of silently skipping buildvcs when git isn’t available, it shows an error.

@ocket8888, please consider re-opening this issue.

There is a new std package in go 1.18, debug/buildinfo, which requires git in order to stamp the version control info on the binary (svn, hg, and bzr might be required too?). It’s unfortunate that this may unnecessarily break some use cases (e.g. tests), but I think it’s reasonable to expect that the official docker image should support the std packages of the language.

But that’s impossible, the Go team knows that it’s unacceptable to ever make a breaking change under any circumstances 🙄

More seriously it looks from that bottom comment like they’re open to fixing this - but at any rate it’s not an issue with this Docker image, but an upstream problem. I’ll take it up with them. Thanks.

I went back to 1.17.8 and confirmed that there’s no git anywhere on the image filesystem. So I’m not sure what was actually broken.