kopia lustrzana https://github.com/jupyterhub/repo2docker
Revert "[MRG] Add limit on git clone depth"
rodzic
4f6501ea6f
commit
a7b1519b4d
|
@ -91,63 +91,22 @@ class Repo2Docker(Application):
|
||||||
)
|
)
|
||||||
|
|
||||||
def fetch(self, url, ref, checkout_path):
|
def fetch(self, url, ref, checkout_path):
|
||||||
def _clone(depth=None):
|
try:
|
||||||
if depth is not None:
|
for line in execute_cmd(['git', 'clone', url, checkout_path],
|
||||||
command = ['git', 'clone', '--depth', str(depth),
|
capture=self.json_logs):
|
||||||
url, checkout_path]
|
self.log.info(line, extra=dict(phase='fetching'))
|
||||||
else:
|
except subprocess.CalledProcessError:
|
||||||
command = ['git', 'clone', url, checkout_path]
|
self.log.error('Failed to clone repository!', extra=dict(phase='failed'))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if ref:
|
||||||
try:
|
try:
|
||||||
for line in execute_cmd(command, capture=self.json_logs):
|
for line in execute_cmd(['git', 'reset', '--hard', ref], cwd=checkout_path,
|
||||||
self.log.info(line, extra=dict(phase='fetching'))
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
self.log.error('Failed to clone repository!',
|
|
||||||
extra=dict(phase='failed'))
|
|
||||||
raise RuntimeError("Failed to clone %s." % url)
|
|
||||||
|
|
||||||
def _unshallow():
|
|
||||||
try:
|
|
||||||
for line in execute_cmd(['git', 'fetch', '--unshallow'],
|
|
||||||
capture=self.json_logs,
|
|
||||||
cwd=checkout_path):
|
|
||||||
self.log.info(line, extra=dict(phase='fetching'))
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
self.log.error('Failed to unshallow repository!',
|
|
||||||
extra=dict(phase='failed'))
|
|
||||||
raise RuntimeError("Failed to create a full clone of"
|
|
||||||
" %s." % url)
|
|
||||||
|
|
||||||
def _contains(ref):
|
|
||||||
try:
|
|
||||||
for line in execute_cmd(['git', 'cat-file', '-t', ref],
|
|
||||||
capture=self.json_logs,
|
|
||||||
cwd=checkout_path):
|
|
||||||
self.log.debug(line, extra=dict(phase='fetching'))
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _checkout(ref):
|
|
||||||
try:
|
|
||||||
for line in execute_cmd(['git', 'reset', '--hard', ref],
|
|
||||||
cwd=checkout_path,
|
|
||||||
capture=self.json_logs):
|
capture=self.json_logs):
|
||||||
self.log.info(line, extra=dict(phase='fetching'))
|
self.log.info(line, extra=dict(phase='fetching'))
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
self.log.error('Failed to check out ref %s', ref,
|
self.log.error('Failed to check out ref %s', ref, extra=dict(phase='failed'))
|
||||||
extra=dict(phase='failed'))
|
sys.exit(1)
|
||||||
raise RuntimeError("Failed to checkout reference %s for"
|
|
||||||
" %s." % (ref, url))
|
|
||||||
|
|
||||||
# create a shallow clone first
|
|
||||||
_clone(depth=50)
|
|
||||||
|
|
||||||
if not _contains(ref):
|
|
||||||
# have to create a full clone
|
|
||||||
_unshallow()
|
|
||||||
_checkout(ref)
|
|
||||||
|
|
||||||
def get_argparser(self):
|
def get_argparser(self):
|
||||||
argparser = argparse.ArgumentParser()
|
argparser = argparse.ArgumentParser()
|
||||||
|
|
|
@ -733,7 +733,9 @@ class LegacyBinderDockerBuildPack(DockerBuildPack):
|
||||||
USER main
|
USER main
|
||||||
WORKDIR /home/main/notebooks
|
WORKDIR /home/main/notebooks
|
||||||
ENV PATH /home/main/anaconda2/envs/python3/bin:$PATH
|
ENV PATH /home/main/anaconda2/envs/python3/bin:$PATH
|
||||||
|
ARG JUPYTERHUB_VERSION
|
||||||
RUN conda install -yq -n python3 notebook==5.0.0 ipykernel==4.6.0 && \
|
RUN conda install -yq -n python3 notebook==5.0.0 ipykernel==4.6.0 && \
|
||||||
|
pip install --no-cache-dir jupyterhub==${JUPYTERHUB_VERSION} && \
|
||||||
conda remove -yq -n python3 nb_conda_kernels && \
|
conda remove -yq -n python3 nb_conda_kernels && \
|
||||||
conda install -yq -n root ipykernel==4.6.0 && \
|
conda install -yq -n root ipykernel==4.6.0 && \
|
||||||
/home/main/anaconda2/envs/python3/bin/ipython kernel install --sys-prefix && \
|
/home/main/anaconda2/envs/python3/bin/ipython kernel install --sys-prefix && \
|
||||||
|
|
|
@ -5,3 +5,4 @@ import sys
|
||||||
assert sys.version_info[:2] == (3, 5), sys.version
|
assert sys.version_info[:2] == (3, 5), sys.version
|
||||||
|
|
||||||
import jupyter
|
import jupyter
|
||||||
|
import jupyterhub
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
# Check that we correctly detect that this ref is more than 50 commits ago
|
|
||||||
# and trigger a full clone of the repository
|
|
||||||
- name: A dummy repo with 100 commits - unshallow to reach ref
|
|
||||||
url: https://github.com/betatim/repo2docker-ci-clone-depth
|
|
||||||
ref: f702ae5c612ca0dcaf77954f9f5dd4ede7cb9b5f
|
|
||||||
verify: python -c "commit = open('COMMIT').read(); assert int(commit) == 1, 'this is not the first commit'"
|
|
||||||
|
|
||||||
- name: A dummy repo with 100 commits - shallow clone is enough
|
|
||||||
url: https://github.com/betatim/repo2docker-ci-clone-depth
|
|
||||||
ref: 28674ab4da34585525d9c5451f6d6a872522d017
|
|
||||||
# we checkout the second to last commit, hence the log has 49 entries at a
|
|
||||||
# max clone depth of 50
|
|
||||||
verify: /bin/bash -c '[ $(git log --oneline | wc -l) == "49" ]'
|
|
Ładowanie…
Reference in New Issue