kopia lustrzana https://github.com/jupyterhub/repo2docker
rodzic
cf6674cce8
commit
b5194c9165
|
@ -12,7 +12,7 @@ import docker
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from .detectors import BuildPack, PythonBuildPack, DockerBuildPack
|
from .detectors import BuildPack, PythonBuildPack, DockerBuildPack, CondaBuildPack
|
||||||
from .utils import execute_cmd
|
from .utils import execute_cmd
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class Builder(Application):
|
||||||
|
|
||||||
buildpacks = List(
|
buildpacks = List(
|
||||||
None,
|
None,
|
||||||
[DockerBuildPack, PythonBuildPack],
|
[DockerBuildPack, CondaBuildPack, PythonBuildPack],
|
||||||
config=True
|
config=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ class BuildPack(LoggingConfigurable):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DockerBuildPack(BuildPack):
|
class DockerBuildPack(BuildPack):
|
||||||
name = Unicode('Dockerfile')
|
name = Unicode('Dockerfile')
|
||||||
def detect(self, workdir):
|
def detect(self, workdir):
|
||||||
|
@ -56,7 +55,43 @@ class DockerBuildPack(BuildPack):
|
||||||
self.log.info(progress['stream'].rstrip(), extra=dict(phase='building'))
|
self.log.info(progress['stream'].rstrip(), extra=dict(phase='building'))
|
||||||
|
|
||||||
|
|
||||||
class PythonBuildPack(BuildPack):
|
class S2IBuildPack(BuildPack):
|
||||||
|
def s2i_build(self, workdir, ref, output_image_spec, build_image):
|
||||||
|
# Note: Ideally we'd just copy from workdir here, rather than clone and check out again
|
||||||
|
# However, setting just --copy and not specifying a ref seems to check out master for
|
||||||
|
# some reason. Investigate deeper FIXME
|
||||||
|
cmd = [
|
||||||
|
's2i',
|
||||||
|
'build',
|
||||||
|
'--exclude', '""',
|
||||||
|
'--ref', ref,
|
||||||
|
workdir,
|
||||||
|
build_image,
|
||||||
|
output_image_spec,
|
||||||
|
]
|
||||||
|
try:
|
||||||
|
for line in execute_cmd(cmd):
|
||||||
|
self.log.info(line, extra=dict(phase='building', builder=self.name))
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
self.log.error('Failed to build image!', extra=dict(phase='failed'))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
class CondaBuildPack(S2IBuildPack):
|
||||||
|
"""Build Pack for installing from a conda environment.yml using S2I"""
|
||||||
|
|
||||||
|
name = Unicode('conda')
|
||||||
|
build_image = Unicode('jupyterhub/singleuser-builder-conda:v0.1.5', config=True)
|
||||||
|
|
||||||
|
def detect(self, workdir):
|
||||||
|
return os.path.exists(os.path.join(workdir, 'environment.yml'))
|
||||||
|
|
||||||
|
def build(self, workdir, ref, output_image_spec):
|
||||||
|
return self.s2i_build(workdir, ref, output_image_spec, self.build_image)
|
||||||
|
|
||||||
|
|
||||||
|
class PythonBuildPack(S2IBuildPack):
|
||||||
|
"""Build Pack for installing from a pip requirements.txt using S2I"""
|
||||||
name = Unicode('python-pip')
|
name = Unicode('python-pip')
|
||||||
runtime_builder_map = Dict({
|
runtime_builder_map = Dict({
|
||||||
'python-2.7': 'jupyterhub/singleuser-builder-venv-2.7:v0.1.5',
|
'python-2.7': 'jupyterhub/singleuser-builder-venv-2.7:v0.1.5',
|
||||||
|
@ -78,21 +113,4 @@ class PythonBuildPack(BuildPack):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def build(self, workdir, ref, output_image_spec):
|
def build(self, workdir, ref, output_image_spec):
|
||||||
# Note: Ideally we'd just copy from workdir here, rather than clone and check out again
|
return self.s2i_build(workdir, ref, output_image_spec, self.runtime_builder_map[self.runtime])
|
||||||
# However, setting just --copy and not specifying a ref seems to check out master for
|
|
||||||
# some reason. Investigate deeper FIXME
|
|
||||||
cmd = [
|
|
||||||
's2i',
|
|
||||||
'build',
|
|
||||||
'--exclude', '""',
|
|
||||||
'--ref', ref,
|
|
||||||
workdir,
|
|
||||||
self.runtime_builder_map[self.runtime],
|
|
||||||
output_image_spec
|
|
||||||
]
|
|
||||||
try:
|
|
||||||
for line in execute_cmd(cmd):
|
|
||||||
self.log.info(line, extra=dict(phase='building', builder=self.name))
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
self.log.error('Failed to build image!', extra=dict(phase='failed'))
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
Ładowanie…
Reference in New Issue