8000 [enhancement] add optional (features) fields in daemon.json to enable buildkit by AntaresS · Pull Request #37593 · moby/moby · GitHub
[go: up one dir, main page]

Skip to content

Conversation

AntaresS
Copy link
Contributor
@AntaresS AntaresS commented Aug 6, 2018

Signed-off-by: Anda Xu anda.xu@docker.com

- What I did

  • Add optional fields to allow enable buildkit as Dockerfile builder from daemon.json.
    • Add new flag --buildkit in dockerd to enable buildkit as Dockerfile builder. (This is also a pre-req by the daemon implementaion)
  • no longer assuming buildkit is on by default if "--experimental" is true.

- How I did it

- How to verify it
image

also dockerd --help will print help info of --buildkit flag

 --buildkit                                Enable buildkit as dockerfile builder

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

@AntaresS AntaresS requested a review from dnephin as a code owner August 6, 2018 01:55
@AntaresS AntaresS force-pushed the add-enable-buildkit branch 4 times, most recently from 0bdbb35 to ae1f83e Compare August 6, 2018 05:15
@codecov
Copy link
codecov bot commented Aug 6, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@7d4fa69). Click here to learn what that means.
The diff coverage is 6.66%.

@@            Coverage Diff            @@
##             master   #37593   +/-   ##
=========================================
  Coverage          ?   35.82%           
=========================================
  Files             ?      607           
  Lines             ?    44733           
  Branches          ?        0           
=========================================
  Hits              ?    16025           
  Misses            ?    26497           
  Partials          ?     2211

@AntaresS AntaresS force-pushed the add-enable-buildkit branch from ae1f83e to 96f5eeb Compare August 6, 2018 05:22
@AntaresS
Copy link
Contributor Author
AntaresS commented Aug 6, 2018

@tonistiigi @tiborvass @dhiltgen ptal

@AntaresS AntaresS force-pushed the add-enable-buildkit branch from 96f5eeb to 65bdc72 Compare August 6, 2018 18:46
@AntaresS AntaresS changed the title [WIP] add optional fields in daemon.json to enable buildkit [enhancement] add "--buildkit" flag and optional fields in daemon.json to enable buildkit Aug 6, 2018
@AntaresS
Copy link
Contributor Author
AntaresS commented Aug 7, 2018

cc @andrewhsu

@tonistiigi
Copy link
Member

@tiborvass I don't think we need a flag. Config should be enough.

Copy link
Member

Choose a reason for hiding this comment

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

Why is this a middleware?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess it's because all the other things that were setting headers were middlewares as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tonistiigi This is how the request headers are set, Docker-Experimental for one example. In an early discussion, we wanted to have _ping endpoint to carry the information of whether buildkit is enabled on daemon. And this middleware sets the header to _ping.

Copy link
Member

Choose a reason for hiding this comment

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

This looks very weird that API command that does not have anything to do with builder returns Buildkit=true.

@AntaresS
Copy link
Contributor Author
AntaresS commented Aug 7, 2018

I don't think we need a flag. Config should be enough.

@tonistiigi I thought this way too. However, it seems that when the daemon starts and loads the config, there is always a flag check to make sure whatever in the daemon.json is also a valid flag in dockerd cli. Otherwise, an error will be returned by

return fmt.Errorf("the following directives don't match any configuration option: %s", strings.Join(unknown, ", "))

Copy link
Contributor

Choose a reason for hiding this comment

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

BuildKit that's how it's spelled elsewhere especially for API types

Copy link
Member

Choose a reason for hiding this comment

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

Should it be FeatureBuildKit ? Also, need to make the flag longer, or modify the config condition.

@AntaresS AntaresS force-pushed the add-enable-buildkit branch 3 times, most recently from 7eb16e1 to 21e79dd Compare August 7, 2018 18:10
@AntaresS
Copy link
Contributor Author
AntaresS commented Aug 7, 2018

@tonistiigi @tiborvass Made "buildkit" an exception from flag validation as we discussed. Now it's only an optional field in daemon.json

@AntaresS AntaresS changed the title [enhancement] add "--buildkit" flag and optional fields in daemon.json to enable buildkit [enhancement] add optional fields in daemon.json to enable buildkit Aug 7, 2018
@AntaresS AntaresS force-pushed the add-enable-buildkit branch from 21e79dd to e5bf6be Compare August 7, 2018 20:38
Copy link
Member
@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

I don't want to over-complicate this, but it seems we are now moving from a generic all-or-nothing flag to feature flags (liberal use of the term flag here).

I would expect that the pieces in the API to signal somehow that something is a feature flag rather than just some top-level field.

Copy link
Member

Choose a reason for hiding this comment

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

What makes these special as opposed to just headers?

Copy link
Member

Choose a reason for hiding this comment

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

Worried that we are leaking implementation details into the API package here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cpuguy83 @AntaresS let's do Feature-BuildKit-Enabled

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make this FeatureBuildKit and json:"feature-buildkit"

Copy link
Contributor

Choose a reason for hiding this comment

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

@AntaresS we don't want this to be the case, because it will add the header on every response. I don't think you need middlewares, you should be able to just add the header in the ping handler.

Copy link
Contributor Author
@AntaresS AntaresS Aug 9, 2018

Choose a reason for hiding this comment

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

@tiborvass well the ping handler by itself doesn't know anything about daemon config. Unless we modify the Backend interface to get the info of whether buildkit is enabled or somehow pass that knowledge into NewRouter. Is this more desired?

Copy link
Contributor

Choose a reason for hiding this comment

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

FeatureBuildKit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@AntaresS AntaresS force-pushed the add-enable-buildkit branch 3 times, most recently from 86ce496 to f85b725 Compare August 9, 2018 17:24
@thaJeztah
Copy link
Member

For the daemon.json, I'm +1 on using "features": {"buildkit": true} (or {"features": [{"buildkit":true}]}). Yes; it's verbose, but I think it's clearer that it's to enable/disable features, and we can add more features without changing the overall format

@tiborvass
Copy link
Contributor

@thaJeztah alright fine with {"features": [{"buildkit":true}]} and Builder-Version.

@AntaresS AntaresS force-pushed the add-enable-buildkit branch 2 times, most recently from 614248d to 72eb175 Compare August 17, 2018 21:39
@AntaresS
Copy link
Contributor Author

@AntaresS AntaresS force-pushed the add-enable-buildkit branch 2 times, most recently from df5643f to fc627b4 Compare August 18, 2018 00:50
client/ping.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

@AntaresS this should be:

if bv := serverResp.header.Get("Builder-Version"); bv != "" {
    ping.BuilderVersion = bv
}

client/ping.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong header in comment

@AntaresS AntaresS force-pushed the add-enable-buildkit branch from fc627b4 to 66a2eb1 Compare August 19, 2018 07:29
Copy link
Contributor
@tiborvass tiborvass left a comment

Choose a reason for hiding this comment

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

LGTM

@tiborvass
Copy link
Contributor

@vdemeester @thaJeztah @cpuguy83 PTAL

Copy link
Member
@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

looks like there's still some issues with the current implementation/code:

$ mkdir -p /etc/docker
$ echo '{"experimental":true, "features": {"buildkit":true}}' > /etc/docker/daemon.json
$ dockerd
unable to configure the Docker daemon with file /etc/docker/daemon.json: the following directives don't match any configuration option: buildkit

Changing to feature-buildkit makes the daemon start;

$ echo '{"experimental":true, "features": {"feature-buildkit":true}}' > /etc/docker/daemon.json
...
INFO[2018-08-19T09:12:24.248409702Z] Daemon has completed initialization
INFO[2018-08-19T09:12:24.274417246Z] API listen on /var/run/docker.sock

But buildkit won't be enabled / visible in /_ping;

$ curl -v --unix-socket /var/run/docker.sock http://localhost/_ping
...
< HTTP/1.1 200 OK
< Api-Version: 1.39
< Docker-Experimental: true
< Ostype: linux
< Server: Docker/dev (linux)
< Date: Sun, 19 Aug 2018 09:13:17 GMT
< Content-Length: 2
< Content-Type: text/plain; charset=utf-8

Live-reload also isn't implemented yet (could possibly be done in a follow-up);

$ rm /etc/docker/daemon.json 
$ kill -HUP $(pidof dockerd)
Got signal to reload configuration, reloading from: /etc/docker/daemon.json 
INFO[2018-08-19T09:18:19.584233372Z] Reloaded configuration: {"mtu":1500,"pidfile":"/var/run/docker.pid","data-root":"/var/lib/docker","exec-root":"/var/run/docker","group":"docker","deprecated-key-path":"/etc/docker/key.json","max-concurrent-downloads":3,"max-concurrent-uploads":5,"shutdown-timeout":15,"hosts":["unix:///var/run/docker.sock"],"log-level":"info","swarm-default-advertise-addr":"","swarm-raft-heartbeat-tick":0,"swarm-raft-election-tick":0,"metrics-addr":"","log-driver":"json-file","ip":"0.0.0.0","icc":true,"iptables":true,"ip-forward":true,"ip-masq":true,"userland-proxy":true,"default-address-pools":{},"network-control-plane-mtu":1500,"disable-legacy-registry":true,"experimental":true,"containerd":"/var/run/docker/containerd/docker-containerd.sock","features":{"feature-buildkit":true},"runtimes":{"runc":{"path":"docker-runc"}},"default-runtime":"runc","oom-score-adjust":-500,"default-shm-size":67108864,"default-ipc-mode":"shareable","resolv-conf":"/etc/resolv.conf"} 

Copy link
Member

Choose a reason for hiding this comment

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

If the buildkit feature is not set in daemon.json, no Builder-Version header is set? I'd expect features: {buildkit:false}} and {} to be equivalent (i.e. in both cases buildkit is not active, so builder version is 1)

Copy link
Contributor

Choose a reason for hiding this comment

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

@thaJeztah yes. So it doesn't matter.

Copy link
Member

Choose a reason for hiding this comment

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

< 67DE /option>

Shouldn't the header be set if no daemon.json is present (thus config.Features["buildkit"] is not set)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thaJeztah We actually meant to make it distinguished, so features: {buildkit:false}} means buildkit is not allowed while {} (or not set in daemon.json) means it's up to client to choose builder version. For header it is the same concept.

Copy link
Member

Choose a reason for hiding this comment

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

Still confused by this; how would the client know that buildkit is available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thaJeztah It's obvious that when the features is set in daemon.json client will know the version. If it is not set in the config file (i.e. header will not include Builder-Version either), cli will use the env var to determine whether to make buildkit request or otherwise use the old builder. Maybe the changes from cli can also help you - docker/cli#1275

Copy link
Member

Choose a reason for hiding this comment

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

Got it

Copy link
Member

Choose a reason for hiding this comment

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

This should be buildkit now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I thought this was fixed. @AntaresS

Copy link
Contributor

Choose a reason for hiding this comment

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

Or maybe just features

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

client/ping.go Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@AntaresS AntaresS force-pushed the add-enable-buildkit branch from 66a2eb1 to d9019e0 Compare August 19, 2018 21:50
Signed-off-by: Anda Xu <anda.xu@docker.com>
Copy link
Member
@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah merged commit 9916827 into moby:master Aug 20, 2018
@thaJeztah thaJeztah changed the title [enhancement] add optional fields in daemon.json to enable buildkit [enhancement] add optional (features) fields in daemon.json to enable buildkit Feb 28, 2019
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.

9 participants
0