|
| 1 | +FROM alpine:3.10 |
| 2 | + |
| 3 | +RUN apk add --no-cache \ |
| 4 | + ca-certificates |
| 5 | + |
| 6 | +# set up nsswitch.conf for Go's "netgo" implementation |
| 7 | +# - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275 |
| 8 | +# - docker run --rm debian:stretch grep '^hosts:' /etc/nsswitch.conf |
| 9 | +RUN [ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf |
| 10 | + |
| 11 | +ENV GOLANG_VERSION 1.12.6 |
| 12 | + |
| 13 | +RUN set -eux; \ |
| 14 | + apk add --no-cache --virtual .build-deps \ |
| 15 | + bash \ |
| 16 | + gcc \ |
| 17 | + musl-dev \ |
| 18 | + openssl \ |
| 19 | + go \ |
| 20 | + ; \ |
| 21 | + export \ |
| 22 | +# set GOROOT_BOOTSTRAP such that we can actually build Go |
| 23 | + GOROOT_BOOTSTRAP="$(go env GOROOT)" \ |
| 24 | +# ... and set "cross-building" related vars to the installed system's values so that we create a build targeting the proper arch |
| 25 | +# (for example, if our build host is GOARCH=amd64, but our build env/image is GOARCH=386, our build needs GOARCH=386) |
| 26 | + GOOS="$(go env GOOS)" \ |
| 27 | + GOARCH="$(go env GOARCH)" \ |
| 28 | + GOHOSTOS="$(go env GOHOSTOS)" \ |
| 29 | + GOHOSTARCH="$(go env GOHOSTARCH)" \ |
| 30 | + ; \ |
| 31 | +# also explicitly set GO386 and GOARM if appropriate |
| 32 | +# https://github.com/docker-library/golang/issues/184 |
| 33 | + apkArch="$(apk --print-arch)"; \ |
| 34 | + case "$apkArch" in \ |
| 35 | + armhf) export GOARM='6' ;; \ |
| 36 | + x86) export GO386='387' ;; \ |
| 37 | + esac; \ |
| 38 | + \ |
| 39 | + wget -O go.tgz "https://golang.org/dl/go$GOLANG_VERSION.src.tar.gz"; \ |
| 40 | + echo 'c96c5ccc7455638ae1a8b7498a030fe653731c8391c5f8e79590bce72f92b4ca *go.tgz' | sha256sum -c -; \ |
| 41 | + tar -C /usr/local -xzf go.tgz; \ |
| 42 | + rm go.tgz; \ |
| 43 | + \ |
| 44 | + cd /usr/local/go/src; \ |
| 45 | + ./make.bash; \ |
| 46 | + \ |
| 47 | + rm -rf \ |
| 48 | +# https://github.com/golang/go/blob/0b30cf534a03618162d3015c8705dd2231e34703/src/cmd/dist/buildtool.go#L121-L125 |
| 49 | + /usr/local/go/pkg/bootstrap \ |
| 50 | +# https://golang.org/cl/82095 |
| 51 | +# https://github.com/golang/build/blob/e3fe1605c30f6a3fd136b561569933312ede8782/cmd/release/releaselet.go#L56 |
| 52 | + /usr/local/go/pkg/obj \ |
| 53 | + ; \ |
| 54 | + apk del .build-deps; \ |
| 55 | + \ |
| 56 | + export PATH="/usr/local/go/bin:$PATH"; \ |
| 57 | + go version |
| 58 | + |
| 59 | +ENV GOPATH /go |
| 60 | +ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH |
| 61 | + |
| 62 | +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" |
| 63 | +WORKDIR $GOPATH |
0 commit comments