Skip to content

Speedup build by skipping what's bind-mounted#29298

Closed
thaJeztah wants to merge 1 commit intomoby:masterfrom
thaJeztah:faster-build
Closed

Speedup build by skipping what's bind-mounted#29298
thaJeztah wants to merge 1 commit intomoby:masterfrom
thaJeztah:faster-build

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

When BIND_DIR is used, all source-code is bind-mounted into the container, so there's no need to COPY the source in the image.

This patch skips the files that are bind-mounted, preventing it from being sent as build-context, and added to the image through COPY.

Some hacks were needed for the .dockerignore file, because we currently don't support specifying an alternative .dockerignore file.

Makefile Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not it be moved to after L47?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me think; I think the issue was that that the original BIND_DIR is overwritten at line 47, and will be either $BINDDIR or "bundles". If it's "bundles", the source-code is not bind-mounted. So we need to look at what's provided at the command-line; if BINDDIR=. or BIND_DIR=. is provided, then the intent was to bind-mount the source files.

I'll check once more

@AkihiroSuda
Copy link
Copy Markdown
Member

Seems hack/dind is not baked into image nor bind-mounted?

$ make binary
...
Step 51/51 : ENTRYPOINT hack/dind
 ---> Using cache
 ---> fe0b68bd073c
Successfully built fe0b68bd073c
mv .dockerignore.orig .dockerignore
rm "Dockerfile.tmp"
docker run --rm -i --privileged -e BUILD_APT_MIRROR -e BUILDFLAGS -e KEEPBUNDLE -e DOCKER_BUILD_ARGS -e DOCKER_BUILD_GOGC -e DOCKER_BUILD_PKGS -e DOCKER_DEBUG -e DOCKER_EXPERIMENTAL -e DOCKER_GITCOMMIT -e DOCKER_GRAPHDRIVER -e DOCKER_INCREMENTAL_BINARY -e DOCKER_PORT -e DOCKER_REMAP_ROOT -e DOCKER_STORAGE_OPTS -e DOCKER_USERLANDPROXY -e TESTDIRS -e TESTFLAGS -e TIMEOUT -e HTTP_PROXY -e HTTPS_PROXY -e NO_PROXY -e http_proxy -e https_proxy -e no_proxy -v "/home/suda/gopath/src/github.com/docker/docker/bundles:/go/src/github.com/docker/docker/bundles" -v "dockerdev-go-pkg-cache-gopath:/go/pkg" -v "dockerdev-go-pkg-cache-goroot-linux_amd64_netgo:/usr/local/go/pkg/linux_amd64_netgo"  -t "docker-dev:thaJeztah-faster-build" hack/make.sh binary
docker: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "exec: \"hack/dind\": stat hack/dind: no such file or directory".
Makefile:86: recipe for target 'binary' failed
make: *** [binary] Error 127

@thaJeztah
Copy link
Copy Markdown
Member Author

Seems hack/dind is not baked into image nor bind-mounted?

Interesting. Let me try and find where that is coming from

When `BIND_DIR` is used, all source-code is
bind-mounted into the container, so there's
no need to `COPY` the source in the image.

This patch skips the files that are bind-mounted,
preventing it from being sent as build-context,
and added to the image through `COPY`.

Some hacks were needed for the `.dockerignore`
file, because we currently don't support
specifying an alternative `.dockerignore` file.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@aaronlehmann
Copy link
Copy Markdown

My SSD thanks you.

docker build ${BUILD_APT_MIRROR} ${DOCKER_BUILD_ARGS} -t "$(DOCKER_IMAGE)" -f "$(DOCKERFILE).tmp" .

mv .dockerignore.orig .dockerignore
rm "$(DOCKERFILE).tmp"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we also need to add *.tmp to .gitignore.

@unclejack
Copy link
Copy Markdown
Contributor

@thaJeztah: Could you find a way to do this without the .dockerignore? It'd be easy to create a temporary build directory for the subset of files and build from there. This would let us avoid the .dockerignore tricks.

@cpuguy83
Copy link
Copy Markdown
Member

I don't know.
It seems to be checking BINDDIR, but I frequently use BINDDIR=bundles rather than BINDDIR=.

@thaJeztah
Copy link
Copy Markdown
Member Author

@cpuguy83
Copy link
Copy Markdown
Member

It is when no DOCKER_HOST is set.

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Jan 26, 2017

@thaJeztah @cpuguy83 any progress on this?

@LK4D4
Copy link
Copy Markdown
Contributor

LK4D4 commented Feb 1, 2017

ping @thaJeztah

@thaJeztah
Copy link
Copy Markdown
Member Author

Let's close this for now, I can revisit after #29405 was merged, and #30290 already makes it a lot faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants