Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update golang #10810

Merged
merged 1 commit into from
Aug 30, 2021
Merged

Update golang #10810

merged 1 commit into from
Aug 30, 2021

Conversation

tianon
Copy link
Member

@tianon tianon commented Aug 30, 2021

Changes:

Changes:

- docker-library/golang@922fb33: Merge pull request docker-library/golang#385 from infosiftr/one-template
- docker-library/golang@48e32c5: Combine Linux templates into one
@github-actions
Copy link

Diff for d5cfdf9:
diff --git a/_bashbrew-cat b/_bashbrew-cat
index ea54dbf..cc91806 100644
--- a/_bashbrew-cat
+++ b/_bashbrew-cat
@@ -3,23 +3,23 @@ GitRepo: https://github.com/docker-library/golang.git
 
 Tags: 1.16.7-alpine3.13, 1.16-alpine3.13
 Architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
-GitCommit: 4c1da70f967b2b38b254e166e787d017cc9ca351
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.16/alpine3.13
 
 Tags: 1.16.7-alpine3.14, 1.16-alpine3.14, 1.16.7-alpine, 1.16-alpine
 Architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
-GitCommit: 4c1da70f967b2b38b254e166e787d017cc9ca351
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.16/alpine3.14
 
 Tags: 1.16.7-bullseye, 1.16-bullseye
 SharedTags: 1.16.7, 1.16
 Architectures: amd64, arm32v5, arm32v7, arm64v8, i386, mips64le, ppc64le, s390x
-GitCommit: 48a7371ed6055a97a10adb0b75756192ad5f1c97
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.16/bullseye
 
 Tags: 1.16.7-buster, 1.16-buster
 Architectures: amd64, arm32v5, arm32v7, arm64v8, i386, mips64le, ppc64le, s390x
-GitCommit: 4c1da70f967b2b38b254e166e787d017cc9ca351
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.16/buster
 
 Tags: 1.16.7-nanoserver-1809, 1.16-nanoserver-1809
@@ -38,7 +38,7 @@ Constraints: nanoserver-ltsc2022, windowsservercore-ltsc2022
 
 Tags: 1.16.7-stretch, 1.16-stretch
 Architectures: amd64, arm32v7, arm64v8, i386
-GitCommit: 4c1da70f967b2b38b254e166e787d017cc9ca351
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.16/stretch
 
 Tags: 1.16.7-windowsservercore-1809, 1.16-windowsservercore-1809
@@ -64,23 +64,23 @@ Constraints: windowsservercore-ltsc2022
 
 Tags: 1.17.0-alpine3.13, 1.17-alpine3.13, 1-alpine3.13, alpine3.13
 Architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
-GitCommit: 2cd4dab7bd702c7315864c428ba286827d50cda3
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.17/alpine3.13
 
 Tags: 1.17.0-alpine3.14, 1.17-alpine3.14, 1-alpine3.14, alpine3.14, 1.17.0-alpine, 1.17-alpine, 1-alpine, alpine
 Architectures: amd64, arm32v6, arm32v7, arm64v8, i386, ppc64le, s390x
-GitCommit: 2cd4dab7bd702c7315864c428ba286827d50cda3
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.17/alpine3.14
 
 Tags: 1.17.0-bullseye, 1.17-bullseye, 1-bullseye, bullseye
 SharedTags: 1.17.0, 1.17, 1, latest
 Architectures: amd64, arm32v5, arm32v7, arm64v8, i386, mips64le, ppc64le, s390x
-GitCommit: 48a7371ed6055a97a10adb0b75756192ad5f1c97
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.17/bullseye
 
 Tags: 1.17.0-buster, 1.17-buster, 1-buster, buster
 Architectures: amd64, arm32v5, arm32v7, arm64v8, i386, mips64le, ppc64le, s390x
-GitCommit: 2cd4dab7bd702c7315864c428ba286827d50cda3
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.17/buster
 
 Tags: 1.17.0-nanoserver-1809, 1.17-nanoserver-1809, 1-nanoserver-1809, nanoserver-1809
@@ -99,7 +99,7 @@ Constraints: nanoserver-ltsc2022, windowsservercore-ltsc2022
 
 Tags: 1.17.0-stretch, 1.17-stretch, 1-stretch, stretch
 Architectures: amd64, arm32v7, arm64v8, i386
-GitCommit: 2cd4dab7bd702c7315864c428ba286827d50cda3
+GitCommit: 48e32c58a6abc052253fba899cea876740cab262
 Directory: 1.17/stretch
 
 Tags: 1.17.0-windowsservercore-1809, 1.17-windowsservercore-1809, 1-windowsservercore-1809, windowsservercore-1809
diff --git a/golang_1.16-alpine/Dockerfile b/golang_1.16-alpine/Dockerfile
index 45cf368..ffa9381 100644
--- a/golang_1.16-alpine/Dockerfile
+++ b/golang_1.16-alpine/Dockerfile
@@ -6,8 +6,7 @@
 
 FROM alpine:3.14
 
-RUN apk add --no-cache \
-		ca-certificates
+RUN apk add --no-cache ca-certificates
 
 # set up nsswitch.conf for Go's "netgo" implementation
 # - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
@@ -19,16 +18,10 @@ ENV PATH /usr/local/go/bin:$PATH
 ENV GOLANG_VERSION 1.16.7
 
 RUN set -eux; \
-	apk add --no-cache --virtual .build-deps \
-		bash \
-		gcc \
-		gnupg \
-		go \
-		musl-dev \
-		openssl \
-	; \
-	apkArch="$(apk --print-arch)"; \
-	case "$apkArch" in \
+	apk add --no-cache --virtual .fetch-deps gnupg; \
+	arch="$(apk --print-arch)"; \
+	url=; \
+	case "$arch" in \
 		'x86_64') \
 			export GOARCH='amd64' GOOS='linux'; \
 			;; \
@@ -50,19 +43,23 @@ RUN set -eux; \
 		's390x') \
 			export GOARCH='s390x' GOOS='linux'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$apkArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
-	\
+	build=; \
+	if [ -z "$url" ]; then \
 # https://github.com/golang/go/issues/38536#issuecomment-616897960
+		build=1; \
 		url='https://dl.google.com/go/go1.16.7.src.tar.gz'; \
 		sha256='1a9f2894d3d878729f7045072f30becebe243524cf2fce4e0a7b248b1e0654ac'; \
+# the precompiled binaries published by Go upstream are not compatible with Alpine, so we always build from source here 😅
+	fi; \
 	\
 	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url"; \
 	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
@@ -72,6 +69,14 @@ RUN set -eux; \
 	tar -C /usr/local -xzf go.tgz; \
 	rm go.tgz; \
 	\
+	if [ -n "$build" ]; then \
+		apk add --no-cache --virtual .build-deps \
+			bash \
+			gcc \
+			go \
+			musl-dev \
+		; \
+		\
 		( \
 			cd /usr/local/go/src; \
 # set GOROOT_BOOTSTRAP + GOHOST* such that we can build Go successfully
@@ -79,13 +84,13 @@ RUN set -eux; \
 			./make.bash; \
 		); \
 		\
+		apk del --no-network .build-deps; \
+		\
 # pre-compile the standard library, just like the official binary release tarballs do
 		go install std; \
 # go install: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
 #		go install -race std; \
 		\
-	apk del --no-network .build-deps; \
-	\
 # remove a few intermediate / bootstrapping files the official binary release tarballs do not contain
 		rm -rf \
 			/usr/local/go/pkg/*/cmd \
@@ -95,6 +100,9 @@ RUN set -eux; \
 			/usr/local/go/pkg/tool/*/go_bootstrap \
 			/usr/local/go/src/cmd/dist/dist \
 		; \
+	fi; \
+	\
+	apk del --no-network .fetch-deps; \
 	\
 	go version
 
diff --git a/golang_1.16-alpine3.13/Dockerfile b/golang_1.16-alpine3.13/Dockerfile
index 38b47d1..731fcda 100644
--- a/golang_1.16-alpine3.13/Dockerfile
+++ b/golang_1.16-alpine3.13/Dockerfile
@@ -6,8 +6,7 @@
 
 FROM alpine:3.13
 
-RUN apk add --no-cache \
-		ca-certificates
+RUN apk add --no-cache ca-certificates
 
 # set up nsswitch.conf for Go's "netgo" implementation
 # - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
@@ -19,16 +18,10 @@ ENV PATH /usr/local/go/bin:$PATH
 ENV GOLANG_VERSION 1.16.7
 
 RUN set -eux; \
-	apk add --no-cache --virtual .build-deps \
-		bash \
-		gcc \
-		gnupg \
-		go \
-		musl-dev \
-		openssl \
-	; \
-	apkArch="$(apk --print-arch)"; \
-	case "$apkArch" in \
+	apk add --no-cache --virtual .fetch-deps gnupg; \
+	arch="$(apk --print-arch)"; \
+	url=; \
+	case "$arch" in \
 		'x86_64') \
 			export GOARCH='amd64' GOOS='linux'; \
 			;; \
@@ -50,19 +43,23 @@ RUN set -eux; \
 		's390x') \
 			export GOARCH='s390x' GOOS='linux'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$apkArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
-	\
+	build=; \
+	if [ -z "$url" ]; then \
 # https://github.com/golang/go/issues/38536#issuecomment-616897960
+		build=1; \
 		url='https://dl.google.com/go/go1.16.7.src.tar.gz'; \
 		sha256='1a9f2894d3d878729f7045072f30becebe243524cf2fce4e0a7b248b1e0654ac'; \
+# the precompiled binaries published by Go upstream are not compatible with Alpine, so we always build from source here 😅
+	fi; \
 	\
 	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url"; \
 	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
@@ -72,15 +69,22 @@ RUN set -eux; \
 	tar -C /usr/local -xzf go.tgz; \
 	rm go.tgz; \
 	\
+	if [ -n "$build" ]; then \
+		apk add --no-cache --virtual .build-deps \
+			bash \
+			gcc \
+			go \
+			musl-dev \
+		; \
+		\
 		( \
 			cd /usr/local/go/src; \
 # set GOROOT_BOOTSTRAP + GOHOST* such that we can build Go successfully
 			export GOROOT_BOOTSTRAP="$(go env GOROOT)" GOHOSTOS="$GOOS" GOHOSTARCH="$GOARCH"; \
 			if [ -n "${GO386:-}" ]; then \
 # https://github.com/docker-library/golang/issues/359 -> https://github.com/golang/go/issues/44500
-# Go 1.15 + Alpine 3.14 == Go 1.16 bootstrap
 # Go 1.16 + Alpine 3.13 == Go 1.15 bootstrap
-# (once Go 1.15 *and* Alpine 3.13 go away, we can remove this)
+# (once Alpine 3.13 goes away, we can remove this)
 				GO386= ./bootstrap.bash; \
 				export GOROOT_BOOTSTRAP="/usr/local/go-$GOOS-$GOARCH-bootstrap"; \
 				"$GOROOT_BOOTSTRAP/bin/go" version; \
@@ -91,13 +95,13 @@ RUN set -eux; \
 			fi; \
 		); \
 		\
+		apk del --no-network .build-deps; \
+		\
 # pre-compile the standard library, just like the official binary release tarballs do
 		go install std; \
 # go install: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
 #		go install -race std; \
 		\
-	apk del --no-network .build-deps; \
-	\
 # remove a few intermediate / bootstrapping files the official binary release tarballs do not contain
 		rm -rf \
 			/usr/local/go/pkg/*/cmd \
@@ -107,6 +111,9 @@ RUN set -eux; \
 			/usr/local/go/pkg/tool/*/go_bootstrap \
 			/usr/local/go/src/cmd/dist/dist \
 		; \
+	fi; \
+	\
+	apk del --no-network .fetch-deps; \
 	\
 	go version
 
diff --git a/golang_1.16-bullseye/Dockerfile b/golang_1.16-bullseye/Dockerfile
index e80e81e..a343f06 100644
--- a/golang_1.16-bullseye/Dockerfile
+++ b/golang_1.16-bullseye/Dockerfile
@@ -6,24 +6,26 @@
 
 FROM buildpack-deps:bullseye-scm
 
-# gcc for cgo
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# install cgo-related dependencies
+RUN set -eux; \
+	apt-get update; \
+	apt-get install -y --no-install-recommends \
 		g++ \
 		gcc \
 		libc6-dev \
 		make \
 		pkg-config \
-	&& rm -rf /var/lib/apt/lists/*
+	; \
+	rm -rf /var/lib/apt/lists/*
 
 ENV PATH /usr/local/go/bin:$PATH
 
 ENV GOLANG_VERSION 1.16.7
 
 RUN set -eux; \
-	\
-	dpkgArch="$(dpkg --print-architecture)"; \
+	arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
 	url=; \
-	case "${dpkgArch##*-}" in \
+	case "$arch" in \
 		'amd64') \
 			url='https://dl.google.com/go/go1.16.7.linux-amd64.tar.gz'; \
 			sha256='7fe7a73f55ba3e2285da36f8b085e5c0159e9564ef5f63ee0ed6b818ade8ef04'; \
@@ -54,7 +56,7 @@ RUN set -eux; \
 			url='https://dl.google.com/go/go1.16.7.linux-s390x.tar.gz'; \
 			sha256='5f691c9551710ebb17bbda04389944aa7332f42ab28f92516a69fbd7860e7e9f'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$dpkgArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
 	build=; \
 	if [ -z "$url" ]; then \
@@ -63,16 +65,16 @@ RUN set -eux; \
 		url='https://dl.google.com/go/go1.16.7.src.tar.gz'; \
 		sha256='1a9f2894d3d878729f7045072f30becebe243524cf2fce4e0a7b248b1e0654ac'; \
 		echo >&2; \
-		echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; \
+		echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \
 		echo >&2; \
 	fi; \
 	\
-	wget -O go.tgz.asc "$url.asc" --progress=dot:giga; \
+	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url" --progress=dot:giga; \
-	echo "$sha256 *go.tgz" | sha256sum --strict --check -; \
+	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
diff --git a/golang_1.16-buster/Dockerfile b/golang_1.16-buster/Dockerfile
index 7ee404f..dbeb4ce 100644
--- a/golang_1.16-buster/Dockerfile
+++ b/golang_1.16-buster/Dockerfile
@@ -6,24 +6,26 @@
 
 FROM buildpack-deps:buster-scm
 
-# gcc for cgo
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# install cgo-related dependencies
+RUN set -eux; \
+	apt-get update; \
+	apt-get install -y --no-install-recommends \
 		g++ \
 		gcc \
 		libc6-dev \
 		make \
 		pkg-config \
-	&& rm -rf /var/lib/apt/lists/*
+	; \
+	rm -rf /var/lib/apt/lists/*
 
 ENV PATH /usr/local/go/bin:$PATH
 
 ENV GOLANG_VERSION 1.16.7
 
 RUN set -eux; \
-	\
-	dpkgArch="$(dpkg --print-architecture)"; \
+	arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
 	url=; \
-	case "${dpkgArch##*-}" in \
+	case "$arch" in \
 		'amd64') \
 			url='https://dl.google.com/go/go1.16.7.linux-amd64.tar.gz'; \
 			sha256='7fe7a73f55ba3e2285da36f8b085e5c0159e9564ef5f63ee0ed6b818ade8ef04'; \
@@ -54,7 +56,7 @@ RUN set -eux; \
 			url='https://dl.google.com/go/go1.16.7.linux-s390x.tar.gz'; \
 			sha256='5f691c9551710ebb17bbda04389944aa7332f42ab28f92516a69fbd7860e7e9f'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$dpkgArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
 	build=; \
 	if [ -z "$url" ]; then \
@@ -63,16 +65,16 @@ RUN set -eux; \
 		url='https://dl.google.com/go/go1.16.7.src.tar.gz'; \
 		sha256='1a9f2894d3d878729f7045072f30becebe243524cf2fce4e0a7b248b1e0654ac'; \
 		echo >&2; \
-		echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; \
+		echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \
 		echo >&2; \
 	fi; \
 	\
-	wget -O go.tgz.asc "$url.asc" --progress=dot:giga; \
+	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url" --progress=dot:giga; \
-	echo "$sha256 *go.tgz" | sha256sum --strict --check -; \
+	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
diff --git a/golang_1.16-stretch/Dockerfile b/golang_1.16-stretch/Dockerfile
index 1ea99ba..fff5ade 100644
--- a/golang_1.16-stretch/Dockerfile
+++ b/golang_1.16-stretch/Dockerfile
@@ -6,24 +6,26 @@
 
 FROM buildpack-deps:stretch-scm
 
-# gcc for cgo
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# install cgo-related dependencies
+RUN set -eux; \
+	apt-get update; \
+	apt-get install -y --no-install-recommends \
 		g++ \
 		gcc \
 		libc6-dev \
 		make \
 		pkg-config \
-	&& rm -rf /var/lib/apt/lists/*
+	; \
+	rm -rf /var/lib/apt/lists/*
 
 ENV PATH /usr/local/go/bin:$PATH
 
 ENV GOLANG_VERSION 1.16.7
 
 RUN set -eux; \
-	\
-	dpkgArch="$(dpkg --print-architecture)"; \
+	arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
 	url=; \
-	case "${dpkgArch##*-}" in \
+	case "$arch" in \
 		'amd64') \
 			url='https://dl.google.com/go/go1.16.7.linux-amd64.tar.gz'; \
 			sha256='7fe7a73f55ba3e2285da36f8b085e5c0159e9564ef5f63ee0ed6b818ade8ef04'; \
@@ -54,7 +56,7 @@ RUN set -eux; \
 			url='https://dl.google.com/go/go1.16.7.linux-s390x.tar.gz'; \
 			sha256='5f691c9551710ebb17bbda04389944aa7332f42ab28f92516a69fbd7860e7e9f'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$dpkgArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
 	build=; \
 	if [ -z "$url" ]; then \
@@ -63,16 +65,16 @@ RUN set -eux; \
 		url='https://dl.google.com/go/go1.16.7.src.tar.gz'; \
 		sha256='1a9f2894d3d878729f7045072f30becebe243524cf2fce4e0a7b248b1e0654ac'; \
 		echo >&2; \
-		echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; \
+		echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \
 		echo >&2; \
 	fi; \
 	\
-	wget -O go.tgz.asc "$url.asc" --progress=dot:giga; \
+	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url" --progress=dot:giga; \
-	echo "$sha256 *go.tgz" | sha256sum --strict --check -; \
+	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
diff --git a/golang_alpine/Dockerfile b/golang_alpine/Dockerfile
index 92da153..a4091eb 100644
--- a/golang_alpine/Dockerfile
+++ b/golang_alpine/Dockerfile
@@ -6,8 +6,7 @@
 
 FROM alpine:3.14
 
-RUN apk add --no-cache \
-		ca-certificates
+RUN apk add --no-cache ca-certificates
 
 # set up nsswitch.conf for Go's "netgo" implementation
 # - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
@@ -19,16 +18,10 @@ ENV PATH /usr/local/go/bin:$PATH
 ENV GOLANG_VERSION 1.17
 
 RUN set -eux; \
-	apk add --no-cache --virtual .build-deps \
-		bash \
-		gcc \
-		gnupg \
-		go \
-		musl-dev \
-		openssl \
-	; \
-	apkArch="$(apk --print-arch)"; \
-	case "$apkArch" in \
+	apk add --no-cache --virtual .fetch-deps gnupg; \
+	arch="$(apk --print-arch)"; \
+	url=; \
+	case "$arch" in \
 		'x86_64') \
 			export GOARCH='amd64' GOOS='linux'; \
 			;; \
@@ -50,19 +43,23 @@ RUN set -eux; \
 		's390x') \
 			export GOARCH='s390x' GOOS='linux'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$apkArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
-	\
+	build=; \
+	if [ -z "$url" ]; then \
 # https://github.com/golang/go/issues/38536#issuecomment-616897960
+		build=1; \
 		url='https://dl.google.com/go/go1.17.src.tar.gz'; \
 		sha256='3a70e5055509f347c0fb831ca07a2bf3b531068f349b14a3c652e9b5b67beb5d'; \
+# the precompiled binaries published by Go upstream are not compatible with Alpine, so we always build from source here 😅
+	fi; \
 	\
 	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url"; \
 	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
@@ -72,6 +69,14 @@ RUN set -eux; \
 	tar -C /usr/local -xzf go.tgz; \
 	rm go.tgz; \
 	\
+	if [ -n "$build" ]; then \
+		apk add --no-cache --virtual .build-deps \
+			bash \
+			gcc \
+			go \
+			musl-dev \
+		; \
+		\
 		( \
 			cd /usr/local/go/src; \
 # set GOROOT_BOOTSTRAP + GOHOST* such that we can build Go successfully
@@ -79,13 +84,13 @@ RUN set -eux; \
 			./make.bash; \
 		); \
 		\
+		apk del --no-network .build-deps; \
+		\
 # pre-compile the standard library, just like the official binary release tarballs do
 		go install std; \
 # go install: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
 #		go install -race std; \
 		\
-	apk del --no-network .build-deps; \
-	\
 # remove a few intermediate / bootstrapping files the official binary release tarballs do not contain
 		rm -rf \
 			/usr/local/go/pkg/*/cmd \
@@ -95,6 +100,9 @@ RUN set -eux; \
 			/usr/local/go/pkg/tool/*/go_bootstrap \
 			/usr/local/go/src/cmd/dist/dist \
 		; \
+	fi; \
+	\
+	apk del --no-network .fetch-deps; \
 	\
 	go version
 
diff --git a/golang_alpine3.13/Dockerfile b/golang_alpine3.13/Dockerfile
index d7134c3..8222687 100644
--- a/golang_alpine3.13/Dockerfile
+++ b/golang_alpine3.13/Dockerfile
@@ -6,8 +6,7 @@
 
 FROM alpine:3.13
 
-RUN apk add --no-cache \
-		ca-certificates
+RUN apk add --no-cache ca-certificates
 
 # set up nsswitch.conf for Go's "netgo" implementation
 # - https://github.com/golang/go/blob/go1.9.1/src/net/conf.go#L194-L275
@@ -19,16 +18,10 @@ ENV PATH /usr/local/go/bin:$PATH
 ENV GOLANG_VERSION 1.17
 
 RUN set -eux; \
-	apk add --no-cache --virtual .build-deps \
-		bash \
-		gcc \
-		gnupg \
-		go \
-		musl-dev \
-		openssl \
-	; \
-	apkArch="$(apk --print-arch)"; \
-	case "$apkArch" in \
+	apk add --no-cache --virtual .fetch-deps gnupg; \
+	arch="$(apk --print-arch)"; \
+	url=; \
+	case "$arch" in \
 		'x86_64') \
 			export GOARCH='amd64' GOOS='linux'; \
 			;; \
@@ -50,19 +43,23 @@ RUN set -eux; \
 		's390x') \
 			export GOARCH='s390x' GOOS='linux'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$apkArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
-	\
+	build=; \
+	if [ -z "$url" ]; then \
 # https://github.com/golang/go/issues/38536#issuecomment-616897960
+		build=1; \
 		url='https://dl.google.com/go/go1.17.src.tar.gz'; \
 		sha256='3a70e5055509f347c0fb831ca07a2bf3b531068f349b14a3c652e9b5b67beb5d'; \
+# the precompiled binaries published by Go upstream are not compatible with Alpine, so we always build from source here 😅
+	fi; \
 	\
 	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url"; \
 	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
@@ -72,15 +69,22 @@ RUN set -eux; \
 	tar -C /usr/local -xzf go.tgz; \
 	rm go.tgz; \
 	\
+	if [ -n "$build" ]; then \
+		apk add --no-cache --virtual .build-deps \
+			bash \
+			gcc \
+			go \
+			musl-dev \
+		; \
+		\
 		( \
 			cd /usr/local/go/src; \
 # set GOROOT_BOOTSTRAP + GOHOST* such that we can build Go successfully
 			export GOROOT_BOOTSTRAP="$(go env GOROOT)" GOHOSTOS="$GOOS" GOHOSTARCH="$GOARCH"; \
 			if [ -n "${GO386:-}" ]; then \
 # https://github.com/docker-library/golang/issues/359 -> https://github.com/golang/go/issues/44500
-# Go 1.15 + Alpine 3.14 == Go 1.16 bootstrap
 # Go 1.16 + Alpine 3.13 == Go 1.15 bootstrap
-# (once Go 1.15 *and* Alpine 3.13 go away, we can remove this)
+# (once Alpine 3.13 goes away, we can remove this)
 				GO386= ./bootstrap.bash; \
 				export GOROOT_BOOTSTRAP="/usr/local/go-$GOOS-$GOARCH-bootstrap"; \
 				"$GOROOT_BOOTSTRAP/bin/go" version; \
@@ -91,13 +95,13 @@ RUN set -eux; \
 			fi; \
 		); \
 		\
+		apk del --no-network .build-deps; \
+		\
 # pre-compile the standard library, just like the official binary release tarballs do
 		go install std; \
 # go install: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64
 #		go install -race std; \
 		\
-	apk del --no-network .build-deps; \
-	\
 # remove a few intermediate / bootstrapping files the official binary release tarballs do not contain
 		rm -rf \
 			/usr/local/go/pkg/*/cmd \
@@ -107,6 +111,9 @@ RUN set -eux; \
 			/usr/local/go/pkg/tool/*/go_bootstrap \
 			/usr/local/go/src/cmd/dist/dist \
 		; \
+	fi; \
+	\
+	apk del --no-network .fetch-deps; \
 	\
 	go version
 
diff --git a/golang_bullseye/Dockerfile b/golang_bullseye/Dockerfile
index ef0e425..a7e925f 100644
--- a/golang_bullseye/Dockerfile
+++ b/golang_bullseye/Dockerfile
@@ -6,24 +6,26 @@
 
 FROM buildpack-deps:bullseye-scm
 
-# gcc for cgo
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# install cgo-related dependencies
+RUN set -eux; \
+	apt-get update; \
+	apt-get install -y --no-install-recommends \
 		g++ \
 		gcc \
 		libc6-dev \
 		make \
 		pkg-config \
-	&& rm -rf /var/lib/apt/lists/*
+	; \
+	rm -rf /var/lib/apt/lists/*
 
 ENV PATH /usr/local/go/bin:$PATH
 
 ENV GOLANG_VERSION 1.17
 
 RUN set -eux; \
-	\
-	dpkgArch="$(dpkg --print-architecture)"; \
+	arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
 	url=; \
-	case "${dpkgArch##*-}" in \
+	case "$arch" in \
 		'amd64') \
 			url='https://dl.google.com/go/go1.17.linux-amd64.tar.gz'; \
 			sha256='6bf89fc4f5ad763871cf7eac80a2d594492de7a818303283f1366a7f6a30372d'; \
@@ -54,7 +56,7 @@ RUN set -eux; \
 			url='https://dl.google.com/go/go1.17.linux-s390x.tar.gz'; \
 			sha256='a50aaecf054f393575f969a9105d5c6864dd91afc5287d772449033fbafcf7e3'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$dpkgArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
 	build=; \
 	if [ -z "$url" ]; then \
@@ -63,16 +65,16 @@ RUN set -eux; \
 		url='https://dl.google.com/go/go1.17.src.tar.gz'; \
 		sha256='3a70e5055509f347c0fb831ca07a2bf3b531068f349b14a3c652e9b5b67beb5d'; \
 		echo >&2; \
-		echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; \
+		echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \
 		echo >&2; \
 	fi; \
 	\
-	wget -O go.tgz.asc "$url.asc" --progress=dot:giga; \
+	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url" --progress=dot:giga; \
-	echo "$sha256 *go.tgz" | sha256sum --strict --check -; \
+	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
diff --git a/golang_buster/Dockerfile b/golang_buster/Dockerfile
index 298872b..a772f2f 100644
--- a/golang_buster/Dockerfile
+++ b/golang_buster/Dockerfile
@@ -6,24 +6,26 @@
 
 FROM buildpack-deps:buster-scm
 
-# gcc for cgo
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# install cgo-related dependencies
+RUN set -eux; \
+	apt-get update; \
+	apt-get install -y --no-install-recommends \
 		g++ \
 		gcc \
 		libc6-dev \
 		make \
 		pkg-config \
-	&& rm -rf /var/lib/apt/lists/*
+	; \
+	rm -rf /var/lib/apt/lists/*
 
 ENV PATH /usr/local/go/bin:$PATH
 
 ENV GOLANG_VERSION 1.17
 
 RUN set -eux; \
-	\
-	dpkgArch="$(dpkg --print-architecture)"; \
+	arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
 	url=; \
-	case "${dpkgArch##*-}" in \
+	case "$arch" in \
 		'amd64') \
 			url='https://dl.google.com/go/go1.17.linux-amd64.tar.gz'; \
 			sha256='6bf89fc4f5ad763871cf7eac80a2d594492de7a818303283f1366a7f6a30372d'; \
@@ -54,7 +56,7 @@ RUN set -eux; \
 			url='https://dl.google.com/go/go1.17.linux-s390x.tar.gz'; \
 			sha256='a50aaecf054f393575f969a9105d5c6864dd91afc5287d772449033fbafcf7e3'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$dpkgArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
 	build=; \
 	if [ -z "$url" ]; then \
@@ -63,16 +65,16 @@ RUN set -eux; \
 		url='https://dl.google.com/go/go1.17.src.tar.gz'; \
 		sha256='3a70e5055509f347c0fb831ca07a2bf3b531068f349b14a3c652e9b5b67beb5d'; \
 		echo >&2; \
-		echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; \
+		echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \
 		echo >&2; \
 	fi; \
 	\
-	wget -O go.tgz.asc "$url.asc" --progress=dot:giga; \
+	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url" --progress=dot:giga; \
-	echo "$sha256 *go.tgz" | sha256sum --strict --check -; \
+	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \
diff --git a/golang_stretch/Dockerfile b/golang_stretch/Dockerfile
index 5c30f1a..c98b0c2 100644
--- a/golang_stretch/Dockerfile
+++ b/golang_stretch/Dockerfile
@@ -6,24 +6,26 @@
 
 FROM buildpack-deps:stretch-scm
 
-# gcc for cgo
-RUN apt-get update && apt-get install -y --no-install-recommends \
+# install cgo-related dependencies
+RUN set -eux; \
+	apt-get update; \
+	apt-get install -y --no-install-recommends \
 		g++ \
 		gcc \
 		libc6-dev \
 		make \
 		pkg-config \
-	&& rm -rf /var/lib/apt/lists/*
+	; \
+	rm -rf /var/lib/apt/lists/*
 
 ENV PATH /usr/local/go/bin:$PATH
 
 ENV GOLANG_VERSION 1.17
 
 RUN set -eux; \
-	\
-	dpkgArch="$(dpkg --print-architecture)"; \
+	arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
 	url=; \
-	case "${dpkgArch##*-}" in \
+	case "$arch" in \
 		'amd64') \
 			url='https://dl.google.com/go/go1.17.linux-amd64.tar.gz'; \
 			sha256='6bf89fc4f5ad763871cf7eac80a2d594492de7a818303283f1366a7f6a30372d'; \
@@ -54,7 +56,7 @@ RUN set -eux; \
 			url='https://dl.google.com/go/go1.17.linux-s390x.tar.gz'; \
 			sha256='a50aaecf054f393575f969a9105d5c6864dd91afc5287d772449033fbafcf7e3'; \
 			;; \
-		*) echo >&2 "error: unsupported architecture '$dpkgArch' (likely packaging update needed)"; exit 1 ;; \
+		*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
 	esac; \
 	build=; \
 	if [ -z "$url" ]; then \
@@ -63,16 +65,16 @@ RUN set -eux; \
 		url='https://dl.google.com/go/go1.17.src.tar.gz'; \
 		sha256='3a70e5055509f347c0fb831ca07a2bf3b531068f349b14a3c652e9b5b67beb5d'; \
 		echo >&2; \
-		echo >&2 "warning: current architecture ($dpkgArch) does not have a corresponding Go binary release; will be building from source"; \
+		echo >&2 "warning: current architecture ($arch) does not have a compatible Go binary release; will be building from source"; \
 		echo >&2; \
 	fi; \
 	\
-	wget -O go.tgz.asc "$url.asc" --progress=dot:giga; \
+	wget -O go.tgz.asc "$url.asc"; \
 	wget -O go.tgz "$url" --progress=dot:giga; \
-	echo "$sha256 *go.tgz" | sha256sum --strict --check -; \
+	echo "$sha256 *go.tgz" | sha256sum -c -; \
 	\
 # https://github.com/golang/go/issues/14739#issuecomment-324767697
-	export GNUPGHOME="$(mktemp -d)"; \
+	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'; \
 	gpg --batch --verify go.tgz.asc go.tgz; \

@yosifkit yosifkit merged commit 014d28f into docker-library:master Aug 30, 2021
@yosifkit yosifkit deleted the golang branch August 30, 2021 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants