diff --git a/Dockerfile b/Dockerfile index bc02ef809a..861655c64c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,11 +25,12 @@ # ARG CROSS="false" +ARG GO_VERSION=1.12.7 -FROM golang:1.12.7 AS base -# allow replacing httpredir or deb mirror -ARG APT_MIRROR=deb.debian.org -RUN sed -ri "s/(httpredir|deb).debian.org/$APT_MIRROR/g" /etc/apt/sources.list +FROM golang:${GO_VERSION}-stretch 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 FROM base AS criu # Install CRIU for checkpoint/restore support diff --git a/Dockerfile.e2e b/Dockerfile.e2e index f24d29a364..9b6c0fe544 100644 --- a/Dockerfile.e2e +++ b/Dockerfile.e2e @@ -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 \ diff --git a/Dockerfile.simple b/Dockerfile.simple index 303b0cfd35..ff64fa4f54 100644 --- a/Dockerfile.simple +++ b/Dockerfile.simple @@ -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}-stretch # allow replacing httpredir or deb mirror ARG APT_MIRROR=deb.debian.org diff --git a/Dockerfile.windows b/Dockerfile.windows index 7c034019d1..c11b373c4f 100644 --- a/Dockerfile.windows +++ b/Dockerfile.windows @@ -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 diff --git a/Makefile b/Makefile index f778902fe6..1c97812b2c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/TESTING.md b/TESTING.md index b2c53769ca..15322f9eed 100644 --- a/TESTING.md +++ b/TESTING.md @@ -87,3 +87,10 @@ To run the integration test suite: ``` make test-integration ``` + +You can change a version of golang used for building stuff that is being tested +by setting `GO_VERSION` variable, for example: + +``` +make GO_VERSION=1.12.7 test +``` diff --git a/hack/ci/windows.ps1 b/hack/ci/windows.ps1 index 6d87f3256b..8828f73d01 100644 --- a/hack/ci/windows.ps1 +++ b/hack/ci/windows.ps1 @@ -426,20 +426,9 @@ Try { Write-Host -ForegroundColor Green "INFO: Location for testing is $env:TEMP" # CI Integrity check - ensure Dockerfile.windows and Dockerfile go versions match - $goVersionDockerfileWindows=$(Get-Content ".\Dockerfile.windows" | Select-String "^ENV GO_VERSION" | Select-object -First 1).ToString().Replace("ENV GO_VERSION=","").Replace("\","").Replace("``","").Trim() - $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^ENV GO_VERSION" | Select-object -First 1) - - # As of go 1.11, Dockerfile changed to be in the format like "FROM golang:1.11.0 AS base". - # If a version number ends with .0 (as in 1.11.0, a convention used in golang docker - # image versions), it needs to be removed (i.e. "1.11.0" becomes "1.11"). - if ($null -eq $goVersionDockerfile) { - $goVersionDockerfile=$(Get-Content ".\Dockerfile" | Select-String "^FROM golang:" | Select-object -First 1) - if ($null -ne $goVersionDockerfile) { - $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[1].Split(":")[1] -replace '\.0$','' - } - } else { - $goVersionDockerfile = $goVersionDockerfile.ToString().Split(" ")[2] - } + $goVersionDockerfileWindows=(Select-String -Path ".\Dockerfile.windows" -Pattern "^ARG[\s]+GO_VERSION=(.*)$").Matches.groups[1].Value + $goVersionDockerfile=(Select-String -Path ".\Dockerfile" -Pattern "^ARG[\s]+GO_VERSION=(.*)$").Matches.groups[1].Value + if ($null -eq $goVersionDockerfile) { Throw "ERROR: Failed to extract golang version from Dockerfile" } @@ -453,7 +442,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" diff --git a/hack/make.ps1 b/hack/make.ps1 index 6e5bc45e50..3c51716ed3 100644 --- a/hack/make.ps1 +++ b/hack/make.ps1 @@ -134,7 +134,7 @@ Function Check-InContainer() { # outside of a container where it may be out of date with master. Function Verify-GoVersion() { Try { - $goVersionDockerfile=(Select-String -Path ".\Dockerfile" -Pattern "^FROM golang:").ToString().Split(" ")[1].SubString(7) -replace '\.0$','' + $goVersionDockerfile=(Select-String -Path ".\Dockerfile" -Pattern "^ARG[\s]+GO_VERSION=(.*)$").Matches.groups[1].Value.TrimEnd(".0") $goVersionInstalled=(go version).ToString().Split(" ")[2].SubString(2) } Catch [Exception] {