2022-07-26 16:24:27 +03:00
|
|
|
FROM alpine:3.13
|
|
|
|
|
|
|
|
ENV PATH /usr/local/go/bin:$PATH
|
|
|
|
|
|
|
|
RUN set -eux; \
|
2022-07-26 19:39:53 +03:00
|
|
|
apk add --no-cache ca-certificates jq curl; \
|
|
|
|
([ ! -e /etc/nsswitch.conf ] && echo 'hosts: files dns' > /etc/nsswitch.conf); \
|
2022-07-26 16:24:27 +03:00
|
|
|
apk add --no-cache --virtual .fetch-deps gnupg; \
|
|
|
|
arch="$(apk --print-arch)"; \
|
2022-07-26 19:39:53 +03:00
|
|
|
export GOVERSION="$(curl -fsSL 'https://go.dev/dl/?mode=json&include=1.18' | jq -r '.[0].version')"; \
|
2022-07-26 16:24:27 +03:00
|
|
|
case "$arch" in \
|
|
|
|
'x86_64') \
|
|
|
|
export GOAMD64='v1' GOARCH='amd64' GOOS='linux'; \
|
|
|
|
;; \
|
|
|
|
'armhf') \
|
|
|
|
export GOARCH='arm' GOARM='6' GOOS='linux'; \
|
|
|
|
;; \
|
|
|
|
'armv7') \
|
|
|
|
export GOARCH='arm' GOARM='7' GOOS='linux'; \
|
|
|
|
;; \
|
|
|
|
'aarch64') \
|
|
|
|
export GOARCH='arm64' GOOS='linux'; \
|
|
|
|
;; \
|
|
|
|
'x86') \
|
2022-07-26 19:56:37 +03:00
|
|
|
export GOARCH='386' GOOS='linux'; \
|
2022-07-26 16:24:27 +03:00
|
|
|
;; \
|
|
|
|
'ppc64le') \
|
|
|
|
export GOARCH='ppc64le' GOOS='linux'; \
|
|
|
|
;; \
|
|
|
|
's390x') \
|
|
|
|
export GOARCH='s390x' GOOS='linux'; \
|
|
|
|
;; \
|
|
|
|
*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
|
|
|
|
esac; \
|
|
|
|
# https://github.com/golang/go/issues/38536#issuecomment-616897960
|
2022-07-26 19:39:53 +03:00
|
|
|
url="https://dl.google.com/go/$GOVERSION.src.tar.gz"; \
|
2022-07-26 16:24:27 +03:00
|
|
|
# the precompiled binaries published by Go upstream are not compatible with Alpine, so we always build from source here 😅
|
|
|
|
\
|
2022-07-26 18:12:25 +03:00
|
|
|
wget -O go.tgz.asc "$url.asc"; \
|
|
|
|
wget -O go.tgz "$url"; \
|
2022-07-26 16:24:27 +03:00
|
|
|
\
|
|
|
|
# https://github.com/golang/go/issues/14739#issuecomment-324767697
|
|
|
|
GNUPGHOME="$(mktemp -d)"; export GNUPGHOME; \
|
|
|
|
# https://www.google.com/linuxrepositories/
|
|
|
|
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys 'EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796'; \
|
|
|
|
# let's also fetch the specific subkey of that key explicitly that we expect "go.tgz.asc" to be signed by, just to make sure we definitely have it
|
|
|
|
gpg --batch --keyserver keyserver.ubuntu.com --recv-keys '2F52 8D36 D67B 69ED F998 D857 78BD 6547 3CB3 BD13'; \
|
|
|
|
gpg --batch --verify go.tgz.asc go.tgz; \
|
|
|
|
gpgconf --kill all; \
|
|
|
|
rm -rf "$GNUPGHOME" go.tgz.asc; \
|
|
|
|
\
|
|
|
|
tar -C /usr/local -xzf go.tgz; \
|
|
|
|
rm go.tgz; \
|
|
|
|
\
|
2022-07-26 19:39:53 +03:00
|
|
|
apk add --no-cache --virtual .build-deps \
|
|
|
|
bash \
|
|
|
|
gcc \
|
|
|
|
go \
|
|
|
|
musl-dev \
|
|
|
|
; \
|
|
|
|
\
|
|
|
|
export GOCACHE='/tmp/gocache'; \
|
|
|
|
\
|
|
|
|
( \
|
|
|
|
cd /usr/local/go/src; \
|
2022-07-26 16:24:27 +03:00
|
|
|
# set GOROOT_BOOTSTRAP + GOHOST* such that we can build Go successfully
|
2022-07-26 19:39:53 +03:00
|
|
|
export GOROOT_BOOTSTRAP="$(go env GOROOT)" GOHOSTOS="$GOOS" GOHOSTARCH="$GOARCH"; \
|
|
|
|
./make.bash; \
|
|
|
|
); \
|
|
|
|
\
|
|
|
|
apk del --no-network .build-deps; \
|
|
|
|
\
|
2022-07-26 16:24:27 +03:00
|
|
|
# remove a few intermediate / bootstrapping files the official binary release tarballs do not contain
|
2022-07-26 19:39:53 +03:00
|
|
|
rm -rf \
|
|
|
|
/usr/local/go/pkg/*/cmd \
|
|
|
|
/usr/local/go/pkg/bootstrap \
|
|
|
|
/usr/local/go/pkg/obj \
|
|
|
|
/usr/local/go/pkg/tool/*/api \
|
|
|
|
/usr/local/go/pkg/tool/*/go_bootstrap \
|
|
|
|
/usr/local/go/src/cmd/dist/dist \
|
|
|
|
"$GOCACHE" \
|
|
|
|
; \
|
2022-07-26 16:24:27 +03:00
|
|
|
\
|
|
|
|
apk del --no-network .fetch-deps; \
|
|
|
|
\
|
|
|
|
go version
|
|
|
|
|
|
|
|
ENV GOPATH /go
|
|
|
|
ENV PATH $GOPATH/bin:$PATH
|
|
|
|
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
|
|
|
|
WORKDIR $GOPATH
|
|
|
|
|
2022-07-26 17:58:34 +03:00
|
|
|
RUN set -eux; \
|
2022-07-26 19:39:53 +03:00
|
|
|
apk add --no-cache bash make git gcc libc-dev dumb-init && \
|
|
|
|
go install github.com/go-delve/delve/cmd/dlv@latest && \
|
|
|
|
go install github.com/cosmtrek/air@latest && \
|
|
|
|
go install github.com/jstemmer/go-junit-report@latest && \
|
|
|
|
go install github.com/axw/gocov/gocov@latest && \
|
|
|
|
chmod -R 777 "$GOPATH"
|
2022-07-26 17:58:34 +03:00
|
|
|
WORKDIR /
|
2022-07-26 16:24:27 +03:00
|
|
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|