-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add support for building with buildkit #3344
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, | |
decode=False, buildargs=None, gzip=False, shmsize=None, | ||
labels=None, cache_from=None, target=None, network_mode=None, | ||
squash=None, extra_hosts=None, platform=None, isolation=None, | ||
use_config_proxy=True): | ||
version=None, use_config_proxy=True): | ||
""" | ||
Similar to the ``docker build`` command. Either ``path`` or ``fileobj`` | ||
needs to be set. ``path`` can be a local path (to a directory | ||
|
@@ -101,6 +101,10 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, | |
platform (str): Platform in the format ``os[/arch[/variant]]`` | ||
isolation (str): Isolation technology used during build. | ||
Default: `None`. | ||
version (str): Version of the builder backend to use. | ||
- `1` is the first generation classic (deprecated) builder in the Docker daemon (default) | ||
- `2` is [BuildKit](https://github.com/moby/buildkit) | ||
Default: `None`. | ||
use_config_proxy (bool): If ``True``, and if the docker client | ||
configuration file (``~/.docker/config.json`` by default) | ||
contains a proxy configuration, the corresponding environment | ||
|
@@ -253,6 +257,13 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None, | |
) | ||
params['isolation'] = isolation | ||
|
||
if version is not None: | ||
if utils.version_lt(self._version, '1.38'): | ||
raise errors.InvalidVersion( | ||
'version was only introduced in API version 1.38' | ||
) | ||
params['version'] = version | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bumping up the version number doesn't magically implement the BuildKit API. In addition to implementing the gRPC client, you also have to implement several "attachable" servers (auth, secret, ssh) via the reverse-gRPC connection. This is quite complicated than you might imagine; I suggest just shelling out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for reviewing it.
Tests prove you are wrong. No?
Exposing additional options can be done in follow-up PRs. This PR is sufficient for my use case which is building Dockerfiles that depend on BuilKit-features that are not auth, secret, or ssh.
That means installing docker buildx, which means installing docker cli. It's a big downside comparing to just calling the Rest API. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only basic BuildKit features can be enabled by just bumping up the version: The scope of the available features should be documented There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean I should clarify that Otherwise, I expect all options currently supported by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will test it more, and let you know. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this is worse than I expected. I got lucky with the tests because I only tried with Even a basic Dockerfile like below does not work: @requires_api_version('1.38')
def test_build_buildkit_alpine(self):
script = io.BytesIO('\n'.join([
'FROM alpine',
]).encode('ascii'))
self.tmp_imgs.append('buildkitalpine')
stream = self.client.build(
fileobj=script, tag='buildkitalpine',
version='2'
)
for _chunk in stream:
pass
assert self.client.inspect_image('buildkitalpine') But it's because of a bug: Still, it means not even basic use cases like pulling an image that doesn't require auth will not be able to use this feature. @AkihiroSuda do you have any idea? Otherwise, I think it may be the end of this PR (and a dream). :( This comment says creating a basic session is enough for pull to work. Do you think it would be acceptable to build a solution around it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
SGTM There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't been able to build anything so far, but I will update when I have any news. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI I found some gRPC references from an unfinished buildkit implementation in this library from @shin-: |
||
|
||
if context is not None: | ||
headers = {'Content-Type': 'application/tar'} | ||
if encoding: | ||
|
Uh oh!
There was an error while loading. Please reload this page.