Browse code

Bind-mount context for Dockerfile build targets

Signed-off-by: Brian Goff <cpuguy83@gmail.com>

Brian Goff authored on 2019/11/06 06:41:04
Showing 1 changed files
... ...
@@ -309,12 +309,7 @@ VOLUME /var/lib/docker
309 309
 # Wrap all commands in the "docker-in-docker" script to allow nested containers
310 310
 ENTRYPOINT ["hack/dind"]
311 311
 
312
-FROM runtime-dev AS src
313
-# Make arg inheritable
314
-WORKDIR /go/src/github.com/docker/docker
315
-COPY . /go/src/github.com/docker/docker
316
-
317
-FROM src AS binary-base
312
+FROM runtime-dev AS binary-base
318 313
 ARG DOCKER_GITCOMMIT=HEAD
319 314
 ENV DOCKER_GITCOMMIT=${DOCKER_GITCOMMIT}
320 315
 ARG VERSION
... ...
@@ -327,6 +322,7 @@ ARG DEFAULT_PRODUCT_LICENSE
327 327
 ENV DEFAULT_PRODUCT_LICENSE=${DEFAULT_PRODUCT_LICENSE}
328 328
 ARG DOCKER_BUILDTAGS
329 329
 ENV DOCKER_BUILDTAGS="${DOCKER_BUILDTAGS}"
330
+ENV PREFIX=/build
330 331
 # TODO: This is here because hack/make.sh binary copies these extras binaries
331 332
 # from $PATH into the bundles dir.
332 333
 # It would be nice to handle this in a different way.
... ...
@@ -335,26 +331,32 @@ COPY --from=runc        /build/ /usr/local/bin/
335 335
 COPY --from=containerd  /build/ /usr/local/bin/
336 336
 COPY --from=rootlesskit /build/ /usr/local/bin/
337 337
 COPY --from=proxy       /build/ /usr/local/bin/
338
+WORKDIR /go/src/github.com/docker/docker
338 339
 
339 340
 FROM binary-base AS build-binary
340 341
 RUN --mount=type=cache,target=/root/.cache/go-build \
342
+    --mount=type=bind,target=/go/src/github.com/docker/docker \
341 343
         hack/make.sh binary
342 344
 
343 345
 FROM binary-base AS build-dynbinary
344 346
 RUN --mount=type=cache,target=/root/.cache/go-build \
347
+    --mount=type=bind,target=/go/src/github.com/docker/docker \
345 348
         hack/make.sh dynbinary
346 349
 
347 350
 FROM binary-base AS build-cross
348 351
 ARG DOCKER_CROSSPLATFORMS
352
+RUN --mount=type=cache,target=/root/.cache/go-build \
353
+    --mount=type=bind,target=/go/src/github.com/docker/docker \
349 354
         hack/make.sh cross
350 355
 
351 356
 FROM scratch AS binary
352
-COPY --from=build-binary /go/src/github.com/docker/docker/bundles/ /
357
+COPY --from=build-binary /build/bundles/ /
353 358
 
354 359
 FROM scratch AS dynbinary
355
-COPY --from=build-dynbinary /go/src/github.com/docker/docker/bundles/ /
360
+COPY --from=build-dynbinary /build/ /
356 361
 
357 362
 FROM scratch AS cross
358
-COPY --from=build-cross /go/src/github.com/docker/docker/bundles/ /
363
+COPY --from=build-cross /build/ /
359 364
 
360
-FROM src AS final
365
+FROM dev AS final
366
+COPY . /go/src/github.com/docker/docker