Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
cmd/go: [modules + integration] go mod build, build all the binaries provided by a module #31323
This report is part of a series, filled at the request of @mdempsky, focused at making Go modules integrator-friendly.
Please do not close or mark it as duplicate before making sure you’ve read and understood the general context. A lot of work went into identifying problems points precisely.
Go needs an official
Go modules are wonderful and exciting, until you realise they only deal with the code download part. One stills need to dissect individual Go packages in the next stages of a CI/CD Go-related job.
The Go module concept should be extended to the rest of Go code processing phases.
I got to really need this in Container related environments.
Normally, I use a previous STEP in Dockerfile in order to download all module dependencies and then I compile the program, so that Docker will cache the module download step and then only execute the program compilation. In newer Golang versions, some modules binary becomes "incompatible" so that Golang will have to compile them along with our program, so that build time becomes very slow.
If we have the before mentioned "go mod build", it would compile all dependencies objects as ".a" files and them only link it to our program at the later stage, making build time during development or CI/CD much faster.
See a sample Dockerfile I use in almost every Golang project of mine (it used to run in less than 5secs before "incompatibilities"):
FROM golang:1.14.3-alpine3.11 AS BUILD RUN apk add build-base ENV GO111MODULE 'on' WORKDIR /app ADD /go.mod /app ADD /go.sum /app RUN go mod download #now build source code ADD / /app RUN go build -x -o /bin/userme-demo-api