kopia lustrzana https://github.com/jupyterhub/repo2docker
Make the repo2docker app work with new buildpacks
rodzic
37b60a04f8
commit
523b30cf7b
|
@ -26,11 +26,22 @@ import subprocess
|
||||||
|
|
||||||
from .detectors import (
|
from .detectors import (
|
||||||
BuildPack, PythonBuildPack, DockerBuildPack, LegacyBinderDockerBuildPack,
|
BuildPack, PythonBuildPack, DockerBuildPack, LegacyBinderDockerBuildPack,
|
||||||
CondaBuildPack, DefaultBuildPack, JuliaBuildPack
|
CondaBuildPack, JuliaBuildPack, Python2BuildPack, BaseImage
|
||||||
)
|
)
|
||||||
from .utils import execute_cmd
|
from .utils import execute_cmd
|
||||||
from . import __version__
|
from . import __version__
|
||||||
|
|
||||||
|
|
||||||
|
def c(args):
|
||||||
|
"""
|
||||||
|
Shortcut to compose many buildpacks together
|
||||||
|
"""
|
||||||
|
image = args[0]()
|
||||||
|
for arg in args[1:]:
|
||||||
|
image = image.compose_with(arg())
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
class Repo2Docker(Application):
|
class Repo2Docker(Application):
|
||||||
name = 'jupyter-repo2docker'
|
name = 'jupyter-repo2docker'
|
||||||
version = __version__
|
version = __version__
|
||||||
|
@ -92,8 +103,18 @@ class Repo2Docker(Application):
|
||||||
)
|
)
|
||||||
|
|
||||||
buildpacks = List(
|
buildpacks = List(
|
||||||
Type(BuildPack),
|
[
|
||||||
[LegacyBinderDockerBuildPack, DockerBuildPack, CondaBuildPack, PythonBuildPack, JuliaBuildPack, DefaultBuildPack],
|
(LegacyBinderDockerBuildPack, ),
|
||||||
|
(DockerBuildPack, ),
|
||||||
|
|
||||||
|
(BaseImage, CondaBuildPack, JuliaBuildPack),
|
||||||
|
(BaseImage, CondaBuildPack),
|
||||||
|
|
||||||
|
(BaseImage, PythonBuildPack, Python2BuildPack, JuliaBuildPack),
|
||||||
|
(BaseImage, PythonBuildPack, JuliaBuildPack),
|
||||||
|
(BaseImage, PythonBuildPack, Python2BuildPack),
|
||||||
|
(BaseImage, PythonBuildPack),
|
||||||
|
],
|
||||||
config=True,
|
config=True,
|
||||||
help="""
|
help="""
|
||||||
Ordered list of BuildPacks to try to use to build a git repository.
|
Ordered list of BuildPacks to try to use to build a git repository.
|
||||||
|
@ -259,15 +280,20 @@ class Repo2Docker(Application):
|
||||||
checkout_path
|
checkout_path
|
||||||
)
|
)
|
||||||
|
|
||||||
for bp_class in self.buildpacks:
|
os.chdir(checkout_path)
|
||||||
bp = bp_class(parent=self, log=self.log, capture=self.json_logs)
|
for bp_spec in self.buildpacks:
|
||||||
if bp.detect(checkout_path):
|
bp = c(bp_spec)
|
||||||
|
if bp.detect():
|
||||||
self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building'))
|
self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building'))
|
||||||
bp.build(checkout_path, self.ref, self.output_image_spec)
|
for l in bp.build(self.output_image_spec):
|
||||||
break
|
if 'stream' in l:
|
||||||
else:
|
self.log.info(l['stream'], extra=dict(phase='building'))
|
||||||
self.log.error('Could not figure out how to build this repository! Tell us?', extra=dict(phase='failed'))
|
elif 'error' in l:
|
||||||
sys.exit(1)
|
self.log.info(l['error'], extra=dict(phase='failure'))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
self.log.info(json.dumps(l), extra=dict(phase='failure'))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if self.cleanup_checkout:
|
if self.cleanup_checkout:
|
||||||
shutil.rmtree(checkout_path)
|
shutil.rmtree(checkout_path)
|
||||||
|
|
|
@ -324,15 +324,7 @@ class BuildPack(LoggingConfigurable):
|
||||||
custom_context=True,
|
custom_context=True,
|
||||||
decode=True
|
decode=True
|
||||||
):
|
):
|
||||||
if 'stream' in line:
|
yield line
|
||||||
print(line['stream'], end='')
|
|
||||||
elif 'error' in line:
|
|
||||||
print(line['error'], end='')
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError("Unexpected return from docker builder: {}".format(json.dumps(line)))
|
|
||||||
else:
|
|
||||||
print("Built image", image_spec)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseImage(BuildPack):
|
class BaseImage(BuildPack):
|
||||||
|
@ -677,31 +669,3 @@ class LegacyBinderDockerBuildPack(BuildPack):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def c(*args):
|
|
||||||
image = args[0]()
|
|
||||||
for arg in args[1:]:
|
|
||||||
image = image.compose_with(arg())
|
|
||||||
return image
|
|
||||||
|
|
||||||
def main():
|
|
||||||
images = [
|
|
||||||
LegacyBinderDockerBuildPack(),
|
|
||||||
DockerBuildPack(),
|
|
||||||
|
|
||||||
c(BaseImage, CondaBuildPack, JuliaBuildPack),
|
|
||||||
c(BaseImage, CondaBuildPack),
|
|
||||||
|
|
||||||
c(BaseImage, PythonBuildPack, Python2BuildPack, JuliaBuildPack),
|
|
||||||
c(BaseImage, PythonBuildPack, JuliaBuildPack),
|
|
||||||
c(BaseImage, PythonBuildPack, Python2BuildPack),
|
|
||||||
c(BaseImage, PythonBuildPack),
|
|
||||||
]
|
|
||||||
|
|
||||||
for i in images:
|
|
||||||
if i.detect():
|
|
||||||
i.build('wat')
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
Ładowanie…
Reference in New Issue