Browse code

Use BuildKit to skip source code COPY if BIND_DIR set

build the final stage of the Dockerfile (including COPY ...) if no BIND_DIR
is used.
if BIND_DIR is used, build the dev stage, thus skipping the COPY.

Original author: @thaJeztah

Signed-off-by: Mohammad Nasirifar <farnasirim@gmail.com>

Mohammad Nasirifar authored on 2018/12/14 10:26:10
Showing 2 changed files
... ...
@@ -236,5 +236,7 @@ WORKDIR /go/src/github.com/docker/docker
236 236
 VOLUME /var/lib/docker
237 237
 # Wrap all commands in the "docker-in-docker" script to allow nested containers
238 238
 ENTRYPOINT ["hack/dind"]
239
+
240
+FROM dev AS final
239 241
 # Upload docker source
240 242
 COPY . /go/src/github.com/docker/docker
... ...
@@ -28,6 +28,7 @@ DOCKER_ENVS := \
28 28
 	-e KEEPBUNDLE \
29 29
 	-e DOCKER_BUILD_ARGS \
30 30
 	-e DOCKER_BUILD_GOGC \
31
+	-e DOCKER_BUILD_OPTS \
31 32
 	-e DOCKER_BUILD_PKGS \
32 33
 	-e DOCKER_BUILDKIT \
33 34
 	-e DOCKER_BASH_COMPLETION_PATH \
... ...
@@ -107,6 +108,9 @@ INTERACTIVE := $(shell [ -t 0 ] && echo 1 || echo 0)
107 107
 ifeq ($(INTERACTIVE), 1)
108 108
 	DOCKER_FLAGS += -t
109 109
 endif
110
+ifeq ($(BIND_DIR), .)
111
+	DOCKER_BUILD_OPTS += --target=dev
112
+endif
110 113
 
111 114
 DOCKER_RUN_DOCKER := $(DOCKER_FLAGS) "$(DOCKER_IMAGE)"
112 115
 
... ...
@@ -123,7 +127,7 @@ dynbinary: build ## build the linux dynbinaries
123 123
 
124 124
 build: bundles
125 125
 	$(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})
126
-	docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
126
+	docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} ${DOCKER_BUILD_OPTS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE)" .
127 127
 
128 128
 bundles:
129 129
 	mkdir bundles