kopia lustrzana https://github.com/jupyterhub/repo2docker
Update build method in docker and legacy files
rodzic
5bf2eadcf8
commit
7609e7f0aa
|
@ -532,8 +532,7 @@ class Repo2Docker(Application):
|
||||||
|
|
||||||
run_kwargs.update(self.extra_run_kwargs)
|
run_kwargs.update(self.extra_run_kwargs)
|
||||||
|
|
||||||
container = client.containers.run(
|
container = client.containers.run(self.output_image_spec, **run_kwargs)
|
||||||
self.output_image_spec, **run_kwargs)
|
|
||||||
|
|
||||||
while container.status == 'created':
|
while container.status == 'created':
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
@ -672,7 +671,7 @@ class Repo2Docker(Application):
|
||||||
self.log.info(l['error'], extra=dict(phase='failure'))
|
self.log.info(l['error'], extra=dict(phase='failure'))
|
||||||
raise docker.errors.BuildError(l['error'], build_log='')
|
raise docker.errors.BuildError(l['error'], build_log='')
|
||||||
elif 'status' in l:
|
elif 'status' in l:
|
||||||
self.log.info('Fetching base image...\r',
|
self.log.info('Fetching base image...\r',
|
||||||
extra=dict(phase='building'))
|
extra=dict(phase='building'))
|
||||||
else:
|
else:
|
||||||
self.log.info(json.dumps(l),
|
self.log.info(json.dumps(l),
|
||||||
|
|
|
@ -19,7 +19,7 @@ class DockerBuildPack(BuildPack):
|
||||||
with open(Dockerfile) as f:
|
with open(Dockerfile) as f:
|
||||||
return f.read()
|
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."""
|
"""Build a Docker image based on the Dockerfile in the source repo."""
|
||||||
limits = {
|
limits = {
|
||||||
# Always disable memory swap for building, since mostly
|
# Always disable memory swap for building, since mostly
|
||||||
|
@ -28,15 +28,20 @@ class DockerBuildPack(BuildPack):
|
||||||
}
|
}
|
||||||
if memory_limit:
|
if memory_limit:
|
||||||
limits['memory'] = memory_limit
|
limits['memory'] = memory_limit
|
||||||
for line in client.build(
|
|
||||||
path=os.getcwd(),
|
build_kwargs = dict(
|
||||||
dockerfile=self.binder_path(self.dockerfile),
|
path=os.getcwd(),
|
||||||
tag=image_spec,
|
dockerfile=self.binder_path(self.dockerfile),
|
||||||
buildargs=build_args,
|
tag=image_spec,
|
||||||
decode=True,
|
buildargs=build_args,
|
||||||
forcerm=True,
|
decode=True,
|
||||||
rm=True,
|
forcerm=True,
|
||||||
container_limits=limits,
|
rm=True,
|
||||||
cache_from=cache_from
|
container_limits=limits,
|
||||||
):
|
cache_from=cache_from
|
||||||
|
)
|
||||||
|
|
||||||
|
build_kwargs.update(extra_build_kwargs)
|
||||||
|
|
||||||
|
for line in client.build(**build_kwargs):
|
||||||
yield line
|
yield line
|
||||||
|
|
|
@ -76,14 +76,14 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
|
||||||
|
|
||||||
This currently adds a frozen set of Python requirements to the dict
|
This currently adds a frozen set of Python requirements to the dict
|
||||||
of files.
|
of files.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
return {
|
return {
|
||||||
'legacy/root.frozen.yml': '/tmp/root.frozen.yml',
|
'legacy/root.frozen.yml': '/tmp/root.frozen.yml',
|
||||||
'legacy/python3.frozen.yml': '/tmp/python3.frozen.yml',
|
'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."""
|
"""Build a legacy Docker image."""
|
||||||
with open(self.dockerfile, 'w') as f:
|
with open(self.dockerfile, 'w') as f:
|
||||||
f.write(self.render())
|
f.write(self.render())
|
||||||
|
@ -94,7 +94,7 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
|
||||||
env_file,
|
env_file,
|
||||||
)
|
)
|
||||||
shutil.copy(src_path, 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):
|
def detect(self):
|
||||||
"""Check if current repo should be built with the Legacy BuildPack.
|
"""Check if current repo should be built with the Legacy BuildPack.
|
||||||
|
|
|
@ -17,10 +17,11 @@ def test_cache_from_base(tmpdir):
|
||||||
fake_log_value = {'stream': 'fake'}
|
fake_log_value = {'stream': 'fake'}
|
||||||
fake_client = MagicMock(spec=docker.APIClient)
|
fake_client = MagicMock(spec=docker.APIClient)
|
||||||
fake_client.build.return_value = iter([fake_log_value])
|
fake_client.build.return_value = iter([fake_log_value])
|
||||||
|
extra_build_kwargs = {'somekey': 'somevalue'}
|
||||||
|
|
||||||
# Test base image build pack
|
# Test base image build pack
|
||||||
tmpdir.chdir()
|
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
|
assert line == fake_log_value
|
||||||
called_args, called_kwargs = fake_client.build.call_args
|
called_args, called_kwargs = fake_client.build.call_args
|
||||||
assert 'cache_from' in called_kwargs
|
assert 'cache_from' in called_kwargs
|
||||||
|
@ -36,13 +37,14 @@ def test_cache_from_docker(tmpdir):
|
||||||
fake_log_value = {'stream': 'fake'}
|
fake_log_value = {'stream': 'fake'}
|
||||||
fake_client = MagicMock(spec=docker.APIClient)
|
fake_client = MagicMock(spec=docker.APIClient)
|
||||||
fake_client.build.return_value = iter([fake_log_value])
|
fake_client.build.return_value = iter([fake_log_value])
|
||||||
|
extra_build_kwargs = {'somekey': 'somevalue'}
|
||||||
tmpdir.chdir()
|
tmpdir.chdir()
|
||||||
|
|
||||||
# test dockerfile
|
# test dockerfile
|
||||||
with tmpdir.join("Dockerfile").open('w') as f:
|
with tmpdir.join("Dockerfile").open('w') as f:
|
||||||
f.write('FROM scratch\n')
|
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
|
assert line == fake_log_value
|
||||||
called_args, called_kwargs = fake_client.build.call_args
|
called_args, called_kwargs = fake_client.build.call_args
|
||||||
assert 'cache_from' in called_kwargs
|
assert 'cache_from' in called_kwargs
|
||||||
|
@ -57,12 +59,13 @@ def test_cache_from_legacy(tmpdir):
|
||||||
fake_log_value = {'stream': 'fake'}
|
fake_log_value = {'stream': 'fake'}
|
||||||
fake_client = MagicMock(spec=docker.APIClient)
|
fake_client = MagicMock(spec=docker.APIClient)
|
||||||
fake_client.build.return_value = iter([fake_log_value])
|
fake_client.build.return_value = iter([fake_log_value])
|
||||||
|
extra_build_kwargs = {'somekey': 'somevalue'}
|
||||||
|
|
||||||
# Test legacy docker image
|
# Test legacy docker image
|
||||||
with tmpdir.join("Dockerfile").open('w') as f:
|
with tmpdir.join("Dockerfile").open('w') as f:
|
||||||
f.write('FROM andrewosh/binder-base\n')
|
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
|
assert line == fake_log_value
|
||||||
called_args, called_kwargs = fake_client.build.call_args
|
called_args, called_kwargs = fake_client.build.call_args
|
||||||
assert 'cache_from' in called_kwargs
|
assert 'cache_from' in called_kwargs
|
||||||
|
|
Ładowanie…
Reference in New Issue