Update build method in docker and legacy files
MODIFY
repo2docker/app.py
repo2docker/app.py
@@ -532,8 +532,7 @@ class Repo2Docker(Application):
run_kwargs.update(self.extra_run_kwargs)
- container = client.containers.run(
- self.output_image_spec, **run_kwargs)
+ container = client.containers.run(self.output_image_spec, **run_kwargs)
while container.status == 'created':
time.sleep(0.5)

MODIFY
repo2docker/buildpacks/docker.py
repo2docker/buildpacks/docker.py
@@ -19,7 +19,7 @@ class DockerBuildPack(BuildPack):
with open(Dockerfile) as f:
return f.read()
- def build(self, client, image_spec, memory_limit, build_args, cache_from):
+ def build(self, client, image_spec, memory_limit, build_args, cache_from, extra_build_kwargs):
"""Build a Docker image based on the Dockerfile in the source repo."""
limits = {
# Always disable memory swap for building, since mostly
@@ -28,7 +28,8 @@ class DockerBuildPack(BuildPack):
}
if memory_limit:
limits['memory'] = memory_limit
- for line in client.build(
+
+ build_kwargs = dict(
path=os.getcwd(),
dockerfile=self.binder_path(self.dockerfile),
tag=image_spec,
@@ -38,5 +39,9 @@ class DockerBuildPack(BuildPack):
rm=True,
container_limits=limits,
cache_from=cache_from
- ):
+ )
+
+ build_kwargs.update(extra_build_kwargs)
+
+ for line in client.build(**build_kwargs):
yield line

MODIFY
repo2docker/buildpacks/legacy/__init__.py
repo2docker/buildpacks/legacy/__init__.py
@@ -83,7 +83,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
'legacy/python3.frozen.yml': '/tmp/python3.frozen.yml',
}
- def build(self, client, image_spec, memory_limit, build_args, cache_from):
+ def build(self, client, image_spec, memory_limit, build_args, cache_from, extra_build_kwargs):
"""Build a legacy Docker image."""
with open(self.dockerfile, 'w') as f:
f.write(self.render())
@@ -94,7 +94,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
env_file,
)
shutil.copy(src_path, env_file)
- return super().build(client, image_spec, memory_limit, build_args, cache_from)
+ return super().build(client, image_spec, memory_limit, build_args, cache_from, extra_build_kwargs)
def detect(self):
"""Check if current repo should be built with the Legacy BuildPack.

MODIFY
tests/unit/test_cache_from.py
tests/unit/test_cache_from.py
@@ -17,10 +17,11 @@ def test_cache_from_base(tmpdir):
fake_log_value = {'stream': 'fake'}
fake_client = MagicMock(spec=docker.APIClient)
fake_client.build.return_value = iter([fake_log_value])
+ extra_build_kwargs = {'somekey': 'somevalue'}
# Test base image build pack
tmpdir.chdir()
- for line in BaseImage().build(fake_client, 'image-2', '1Gi', {}, cache_from):
+ for line in BaseImage().build(fake_client, 'image-2', '1Gi', {}, cache_from, extra_build_kwargs):
assert line == fake_log_value
called_args, called_kwargs = fake_client.build.call_args
assert 'cache_from' in called_kwargs
@@ -36,13 +37,14 @@ def test_cache_from_docker(tmpdir):
fake_log_value = {'stream': 'fake'}
fake_client = MagicMock(spec=docker.APIClient)
fake_client.build.return_value = iter([fake_log_value])
-
+ extra_build_kwargs = {'somekey': 'somevalue'}
tmpdir.chdir()
+
# test dockerfile
with tmpdir.join("Dockerfile").open('w') as f:
f.write('FROM scratch\n')
- for line in DockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from):
+ for line in DockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from, extra_build_kwargs):
assert line == fake_log_value
called_args, called_kwargs = fake_client.build.call_args
assert 'cache_from' in called_kwargs
@@ -57,12 +59,13 @@ def test_cache_from_legacy(tmpdir):
fake_log_value = {'stream': 'fake'}
fake_client = MagicMock(spec=docker.APIClient)
fake_client.build.return_value = iter([fake_log_value])
+ extra_build_kwargs = {'somekey': 'somevalue'}
# Test legacy docker image
with tmpdir.join("Dockerfile").open('w') as f:
f.write('FROM andrewosh/binder-base\n')
- for line in LegacyBinderDockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from):
+ for line in LegacyBinderDockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from, extra_build_kwargs):
assert line == fake_log_value
called_args, called_kwargs = fake_client.build.call_args
assert 'cache_from' in called_kwargs

Update build method in docker and legacy files