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 (
|
||||
BuildPack, PythonBuildPack, DockerBuildPack, LegacyBinderDockerBuildPack,
|
||||
CondaBuildPack, DefaultBuildPack, JuliaBuildPack
|
||||
CondaBuildPack, JuliaBuildPack, Python2BuildPack, BaseImage
|
||||
)
|
||||
from .utils import execute_cmd
|
||||
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):
|
||||
name = 'jupyter-repo2docker'
|
||||
version = __version__
|
||||
|
@ -92,8 +103,18 @@ class Repo2Docker(Application):
|
|||
)
|
||||
|
||||
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,
|
||||
help="""
|
||||
Ordered list of BuildPacks to try to use to build a git repository.
|
||||
|
@ -259,14 +280,19 @@ class Repo2Docker(Application):
|
|||
checkout_path
|
||||
)
|
||||
|
||||
for bp_class in self.buildpacks:
|
||||
bp = bp_class(parent=self, log=self.log, capture=self.json_logs)
|
||||
if bp.detect(checkout_path):
|
||||
os.chdir(checkout_path)
|
||||
for bp_spec in self.buildpacks:
|
||||
bp = c(bp_spec)
|
||||
if bp.detect():
|
||||
self.log.info('Using %s builder\n', bp.name, extra=dict(phase='building'))
|
||||
bp.build(checkout_path, self.ref, self.output_image_spec)
|
||||
break
|
||||
for l in bp.build(self.output_image_spec):
|
||||
if 'stream' in l:
|
||||
self.log.info(l['stream'], extra=dict(phase='building'))
|
||||
elif 'error' in l:
|
||||
self.log.info(l['error'], extra=dict(phase='failure'))
|
||||
sys.exit(1)
|
||||
else:
|
||||
self.log.error('Could not figure out how to build this repository! Tell us?', extra=dict(phase='failed'))
|
||||
self.log.info(json.dumps(l), extra=dict(phase='failure'))
|
||||
sys.exit(1)
|
||||
|
||||
if self.cleanup_checkout:
|
||||
|
|
|
@ -324,15 +324,7 @@ class BuildPack(LoggingConfigurable):
|
|||
custom_context=True,
|
||||
decode=True
|
||||
):
|
||||
if 'stream' in 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)
|
||||
yield line
|
||||
|
||||
|
||||
class BaseImage(BuildPack):
|
||||
|
@ -677,31 +669,3 @@ class LegacyBinderDockerBuildPack(BuildPack):
|
|||
pass
|
||||
|
||||
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