Skip to content

Commit

Permalink
Dockerfile: use GO_VERSION build-arg for overriding Go version
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
thaJeztah authored and kolyshkin committed Jul 19, 2019
1 parent b4058a6 commit c6281bc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#

ARG CROSS="false"
ARG GO_VERSION=1.12.7

FROM golang:1.12.7 AS base
FROM golang:${GO_VERSION} AS base
ARG APT_MIRROR
RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
&& sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM golang:1.12.7-alpine as base
ARG GO_VERSION=1.12.7

FROM golang:${GO_VERSION}-alpine AS base

RUN apk --no-cache add \
bash \
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.simple
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

# This represents the bare minimum required to build and test Docker.

FROM golang:1.12.7
ARG GO_VERSION=1.12.7

FROM golang:${GO_VERSION}

# allow replacing httpredir or deb mirror
ARG APT_MIRROR=deb.debian.org
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ FROM microsoft/windowsservercore
# Use PowerShell as the default shell
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

ARG GO_VERSION=1.12.7

# Environment variable notes:
# - GO_VERSION must be consistent with 'Dockerfile' used by Linux.
# - FROM_DOCKERFILE is used for detection of building within a container.
ENV GO_VERSION=1.12.7 `
ENV GO_VERSION=${GO_VERSION} `
GIT_VERSION=2.11.1 `
GOPATH=C:\go `
FROM_DOCKERFILE=1
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ build: DOCKER_BUILD_ARGS += --build-arg=CROSS=$(DOCKER_CROSS)
build: DOCKER_BUILDKIT ?= 1
build: bundles
$(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})
DOCKER_BUILDKIT="${DOCKER_BUILDKIT}" docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
DOCKER_BUILDKIT="${DOCKER_BUILDKIT}" docker build --build-arg=GO_VERSION ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .

bundles:
mkdir bundles
Expand Down
2 changes: 1 addition & 1 deletion hack/ci/windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Try {
Write-Host -ForegroundColor Cyan "`n`nINFO: Building the image from Dockerfile.windows at $(Get-Date)..."
Write-Host
$ErrorActionPreference = "SilentlyContinue"
$Duration=$(Measure-Command { docker build -t docker -f Dockerfile.windows . | Out-Host })
$Duration=$(Measure-Command { docker build --build-arg=GO_VERSION -t docker -f Dockerfile.windows . | Out-Host })
$ErrorActionPreference = "Stop"
if (-not($LastExitCode -eq 0)) {
Throw "ERROR: Failed to build image from Dockerfile.windows"
Expand Down

0 comments on commit c6281bc

Please sign in to comment.