From 0d3022c6d284e3e742065228fcda89d3275ce682 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 18 Jul 2019 11:13:45 +0200 Subject: [PATCH] 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 -f docker.Makefile binary Signed-off-by: Sebastiaan van Stijn --- docker.Makefile | 12 ++++++------ dockerfiles/Dockerfile.binary-native | 4 +++- dockerfiles/Dockerfile.cross | 4 +++- dockerfiles/Dockerfile.dev | 4 +++- dockerfiles/Dockerfile.lint | 4 +++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docker.Makefile b/docker.Makefile index 3783e8bff678..cf4f406cf920 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -27,32 +27,32 @@ ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM -e TESTFLAGS -e TESTDIR .PHONY: build_docker_image build_docker_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} -t $(DEV_DOCKER_IMAGE_NAME) - + cat ./dockerfiles/Dockerfile.dev | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(DEV_DOCKER_IMAGE_NAME) - # build docker image having the linting tools (dockerfiles/Dockerfile.lint) .PHONY: build_linter_image build_linter_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.lint | docker build ${DOCKER_BUILD_ARGS} -t $(LINTER_IMAGE_NAME) - + cat ./dockerfiles/Dockerfile.lint | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(LINTER_IMAGE_NAME) - .PHONY: build_cross_image build_cross_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.cross | docker build ${DOCKER_BUILD_ARGS} -t $(CROSS_IMAGE_NAME) - + cat ./dockerfiles/Dockerfile.cross | docker build ${DOCKER_BUILD_ARGS} --build-arg=GO_VERSION -t $(CROSS_IMAGE_NAME) - .PHONY: build_shell_validate_image build_shell_validate_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.shellcheck | docker build -t $(VALIDATE_IMAGE_NAME) - + cat ./dockerfiles/Dockerfile.shellcheck | docker build --build-arg=GO_VERSION -t $(VALIDATE_IMAGE_NAME) - .PHONY: build_binary_native_image build_binary_native_image: # build dockerfile from stdin so that we don't send the build-context; source is bind-mounted in the development environment - cat ./dockerfiles/Dockerfile.binary-native | docker build -t $(BINARY_NATIVE_IMAGE_NAME) - + cat ./dockerfiles/Dockerfile.binary-native | docker build --build-arg=GO_VERSION -t $(BINARY_NATIVE_IMAGE_NAME) - .PHONY: build_e2e_image build_e2e_image: - docker build -t $(E2E_IMAGE_NAME) --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e . + docker build -t $(E2E_IMAGE_NAME) --build-arg=GO_VERSION --build-arg VERSION=$(VERSION) --build-arg GITCOMMIT=$(GITCOMMIT) -f ./dockerfiles/Dockerfile.e2e . DOCKER_RUN_NAME_OPTION := $(if $(DOCKER_CLI_CONTAINER_NAME),--name $(DOCKER_CLI_CONTAINER_NAME),) DOCKER_RUN := docker run --rm $(ENVVARS) $(DOCKER_CLI_MOUNTS) $(DOCKER_RUN_NAME_OPTION) diff --git a/dockerfiles/Dockerfile.binary-native b/dockerfiles/Dockerfile.binary-native index 8193522d1208..4e37092c5138 100644 --- a/dockerfiles/Dockerfile.binary-native +++ b/dockerfiles/Dockerfile.binary-native @@ -1,4 +1,6 @@ -FROM golang:1.12.7-alpine +ARG GO_VERSION=1.12.7 + +FROM golang:${GO_VERSION}-alpine RUN apk add -U git bash coreutils gcc musl-dev diff --git a/dockerfiles/Dockerfile.cross b/dockerfiles/Dockerfile.cross index 53e3cffca0d5..6f9103cea7cf 100644 --- a/dockerfiles/Dockerfile.cross +++ b/dockerfiles/Dockerfile.cross @@ -1,4 +1,6 @@ -FROM dockercore/golang-cross:1.12.7 +ARG GO_VERSION=1.12.7 + +FROM dockercore/golang-cross:${GO_VERSION} ENV DISABLE_WARN_OUTSIDE_CONTAINER=1 WORKDIR /go/src/github.com/docker/cli COPY . . diff --git a/dockerfiles/Dockerfile.dev b/dockerfiles/Dockerfile.dev index a3e2d18c0aef..23ee63b195e2 100644 --- a/dockerfiles/Dockerfile.dev +++ b/dockerfiles/Dockerfile.dev @@ -1,4 +1,6 @@ -FROM golang:1.12.7-alpine +ARG GO_VERSION=1.12.7 + +FROM golang:${GO_VERSION}-alpine RUN apk add -U git make bash coreutils ca-certificates curl diff --git a/dockerfiles/Dockerfile.lint b/dockerfiles/Dockerfile.lint index 9e967232c935..70ace9046312 100644 --- a/dockerfiles/Dockerfile.lint +++ b/dockerfiles/Dockerfile.lint @@ -1,4 +1,6 @@ -FROM golang:1.12.7-alpine +ARG GO_VERSION=1.12.7 + +FROM golang:${GO_VERSION}-alpine RUN apk add -U git