Skip to content

Commit 7609e7f

Browse files
Update build method in docker and legacy files
1 parent 5bf2ead commit 7609e7f

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

repo2docker/app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ def start_container(self):
532532

533533
run_kwargs.update(self.extra_run_kwargs)
534534

535-
container = client.containers.run(
536-
self.output_image_spec, **run_kwargs)
535+
container = client.containers.run(self.output_image_spec, **run_kwargs)
537536

538537
while container.status == 'created':
539538
time.sleep(0.5)
@@ -672,7 +671,7 @@ def build(self):
672671
self.log.info(l['error'], extra=dict(phase='failure'))
673672
raise docker.errors.BuildError(l['error'], build_log='')
674673
elif 'status' in l:
675-
self.log.info('Fetching base image...\r',
674+
self.log.info('Fetching base image...\r',
676675
extra=dict(phase='building'))
677676
else:
678677
self.log.info(json.dumps(l),

repo2docker/buildpacks/docker.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def render(self):
1919
with open(Dockerfile) as f:
2020
return f.read()
2121

22-
def build(self, client, image_spec, memory_limit, build_args, cache_from):
22+
def build(self, client, image_spec, memory_limit, build_args, cache_from, extra_build_kwargs):
2323
"""Build a Docker image based on the Dockerfile in the source repo."""
2424
limits = {
2525
# Always disable memory swap for building, since mostly
@@ -28,15 +28,20 @@ def build(self, client, image_spec, memory_limit, build_args, cache_from):
2828
}
2929
if memory_limit:
3030
limits['memory'] = memory_limit
31-
for line in client.build(
32-
path=os.getcwd(),
33-
dockerfile=self.binder_path(self.dockerfile),
34-
tag=image_spec,
35-
buildargs=build_args,
36-
decode=True,
37-
forcerm=True,
38-
rm=True,
39-
container_limits=limits,
40-
cache_from=cache_from
41-
):
31+
32+
build_kwargs = dict(
33+
path=os.getcwd(),
34+
dockerfile=self.binder_path(self.dockerfile),
35+
tag=image_spec,
36+
buildargs=build_args,
37+
decode=True,
38+
forcerm=True,
39+
rm=True,
40+
container_limits=limits,
41+
cache_from=cache_from
42+
)
43+
44+
build_kwargs.update(extra_build_kwargs)
45+
46+
for line in client.build(**build_kwargs):
4247
yield line

repo2docker/buildpacks/legacy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ def get_build_script_files(self):
7676
7777
This currently adds a frozen set of Python requirements to the dict
7878
of files.
79-
79+
8080
"""
8181
return {
8282
'legacy/root.frozen.yml': '/tmp/root.frozen.yml',
8383
'legacy/python3.frozen.yml': '/tmp/python3.frozen.yml',
8484
}
85-
86-
def build(self, client, image_spec, memory_limit, build_args, cache_from):
85+
86+
def build(self, client, image_spec, memory_limit, build_args, cache_from, extra_build_kwargs):
8787
"""Build a legacy Docker image."""
8888
with open(self.dockerfile, 'w') as f:
8989
f.write(self.render())
@@ -94,7 +94,7 @@ def build(self, client, image_spec, memory_limit, build_args, cache_from):
9494
env_file,
9595
)
9696
shutil.copy(src_path, env_file)
97-
return super().build(client, image_spec, memory_limit, build_args, cache_from)
97+
return super().build(client, image_spec, memory_limit, build_args, cache_from, extra_build_kwargs)
9898

9999
def detect(self):
100100
"""Check if current repo should be built with the Legacy BuildPack.

tests/unit/test_cache_from.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ def test_cache_from_base(tmpdir):
1717
fake_log_value = {'stream': 'fake'}
1818
fake_client = MagicMock(spec=docker.APIClient)
1919
fake_client.build.return_value = iter([fake_log_value])
20+
extra_build_kwargs = {'somekey': 'somevalue'}
2021

2122
# Test base image build pack
2223
tmpdir.chdir()
23-
for line in BaseImage().build(fake_client, 'image-2', '1Gi', {}, cache_from):
24+
for line in BaseImage().build(fake_client, 'image-2', '1Gi', {}, cache_from, extra_build_kwargs):
2425
assert line == fake_log_value
2526
called_args, called_kwargs = fake_client.build.call_args
2627
assert 'cache_from' in called_kwargs
@@ -36,13 +37,14 @@ def test_cache_from_docker(tmpdir):
3637
fake_log_value = {'stream': 'fake'}
3738
fake_client = MagicMock(spec=docker.APIClient)
3839
fake_client.build.return_value = iter([fake_log_value])
39-
40+
extra_build_kwargs = {'somekey': 'somevalue'}
4041
tmpdir.chdir()
42+
4143
# test dockerfile
4244
with tmpdir.join("Dockerfile").open('w') as f:
4345
f.write('FROM scratch\n')
4446

45-
for line in DockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from):
47+
for line in DockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from, extra_build_kwargs):
4648
assert line == fake_log_value
4749
called_args, called_kwargs = fake_client.build.call_args
4850
assert 'cache_from' in called_kwargs
@@ -57,12 +59,13 @@ def test_cache_from_legacy(tmpdir):
5759
fake_log_value = {'stream': 'fake'}
5860
fake_client = MagicMock(spec=docker.APIClient)
5961
fake_client.build.return_value = iter([fake_log_value])
62+
extra_build_kwargs = {'somekey': 'somevalue'}
6063

6164
# Test legacy docker image
6265
with tmpdir.join("Dockerfile").open('w') as f:
6366
f.write('FROM andrewosh/binder-base\n')
6467

65-
for line in LegacyBinderDockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from):
68+
for line in LegacyBinderDockerBuildPack().build(fake_client, 'image-2', '1Gi', {}, cache_from, extra_build_kwargs):
6669
assert line == fake_log_value
6770
called_args, called_kwargs = fake_client.build.call_args
6871
assert 'cache_from' in called_kwargs

0 commit comments

Comments
 (0)