kopia lustrzana https://github.com/jupyterhub/repo2docker
Add test for editable option
This test only verifies the option one way: a change inside the container (a new file) is reflected in the local host repository outside the container. A further test where a modification at the host level is reflected in the container, is still neede.pull/421/head
rodzic
fd21926039
commit
6847e71670
|
@ -0,0 +1,14 @@
|
|||
FROM python:3.5
|
||||
|
||||
RUN pip install --no-cache notebook
|
||||
|
||||
CMD "/bin/sh"
|
||||
|
||||
ADD change.sh /usr/local/bin/change.sh
|
||||
ADD verify verify
|
||||
|
||||
ARG NB_UID
|
||||
ENV HOME /tmp
|
||||
WORKDIR ${HOME}
|
||||
|
||||
USER $NB_UID
|
|
@ -0,0 +1,19 @@
|
|||
Docker - Edit mode
|
||||
------------------
|
||||
|
||||
Using the --editable option with a local repository, one can modify a
|
||||
file or create a new file in the container, and this change is
|
||||
reflected in the respective host directory. It is essentially a
|
||||
shortcut for `--mount
|
||||
type=bind,source=<local-host-repository>,target=.` (where the target
|
||||
resolves into the container working directory).
|
||||
|
||||
This is tested by running the change.sh script inside the container
|
||||
(using the 'cmd' argument to the Repo2Docker app), which creates a new
|
||||
file, and then verifying on the host side the new file is created with
|
||||
the proper contents.
|
||||
|
||||
In practice, this can be used to run a notebook from inside a
|
||||
container (which provides the proper environment), making changes as
|
||||
necessary, which are then immediately reflected in the host
|
||||
repository.
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/bash
|
||||
|
||||
cat <<EOF > newfile
|
||||
new contents
|
||||
EOF
|
||||
exit 0
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
/usr/local/bin/change.sh
|
|
@ -0,0 +1,34 @@
|
|||
import pytest
|
||||
import os
|
||||
import time
|
||||
from conftest import make_test_func
|
||||
|
||||
|
||||
DIR = os.path.join(os.path.dirname(__file__), 'dockerfile', 'editable')
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def run_repo2docker():
|
||||
def run_test(args):
|
||||
return make_test_func(args)()
|
||||
return run_test
|
||||
|
||||
|
||||
def test_editable(run_repo2docker):
|
||||
"""Run a local repository in edit mode. Verify a new file has been
|
||||
created afterwards"""
|
||||
newfile = os.path.join(DIR, 'newfile')
|
||||
try:
|
||||
# If the file didn't get properly cleaned up last time, we
|
||||
# need to do that now
|
||||
os.remove(newfile)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
argv = ['--editable', DIR, '/usr/local/bin/change.sh']
|
||||
run_repo2docker(argv)
|
||||
try:
|
||||
with open(newfile) as fp:
|
||||
contents = fp.read()
|
||||
assert contents == "new contents\n"
|
||||
finally:
|
||||
os.remove(newfile)
|
Ładowanie…
Reference in New Issue