kopia lustrzana https://github.com/jupyterhub/repo2docker
Merge pull request #507 from yuvipanda/path
Copy repo to ${REPO_DIR} rather than ${HOME}pull/530/head
commit
d12afc20f9
|
@ -168,6 +168,11 @@ def get_argparser():
|
||||||
help='Use the local repository in edit mode',
|
help='Use the local repository in edit mode',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
argparser.add_argument(
|
||||||
|
'--target-repo-dir',
|
||||||
|
help=Repo2Docker.target_repo_dir.help
|
||||||
|
)
|
||||||
|
|
||||||
argparser.add_argument(
|
argparser.add_argument(
|
||||||
'--appendix',
|
'--appendix',
|
||||||
type=str,
|
type=str,
|
||||||
|
@ -316,6 +321,9 @@ def make_r2d(argv=None):
|
||||||
else:
|
else:
|
||||||
r2d.cleanup_checkout = args.clean
|
r2d.cleanup_checkout = args.clean
|
||||||
|
|
||||||
|
if args.target_repo_dir:
|
||||||
|
r2d.target_repo_dir = args.target_repo_dir
|
||||||
|
|
||||||
return r2d
|
return r2d
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -327,6 +327,16 @@ class Repo2Docker(Application):
|
||||||
config=True
|
config=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
target_repo_dir = Unicode(
|
||||||
|
'',
|
||||||
|
help="""
|
||||||
|
Path inside the image where contents of the repositories are copied to.
|
||||||
|
|
||||||
|
Defaults to ${HOME} if not set
|
||||||
|
""",
|
||||||
|
config=True
|
||||||
|
)
|
||||||
|
|
||||||
def fetch(self, url, ref, checkout_path):
|
def fetch(self, url, ref, checkout_path):
|
||||||
"""Fetch the contents of `url` and place it in `checkout_path`.
|
"""Fetch the contents of `url` and place it in `checkout_path`.
|
||||||
|
|
||||||
|
@ -593,8 +603,10 @@ class Repo2Docker(Application):
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
build_args = {
|
build_args = {
|
||||||
'NB_USER': self.user_name,
|
'NB_USER': self.user_name,
|
||||||
'NB_UID': str(self.user_id)
|
'NB_UID': str(self.user_id),
|
||||||
}
|
}
|
||||||
|
if self.target_repo_dir:
|
||||||
|
build_args['REPO_DIR'] = self.target_repo_dir
|
||||||
self.log.info('Using %s builder\n', bp.__class__.__name__,
|
self.log.info('Using %s builder\n', bp.__class__.__name__,
|
||||||
extra=dict(phase='building'))
|
extra=dict(phase='building'))
|
||||||
|
|
||||||
|
@ -605,7 +617,7 @@ class Repo2Docker(Application):
|
||||||
extra=dict(phase='building'))
|
extra=dict(phase='building'))
|
||||||
elif 'error' in l:
|
elif 'error' in l:
|
||||||
self.log.info(l['error'], extra=dict(phase='failure'))
|
self.log.info(l['error'], extra=dict(phase='failure'))
|
||||||
raise docker.errors.BuildError(l['error'])
|
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'))
|
||||||
|
|
|
@ -42,7 +42,6 @@ RUN adduser --disabled-password \
|
||||||
--gecos "Default user" \
|
--gecos "Default user" \
|
||||||
--uid ${NB_UID} \
|
--uid ${NB_UID} \
|
||||||
${NB_USER}
|
${NB_USER}
|
||||||
WORKDIR ${HOME}
|
|
||||||
|
|
||||||
RUN wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
|
RUN wget --quiet -O - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - && \
|
||||||
DISTRO="bionic" && \
|
DISTRO="bionic" && \
|
||||||
|
@ -98,11 +97,26 @@ COPY {{ src }} {{ dst }}
|
||||||
{{sd}}
|
{{sd}}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
# Allow target path repo is cloned to be configurable
|
||||||
|
ARG REPO_DIR=${HOME}
|
||||||
|
ENV REPO_DIR ${REPO_DIR}
|
||||||
|
WORKDIR ${REPO_DIR}
|
||||||
|
|
||||||
|
# We want to allow two things:
|
||||||
|
# 1. If there's a .local/bin directory in the repo, things there
|
||||||
|
# should automatically be in path
|
||||||
|
# 2. postBuild and users should be able to install things into ~/.local/bin
|
||||||
|
# and have them be automatically in path
|
||||||
|
#
|
||||||
|
# The XDG standard suggests ~/.local/bin as the path for local user-specific
|
||||||
|
# installs. See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
||||||
|
ENV PATH ${HOME}/.local/bin:${REPO_DIR}/.local/bin:${PATH}
|
||||||
|
|
||||||
# Copy and chown stuff. This doubles the size of the repo, because
|
# Copy and chown stuff. This doubles the size of the repo, because
|
||||||
# you can't actually copy as USER, only as root! Thanks, Docker!
|
# you can't actually copy as USER, only as root! Thanks, Docker!
|
||||||
USER root
|
USER root
|
||||||
COPY src/ ${HOME}
|
COPY src/ ${REPO_DIR}
|
||||||
RUN chown -R ${NB_USER}:${NB_USER} ${HOME}
|
RUN chown -R ${NB_USER}:${NB_USER} ${REPO_DIR}
|
||||||
|
|
||||||
{% if env -%}
|
{% if env -%}
|
||||||
# The rest of the environment
|
# The rest of the environment
|
||||||
|
@ -239,10 +253,7 @@ class BuildPack:
|
||||||
Just sets the PATH environment variable. Separated out since
|
Just sets the PATH environment variable. Separated out since
|
||||||
it is very commonly set by various buildpacks.
|
it is very commonly set by various buildpacks.
|
||||||
"""
|
"""
|
||||||
# Allow local user installs into ~/.local, which is where the
|
return []
|
||||||
# XDG desktop standard suggests these should be
|
|
||||||
# See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
|
|
||||||
return ['$HOME/.local/bin']
|
|
||||||
|
|
||||||
def get_labels(self):
|
def get_labels(self):
|
||||||
"""
|
"""
|
||||||
|
@ -525,7 +536,7 @@ class BaseImage(BuildPack):
|
||||||
|
|
||||||
archive_dir, archive = os.path.split(self.stencila_manifest_dir)
|
archive_dir, archive = os.path.split(self.stencila_manifest_dir)
|
||||||
env.extend([
|
env.extend([
|
||||||
("STENCILA_ARCHIVE_DIR", "${HOME}/" + archive_dir),
|
("STENCILA_ARCHIVE_DIR", "${REPO_DIR}/" + archive_dir),
|
||||||
("STENCILA_ARCHIVE", archive),
|
("STENCILA_ARCHIVE", archive),
|
||||||
])
|
])
|
||||||
return env
|
return env
|
||||||
|
|
|
@ -5,6 +5,8 @@ set -ex
|
||||||
NIX_VERSION="2.1.1"
|
NIX_VERSION="2.1.1"
|
||||||
NIX_SHA256="ad10b4da69035a585fe89d7330037c4a5d867a372bb0e52a1542ab95aec67999"
|
NIX_SHA256="ad10b4da69035a585fe89d7330037c4a5d867a372bb0e52a1542ab95aec67999"
|
||||||
|
|
||||||
|
# Do all our operations in /tmp, since we can't rely on current directory being writeable yet.
|
||||||
|
cd /tmp
|
||||||
wget --quiet https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.bz2
|
wget --quiet https://nixos.org/releases/nix/nix-$NIX_VERSION/nix-$NIX_VERSION-x86_64-linux.tar.bz2
|
||||||
echo "$NIX_SHA256 nix-2.1.1-x86_64-linux.tar.bz2" | sha256sum -c
|
echo "$NIX_SHA256 nix-2.1.1-x86_64-linux.tar.bz2" | sha256sum -c
|
||||||
tar xjf nix-*-x86_64-linux.tar.bz2
|
tar xjf nix-*-x86_64-linux.tar.bz2
|
||||||
|
|
|
@ -103,20 +103,26 @@ class Repo2DockerTest(pytest.Function):
|
||||||
|
|
||||||
class LocalRepo(pytest.File):
|
class LocalRepo(pytest.File):
|
||||||
def collect(self):
|
def collect(self):
|
||||||
|
args = [
|
||||||
|
'--appendix', 'RUN echo "appendix" > /tmp/appendix',
|
||||||
|
]
|
||||||
|
# If there's an extra-args.yaml file in a test dir, assume it contains
|
||||||
|
# a yaml list with extra arguments to be passed to repo2docker
|
||||||
|
extra_args_path = os.path.join(self.fspath.dirname, 'extra-args.yaml')
|
||||||
|
if os.path.exists(extra_args_path):
|
||||||
|
with open(extra_args_path) as f:
|
||||||
|
extra_args = yaml.safe_load(f)
|
||||||
|
args += extra_args
|
||||||
|
|
||||||
|
args.append(self.fspath.dirname)
|
||||||
|
|
||||||
yield Repo2DockerTest(
|
yield Repo2DockerTest(
|
||||||
'build', self,
|
'build', self,
|
||||||
args=[
|
args=args
|
||||||
'--appendix', 'RUN echo "appendix" > /tmp/appendix',
|
|
||||||
self.fspath.dirname,
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
yield Repo2DockerTest(
|
yield Repo2DockerTest(
|
||||||
self.fspath.basename, self,
|
self.fspath.basename, self,
|
||||||
args=[
|
args=args + ['./verify']
|
||||||
'--appendix', 'RUN echo "appendix" > /tmp/appendix',
|
|
||||||
self.fspath.dirname,
|
|
||||||
'./verify',
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
Python - Custom Repository Location
|
||||||
|
-----------------------------------
|
||||||
|
|
||||||
|
We want to support custom paths where repositories can be
|
||||||
|
copied to, instead of ${HOME}. The `extra-args.yaml` file in
|
||||||
|
each dir can contain a list of arguments that are passed
|
||||||
|
to repo2docker during the test. We copy this repo to
|
||||||
|
/srv/repo instead of ${HOME}
|
|
@ -0,0 +1,2 @@
|
||||||
|
- --target-repo-dir
|
||||||
|
- /srv/repo
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Python should still be in /srv/conda
|
||||||
|
assert sys.executable == '/srv/conda/bin/python'
|
||||||
|
|
||||||
|
# Repo should be in /srv/repo
|
||||||
|
assert os.path.exists('/srv/repo/verify')
|
||||||
|
assert os.path.abspath(__file__) == '/srv/repo/verify'
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# Verify that ~/.local/bin is on the PATH
|
# Verify that ~/.local/bin & REPO_DIR/.local/bin is on the PATH
|
||||||
import os
|
import os
|
||||||
|
|
||||||
assert os.path.expanduser('~/.local/bin') in os.getenv("PATH"), os.getenv("PATH")
|
assert os.path.expanduser('~/.local/bin') in os.getenv("PATH"), os.getenv("PATH")
|
||||||
|
assert os.getcwd() == os.environ['REPO_DIR']
|
||||||
|
assert '{}/.local/bin'.format(os.environ['REPO_DIR']) in os.getenv('PATH')
|
||||||
|
|
Ładowanie…
Reference in New Issue