@@ -13,7 +13,15 @@ FROM buildpack-deps:{{ env.variant }}-scm AS build
13
13
14
14
ENV PATH /usr/local/go/bin:$PATH
15
15
16
+ {{ if env.version != "tip" then ( -}}
16
17
ENV GOLANG_VERSION {{ .version }}
18
+ {{ ) else ( -}}
19
+ COPY --from=golang:{{ env.variant }} /usr/local/go /usr/local/goroot-bootstrap
20
+
21
+ # {{ .version }}: https://github.com/golang/go/tree/{{ .commit.version }}
22
+ ARG GOLANG_COMMIT={{ .commit.version | @sh }}
23
+ ENV GOLANG_COMMIT $GOLANG_COMMIT
24
+ {{ ) end -}}
17
25
18
26
{{
19
27
def os_arches:
@@ -54,16 +62,23 @@ RUN set -eux; \
54
62
now="$(date '+%s')"; \
55
63
{{ if is_alpine then ( -}}
56
64
apk add --no-cache --virtual .fetch-deps \
65
+ {{ if env.version != "tip" then ( -}}
57
66
ca-certificates \
58
67
gnupg \
59
68
# busybox's "tar" doesn't handle directory mtime correctly, so our SOURCE_DATE_EPOCH lookup doesn't work (the mtime of "/usr/local/go" always ends up being the extraction timestamp)
60
69
tar \
70
+ {{ ) else ( -}}
71
+ bash \
72
+ git \
73
+ {{ ) end -}}
61
74
; \
62
75
arch="$(apk --print-arch)"; \
63
76
{{ ) else ( -}}
64
77
arch="$(dpkg --print-architecture)"; arch="${arch##*-}"; \
65
78
{{ ) end -}}
79
+ {{ if env.version != "tip" then ( -}}
66
80
url=; \
81
+ {{ ) else "" end -}}
67
82
case "$arch" in \
68
83
{{
69
84
[
@@ -78,8 +93,12 @@ RUN set -eux; \
78
93
| (
79
94
-}}
80
95
{{ $osArch | @sh }}) \
96
+ {{ if env.version != "tip" then ( -}}
81
97
url={{ .url | @sh }}; \
82
98
sha256={{ .sha256 | @sh }}; \
99
+ {{ ) else ( -}}
100
+ export {{ .env | to_entries | sort_by(.key) | map(.key + "=" + (.value | @sh)) | join(" ") }}; \
101
+ {{ ) end -}}
83
102
;; \
84
103
{{
85
104
)
@@ -88,6 +107,7 @@ RUN set -eux; \
88
107
*) echo >&2 "error: unsupported architecture '$arch' (likely packaging update needed)"; exit 1 ;; \
89
108
esac; \
90
109
\
110
+ {{ if env.version != "tip" then ( -}}
91
111
wget -O go.tgz.asc "$url.asc"; \
92
112
wget -O go.tgz "$url"{{ if is_alpine then "" else " --progress=dot:giga" end }}; \
93
113
echo "$sha256 *go.tgz" | sha256sum -c -; \
@@ -107,14 +127,56 @@ RUN set -eux; \
107
127
\
108
128
# save the timestamp from the tarball so we can restore it for reproducibility, if necessary (see below)
109
129
SOURCE_DATE_EPOCH="$(stat -c '%Y' /usr/local/go)"; \
130
+ {{ ) else ( -}}
131
+ # before we get too far, let's validate that our "bootstrap" Go works
132
+ export GOROOT_BOOTSTRAP=/usr/local/goroot-bootstrap; \
133
+ "$GOROOT_BOOTSTRAP/bin/go" version; \
134
+ \
135
+ git init --quiet /usr/local/go; \
136
+ git -C /usr/local/go fetch --depth 1 https://github.com/golang/go.git "$GOLANG_COMMIT:"; \
137
+ git -C /usr/local/go checkout --quiet FETCH_HEAD; \
138
+ \
139
+ # save the Git timestamp so we can use it for reproducibility
140
+ SOURCE_DATE_EPOCH="$(git -C /usr/local/go log -1 --format='format:%ct' HEAD)"; \
141
+ {{ ) end -}}
110
142
export SOURCE_DATE_EPOCH; \
111
143
touchy="$(date -d "@$SOURCE_DATE_EPOCH" '+%Y%m%d%H%M.%S')"; \
112
144
# for logging validation/edification
113
145
date --date "@$SOURCE_DATE_EPOCH" --rfc-2822; \
114
146
# sanity check (detected value should be older than our wall clock)
115
147
[ "$SOURCE_DATE_EPOCH" -lt "$now" ]; \
116
148
\
117
- {{ if .arches["arm32v7"].url // "" | contains("armv6") then ( -}}
149
+ {{ if env.version == "tip" then ( -}}
150
+ ( \
151
+ export \
152
+ GOCACHE='/tmp/gocache' \
153
+ # set GOHOST* to make sure explicitly 32bit builds on 64bit infra work correctly
154
+ GOHOSTOS="$GOOS" \
155
+ GOHOSTARCH="$GOARCH" \
156
+ ; \
157
+ \
158
+ cd /usr/local/go/src; \
159
+ ./make.bash; \
160
+ \
161
+ # remove a few intermediate / bootstrapping files the official binary release tarballs do not contain (and ".git" that is hard to make reproducible)
162
+ rm -rf \
163
+ /usr/local/go/.git* \
164
+ /usr/local/go/pkg/*/cmd \
165
+ /usr/local/go/pkg/bootstrap \
166
+ /usr/local/go/pkg/obj \
167
+ /usr/local/go/pkg/tool/*/api \
168
+ /usr/local/go/pkg/tool/*/go_bootstrap \
169
+ /usr/local/go/src/cmd/dist/dist \
170
+ "$GOCACHE" \
171
+ ; \
172
+ \
173
+ # clamp timestamps for reproducibility (allows "COPY --link" to be more clever/useful)
174
+ touch -t "$touchy" /usr/local/.go-date-stamp; \
175
+ find /usr/local/go -depth -newer /usr/local/.go-date-stamp -exec touch -ht "$touchy" '{}' +; \
176
+ rm /usr/local/.go-date-stamp; \
177
+ ); \
178
+ \
179
+ {{ ) elif .arches["arm32v7"].url // "" | contains("armv6") then ( -}}
118
180
if [ "$arch" = {{ os_arches["arm32v7"] | @sh }} ]; then \
119
181
[ -s /usr/local/go/go.env ]; \
120
182
before="$(go env GOARM)"; [ "$before" != {{ .arches["arm32v7"].env["GOARM"] | @sh }} ]; \
@@ -166,8 +228,10 @@ RUN set -eux; \
166
228
rm -rf /var/lib/apt/lists/*
167
229
{{ ) end -}}
168
230
231
+ {{ if env.version != "tip" then ( -}}
169
232
ENV GOLANG_VERSION {{ .version }}
170
233
234
+ {{ ) else "" end -}}
171
235
# don't auto-upgrade the gotoolchain
172
236
# https://github.com/docker-library/golang/issues/472
173
237
ENV GOTOOLCHAIN=local
0 commit comments