From d5de8358f0192551970965d8fabb9a967f0f51f1 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Mon, 10 Dec 2018 11:30:52 +0000 Subject: [PATCH] Use a go build cache to speed up builds. With a docker build cache already primed with the build image I am seeing `time make build -f docker.Makefile DOCKER_BUILDKIT=1 GO_BUILD_CACHE=n` takes more than 1 minute. By contrast `time make build -f docker.Makefile DOCKER_BUILDKIT=1 GO_BUILD_CACHE=y` takes less than 10s with a hot cache irrespective of whether the source tree has changed Signed-off-by: Ian Campbell --- docker.Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docker.Makefile b/docker.Makefile index d9923c890e..f2bfddd875 100644 --- a/docker.Makefile +++ b/docker.Makefile @@ -10,7 +10,12 @@ LINTER_IMAGE_NAME = docker-cli-lint$(IMAGE_TAG) CROSS_IMAGE_NAME = docker-cli-cross$(IMAGE_TAG) VALIDATE_IMAGE_NAME = docker-cli-shell-validate$(IMAGE_TAG) E2E_IMAGE_NAME = docker-cli-e2e$(IMAGE_TAG) +GO_BUILD_CACHE ?= y MOUNTS = -v "$(CURDIR)":/go/src/github.com/docker/cli +CACHE_VOLUME_NAME := docker-cli-dev-cache +ifeq ($(GO_BUILD_CACHE),y) +MOUNTS += -v "$(CACHE_VOLUME_NAME):/root/.cache/go-build" +endif VERSION = $(shell cat VERSION) ENVVARS = -e VERSION=$(VERSION) -e GITCOMMIT -e PLATFORM @@ -49,6 +54,7 @@ build: binary ## alias for binary .PHONY: clean clean: build_docker_image ## clean build artifacts docker run --rm $(ENVVARS) $(MOUNTS) $(DEV_DOCKER_IMAGE_NAME) make clean + docker volume rm -f $(CACHE_VOLUME_NAME) .PHONY: test-unit test-unit: build_docker_image # run unit tests (using go test)