-
Notifications
You must be signed in to change notification settings - Fork 369
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
Shell out to docker buildx build
to build images
#1402
Open
yuvipanda
wants to merge
13
commits into
jupyterhub:main
Choose a base branch
from
yuvipanda:docker-buildx
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d0d87c8
Shell out to `docker buildx build` to build images
yuvipanda 1ca89b8
Remove type hints for now
yuvipanda 258daa7
Automatically load built image to mimic previous behavior
yuvipanda 93cb0d7
Support `Dockerfile` too
yuvipanda 77ed499
Support --platform and --labels
yuvipanda 743c9f9
Iterate labels as dicts
yuvipanda b1cedc4
Remove some patched out tests that don't apply anymore
yuvipanda 8e20b60
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a03bf74
Add a warning + check to make sure docker is installed
yuvipanda d940706
Add extra_buildx_build_args
yuvipanda 5b96156
Fix trait definition
yuvipanda d7968bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6df3ec6
Fix traitlet again?
yuvipanda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ | |
Docker container engine for repo2docker | ||
""" | ||
|
||
import shutil | ||
import tarfile | ||
import tempfile | ||
|
||
from iso8601 import parse_date | ||
from traitlets import Dict | ||
from traitlets import Dict, List, Unicode | ||
|
||
import docker | ||
|
||
from .engine import Container, ContainerEngine, ContainerEngineException, Image | ||
from .utils import execute_cmd | ||
|
||
|
||
class DockerContainer(Container): | ||
|
@@ -53,7 +58,7 @@ class DockerEngine(ContainerEngine): | |
https://docker-py.readthedocs.io/en/4.2.0/api.html#module-docker.api.build | ||
""" | ||
|
||
string_output = False | ||
string_output = True | ||
|
||
extra_init_args = Dict( | ||
{}, | ||
|
@@ -69,6 +74,14 @@ class DockerEngine(ContainerEngine): | |
config=True, | ||
) | ||
|
||
extra_buildx_build_args = List( | ||
[], | ||
help=""" | ||
Extra commandline arguments to pass to `docker buildx build` when building the image. | ||
""", | ||
config=True, | ||
) | ||
|
||
def __init__(self, *, parent): | ||
super().__init__(parent=parent) | ||
try: | ||
|
@@ -94,22 +107,46 @@ def build( | |
platform=None, | ||
**kwargs, | ||
): | ||
return self._apiclient.build( | ||
buildargs=buildargs, | ||
cache_from=cache_from, | ||
container_limits=container_limits, | ||
forcerm=True, | ||
rm=True, | ||
tag=tag, | ||
custom_context=custom_context, | ||
decode=True, | ||
dockerfile=dockerfile, | ||
fileobj=fileobj, | ||
path=path, | ||
labels=labels, | ||
platform=platform, | ||
**kwargs, | ||
) | ||
if not shutil.which("docker"): | ||
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. Looks like |
||
raise RuntimeError("The docker commandline client must be installed") | ||
args = ["docker", "buildx", "build", "--progress", "plain", "--load"] | ||
if buildargs: | ||
for k, v in buildargs.items(): | ||
args += ["--build-arg", f"{k}={v}"] | ||
minrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if cache_from: | ||
for cf in cache_from: | ||
args += ["--cache-from", cf] | ||
|
||
if dockerfile: | ||
args += ["--file", dockerfile] | ||
|
||
if tag: | ||
args += ["--tag", tag] | ||
|
||
if labels: | ||
for k, v in labels.items(): | ||
args += ["--label", f"{k}={v}"] | ||
|
||
if platform: | ||
args += ["--platform", platform] | ||
|
||
# place extra args right *before* the path | ||
args += self.extra_buildx_build_args | ||
|
||
if fileobj: | ||
with tempfile.TemporaryDirectory() as d: | ||
tarf = tarfile.open(fileobj=fileobj) | ||
tarf.extractall(d) | ||
|
||
args += [d] | ||
|
||
yield from execute_cmd(args, True) | ||
else: | ||
# Assume 'path' is passed in | ||
args += [path] | ||
|
||
yield from execute_cmd(args, True) | ||
|
||
def images(self): | ||
images = self._apiclient.images() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to specify the type of items in the list, give a single TraitType instance here (not list):