Add option to "go install" all dependencies for Docker build caching #1374
Description
Some context: I'm setting up a development workflow for Go-based services that will run on a Kubernetes cluster. I'm setting up a minikube-based dev environment using a setup like Draft (not just using Draft because of Azure/draft#432) where i watch for changes to the source files, and then re-build a docker container and run it on Minikube. I'm trying to minimize the time it takes to deploy a change.
I was able to cut the docker build
time from about 15 seconds down to about 8 by go install
ing my dependencies, and then adding my source files and compiling those, because it means that the dependencies don't need to be re-compiled during each build.
My dockerfile looks something like this:
FROM golang:1.9.2-alpine3.6
RUN apk add --no-cache curl && \
curl -Lo /bin/rq https://s3-eu-west-1.amazonaws.com/record-query/record-query/x86_64-unknown-linux-musl/rq && \
chmod +x /bin/rq
RUN mkdir -p /go/src/mycompany/myapp
ENV GOPATH=/go
WORKDIR /go/src/mycompany/myapp
ADD vendor /go/src/
ADD Gopkg.lock /go/src/mycompany/myapp
RUN cd /go/src && \
cat mycompany/myapp/Gopkg.lock | /bin/rq -tJ 'map "projects" | spread | map "name"' | cat | tr -d '"' | xargs -I % go install %/...
ADD *.go ./
RUN go build -o app .
This works, but the bit where i'm using rq
to parse Gopkg.lock
is a pretty crazy hack. Would you be open to adding something like dep install-deps
or dep ensure -vendor-only -install
that would go install
vendored dependencies? Or perhaps there's a simpler way of accomplishing what I'm trying to do, and we could update https://github.com/stephenafamo/dep/blob/master/docs/FAQ.md#how-do-i-use-dep-with-docker ?