Browse code

Dockerfile: use GO_VERSION build-arg for overriding Go version

This allows overriding the version of Go without making modifications in the
source code, which can be useful to test against multiple versions.

For example:

make GO_VERSION=1.13beta1 shell

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit c6281bc4383b7f9eab617fd73601e8594c93365b)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/07/17 20:59:16
Showing 6 changed files
... ...
@@ -25,8 +25,9 @@
25 25
 #
26 26
 
27 27
 ARG CROSS="false"
28
+ARG GO_VERSION=1.12.7
28 29
 
29
-FROM golang:1.12.7 AS base
30
+FROM golang:${GO_VERSION} AS base
30 31
 ARG APT_MIRROR
31 32
 RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
32 33
  && sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list
... ...
@@ -1,4 +1,6 @@
1
-FROM golang:1.12.7-alpine as base
1
+ARG GO_VERSION=1.12.7
2
+
3
+FROM golang:${GO_VERSION}-alpine AS base
2 4
 
3 5
 RUN apk --no-cache add \
4 6
     bash \
... ...
@@ -5,7 +5,9 @@
5 5
 
6 6
 # This represents the bare minimum required to build and test Docker.
7 7
 
8
-FROM golang:1.12.7
8
+ARG GO_VERSION=1.12.7
9
+
10
+FROM golang:${GO_VERSION}
9 11
 
10 12
 # allow replacing httpredir or deb mirror
11 13
 ARG APT_MIRROR=deb.debian.org
... ...
@@ -165,10 +165,12 @@ FROM microsoft/windowsservercore
165 165
 # Use PowerShell as the default shell
166 166
 SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
167 167
 
168
+ARG GO_VERSION=1.12.7
169
+
168 170
 # Environment variable notes:
169 171
 #  - GO_VERSION must be consistent with 'Dockerfile' used by Linux.
170 172
 #  - FROM_DOCKERFILE is used for detection of building within a container.
171
-ENV GO_VERSION=1.12.7 `
173
+ENV GO_VERSION=${GO_VERSION} `
172 174
     GIT_VERSION=2.11.1 `
173 175
     GOPATH=C:\go `
174 176
     FROM_DOCKERFILE=1
... ...
@@ -150,7 +150,7 @@ build: DOCKER_BUILD_ARGS += --build-arg=CROSS=$(DOCKER_CROSS)
150 150
 build: DOCKER_BUILDKIT ?= 1
151 151
 build: bundles
152 152
 	$(warning The docker client CLI has moved to github.com/docker/cli. For a dev-test cycle involving the CLI, run:${\n} DOCKER_CLI_PATH=/host/path/to/cli/binary make shell ${\n} then change the cli and compile into a binary at the same location.${\n})
153
-	DOCKER_BUILDKIT="${DOCKER_BUILDKIT}" docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
153
+	DOCKER_BUILDKIT="${DOCKER_BUILDKIT}" docker build --build-arg=GO_VERSION ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
154 154
 
155 155
 bundles:
156 156
 	mkdir bundles
... ...
@@ -453,7 +453,7 @@ Try {
453 453
         Write-Host  -ForegroundColor Cyan "`n`nINFO: Building the image from Dockerfile.windows at $(Get-Date)..."
454 454
         Write-Host
455 455
         $ErrorActionPreference = "SilentlyContinue"
456
-        $Duration=$(Measure-Command { docker build -t docker -f Dockerfile.windows . | Out-Host })
456
+        $Duration=$(Measure-Command { docker build --build-arg=GO_VERSION -t docker -f Dockerfile.windows . | Out-Host })
457 457
         $ErrorActionPreference = "Stop"
458 458
         if (-not($LastExitCode -eq 0)) {
459 459
            Throw "ERROR: Failed to build image from Dockerfile.windows"