There are a couple ways I know of that you can do this. You can vendor or copy as you mention. Another approach is to create a "build" image that contains relevant credentials and a few `go env -w` directives to set up your build environment, which you build separately and derive other projects from.
``` FROM golang:1.16-alpine3.13 RUN apk --no-cache add ca-certificates git openssh # cert not checked in to repo, (download with artifact script to rebuild base images) ADD certs/mycert.crt /usr/local/share/ca-certificates/mycert.crt RUN chmod 0600 /usr/local/share/ca-certificates/mycert.crt RUN update-ca-certificates # if you host a proxy, use these two lines or similar (see https://golang.org/ref/mod#private-modules) # RUN go env -w GOPROXY=https://proxy.corp.example.com # RUN go env -w GONOSUMDB=corp.example.com # otherwise, make sure you don't reach out to public proxy/sum for internal packages RUN go env -w GOPRIVATE=vcs.package.prefix/* # gitconfig for vcs to use "ssh://git@" instead of "https://" ADD gitconfig /root/.gitconfig # internal VCS creds (probably want to use a "deployment key") ADD ssh /root/.ssh RUN chmod 0600 /root/.ssh/id_rsa /root/.ssh/config RUN chmod 0644 /root/.ssh/id_rsa.pub ``` And then the gitconfig you copy in might be something like: ``` [url "ssh://git@my.internal.bitbucket:7999"] insteadOf = "https://my.internal.bitbucket/scm" ``` This should create a build image that will know about your VCS and download modules from it directly. In your project, you can either do the standard copy of your mod and sum files and go download, but you can also use the new buildkit features to mount a shared cache for both modules and artifacts: ``` # syntax = docker/dockerfile:1-experimental FROM myregistry:base as base # ... RUN --mount=type=cache,id=myproject_mod,target=/go/pkg/mod \ --mount=type=cache,id=myproject_cache,target=/root/.cache/go-build \ go build ``` On Tuesday, January 15, 2019 at 11:01:02 AM UTC-5 greg...@unity3d.com wrote: > On Monday, January 14, 2019 at 4:52:37 PM UTC-8, Philip Nelson wrote: >> >> You can't copy from outside the context but you can volume mount it. In >> my docker-compose.yml I have the following for a golang:1.11-alpine image >> derivative: >> >> ``` >> volumes: >> - ${GOPATH}:/go >> ``` >> >> Phil >> >>> >>> > Oh! That's interesting. Thanks! > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/4b13ada3-362d-4075-9309-0e59e2595fd4n%40googlegroups.com.