Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #421 from evertrol/add-editable-mode
Add an edit-mode option
- Loading branch information
Showing
7 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM python:3.5 | ||
|
||
RUN pip install --no-cache notebook | ||
|
||
CMD "/bin/sh" | ||
|
||
ADD change.sh /usr/local/bin/change.sh | ||
|
||
ARG NB_UID | ||
ENV HOME /tmp | ||
WORKDIR ${HOME} | ||
|
||
USER $NB_UID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
cat <<EOF > newfile | ||
new contents | ||
EOF | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
import time | ||
import re | ||
import tempfile | ||
from conftest import make_test_func | ||
from repo2docker.app import Repo2Docker | ||
|
||
|
||
DIR = os.path.join(os.path.dirname(__file__), 'dockerfile', 'editable') | ||
|
||
|
||
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) | ||
|
||
|
||
def test_editable_by_host(): | ||
"""Test whether a new file created by the host environment, is | ||
detected in the container""" | ||
|
||
app = Repo2Docker() | ||
app.initialize(['--editable', DIR]) | ||
app.run = False | ||
app.start() # This just build the image and does not run it. | ||
container = app.start_container() | ||
# give the container a chance to start | ||
time.sleep(1) | ||
try: | ||
with tempfile.NamedTemporaryFile(dir=DIR, prefix='testfile', suffix='.txt'): | ||
status, output = container.exec_run(['sh', '-c', 'ls testfile????????.txt']) | ||
assert status == 0 | ||
assert re.match(br'^testfile\w{8}\.txt\n$', output) is not None | ||
# File should be removed in the container as well | ||
status, output = container.exec_run(['sh', '-c', 'ls testfile????????.txt']) | ||
assert status != 1 | ||
assert re.match(br'^testfile\w{8}\.txt\n$', output) is None | ||
|
||
finally: | ||
# stop the container | ||
container.stop() | ||
app.wait_for_container(container) |