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

[Feature Request] Remove duplicate context transfers #92

Closed
caervs opened this issue Jun 13, 2019 · 4 comments · Fixed by #2615
Closed

[Feature Request] Remove duplicate context transfers #92

caervs opened this issue Jun 13, 2019 · 4 comments · Fixed by #2615
Assignees
Labels
Milestone

Comments

@caervs
Copy link

caervs commented Jun 13, 2019

As an example use case you may have a single intermediary target in your Dockerfile that acts like a cache for all downstream images. You build all your packages in your cache target and then assemble into different binaries for the different services that make up your app.

Today if you have n targets all of which are downstream from a single target, even if the upstream is the only thing that actually relies on the context, the context will be transferred n times in parallel.

Example

  1. Make a large context with
dd if=/dev/zero of=largefile count=262400 bs=1024
  1. Make a Dockerfile with one upstream image that actually uses the context, and three downstream images.
FROM scratch AS upstream

COPY largefile /largefile


FROM upstream AS downstream0

FROM upstream AS downstream1

FROM upstream AS downstream2
  1. Make a bake hcl with the targets
group "default" {
  targets = ["downstream0", "downstream1", "downstream2"]
}

target "downstream0" {
  target = "downstream0"
  tags = ["docker.io/rabrams/downstream0"]
}

target "downstream1" {
  target = "downstream0"
  tags = ["docker.io/rabrams/downstream1"]
}

target "downstream2" {
  target = "downstream0"
  tags = ["docker.io/rabrams/downstream2"]
}
  1. Run docker buildx bake and observe duplicate context transfers
$ docker buildx bake
[+] Building 1.1s (6/12)
 => [downstream1 internal] load .dockerignore                              0.2s
 => => transferring context: 2B                                            0.1s
 => [downstream2 internal] load build context                              0.9s
 => => transferring context: 327.77kB                                      0.9s
 => [downstream0 internal] load build context                              0.9s
 => => transferring context: 360.55kB                                      0.9s
 => [downstream1 internal] load build context                              0.9s
 => => transferring context: 229.45kB                                      0.9s

For large contexts and many downstream images this can be a problem because your uplink is divided between all the context transfers that are doing the same thing.

@tonistiigi tonistiigi added the kind/enhancement New feature or request label Jul 12, 2019
@tonistiigi
Copy link
Member

btw, my old branch that did this tonistiigi/buildx@bake...bake-shared-session but could use some cleanup

@bhavitsharma
Copy link

Hi @tonistiigi, I want to fix this issue. I would appreciate any help: For example - what part of the codebase do I need to look at?
Some specific questions:

  • How is context transferred to the daemon?
  • Where does the code for evaluation of bake hcl lives? How does it determine which contexts daemon needs?
  • How is the feedback time to test the changes?

Any high level description is good enough for me to get started.

@bhavitsharma
Copy link

I looked at your commit, but the code seems significantly different now.

@bhavitsharma
Copy link

Hey @tonistiigi, I think I have some understanding of the codebase now. It looks like we need to provide a shared session to establish only one connection to the docker daemon. Please correct me if I am wrong:
I would really appreciate your help here!

  • In your referenced commit, we create a new shared session for every new target. Is that desirable? Shouldn't we have just one "shared session" for all the input targets?
  • Does shared session map 1:1 with transferring context, i.e. every new "shared session" will lead to a new context transfer?
  • Our requirement is - all the build files use the same context, i.e. "."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants