Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tiller-proxy build time with BuildKit #1342

Merged
merged 2 commits into from
Dec 4, 2019

Conversation

SimonAlling
Copy link
Contributor

Description of the change

  • BuildKit is used for docker build.
  • COPY . . is replaced with more explicit directives.
  • --mount flag preserves Go build cache between builds.
  • Removing the -a flag makes go build use Go build cache.

Benefits

This brought the build time (after modifying the source code) down from 20 seconds to about 5 seconds on my laptop.

Possible drawbacks

  • BuildKit requires Docker 18.09 or later. I don't know if building still works on older versions of Docker.

Notable changes:

  * BuildKit is used for `docker build`.
  * `COPY . .` is replaced with more explicit directives.
  * `--mount` flag preserves Go build cache between builds.
  * Removing the `-a` flag makes `go build` use Go build cache.

This brought the build time (after modifying the source code) down from
20 seconds to about 5 seconds on my laptop.

More info about BuildKit:
https://docs.docker.com/develop/develop-images/build_enhancements
@andresmgot
Copy link
Contributor

Thanks for the improvements @SimonAlling! Unfortunately, it seems that CircleCI doesn't have a version of docker new enough to support buildkit. Maybe you can move that to a variable? so in your local environment, you execute DOCKER_BUILDKIT=1 make kubeapps/tiller-proxy and in the CI we run it without the buildkit?

@SimonAlling
Copy link
Contributor Author

Thanks for the improvements @SimonAlling! Unfortunately, it seems that CircleCI doesn't have a version of docker new enough to support buildkit. Maybe you can move that to a variable? so in your local environment, you execute DOCKER_BUILDKIT=1 make kubeapps/tiller-proxy and in the CI we run it without the buildkit?

I could definitely do that, but it doesn't seem trivial. In particular, if I remove DOCKER_BUILDKIT=1 in Makefile, it is not possible to make regularly anymore:

$ make kubeapps/tiller-proxy
docker build -t kubeapps/tiller-proxy:dev-2019-12-04T11-54-10-CET --build-arg "VERSION=$(git rev-parse HEAD)" -f cmd/tiller-proxy/Dockerfile .
Sending build context to Docker daemon  64.37MB
Error response from daemon: Dockerfile parse error line 12: Unknown flag: mount

However, judging from the CircleCI output, you're using Docker 18.09, which does support BuildKit:

Build-agent version 1.0.21372-bd73ea34 (2019-12-03T19:06:06+0000)
Docker Engine Version: 18.09.6

So I'm a bit surprised that it doesn't work.

@andresmgot
Copy link
Contributor

Maybe it's something that needs to be enabled in the daemon? This is what I see in the CircleCI logs:

DOCKER_BUILDKIT=1 docker build -t kubeapps/apprepository-controller-ci:build-90c487be9d916722d09c7d7d2a3dec67104beebb --build-arg "VERSION=$(git rev-parse HEAD)" -f cmd/apprepository-controller/Dockerfile .
buildkit not supported by daemon
make: *** [Makefile:22: kubeapps/apprepository-controller] Error 1

@SimonAlling
Copy link
Contributor Author

Yeah, I saw that as well. I'm not very familiar with CircleCI (and I don't have write access anyway); do you have time to try to find a solution? I think almost everyone working with Kubeapps would benefit from this PR.

@andresmgot
Copy link
Contributor

It seems it's possible to enable it from the comment here: https://ideas.circleci.com/ideas/CCI-I-1003

Can you replace in .circleci/config.yaml the line - setup_remote_docker with:

      - setup_remote_docker:
          version: 18.09.3

That should work 🤞

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@andresmgot andresmgot merged commit 237c7b2 into vmware-tanzu:master Dec 4, 2019
@SimonAlling SimonAlling deleted the make-tiller-proxy-dev branch December 4, 2019 17:29
SimonAlling added a commit to SimonAlling/kubeapps that referenced this pull request Dec 6, 2019
SimonAlling added a commit to SimonAlling/kubeapps that referenced this pull request Dec 6, 2019
absoludity pushed a commit that referenced this pull request Dec 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants