Dockerfile publishable cleanup, git diff filter testing removed

main
ziembla 2017-12-01 10:56:36 +01:00
parent 8586120c3d
commit ef9df82689
2 changed files with 22 additions and 74 deletions

View File

@ -32,28 +32,13 @@ RUN jupyter contrib nbextension install --user
RUN jupyter nbextension enable toc2/main
## INFO: Uncomment the RUN command below for easy and constant notebook URL (just localhost:8888)
# That will switch jupyter to using empty password instead of a token.
# To avoid making a security hole you SHOULD in fact not only uncomment but
# regenerate the hash for your own non-empty password and replace the hash below.
# You can compute a password hash in any notebook, just run the code:
# from notebook.auth import passwd
# passwd()
# and take the hash from the output
#RUN mkdir -p ${HOME}/.jupyter && \
# echo 'c.NotebookApp.password = u"sha1:c6bbcba2d04b:f969e403db876dcfbe26f47affe41909bd53392e"' \
# >> ${HOME}/.jupyter/jupyter_notebook_config.py
## INFO: Uncomment the RUN command below to disable git diff paging
RUN git config --global core.pager ''
# INFO: Below - work in progress, nbdime not totally integrated, still it enables diffing
# notebooks with nbdiff (and nbdiff support in git diff command) after connecting to
# the container by "make exec" (docker exec)
# Try:
# nbd NOTEBOOK_NAME.ipynb
# to get nbdiff between checkpointed version and current version of the given notebook
# INFO: Jupyter and nbdime extension are not totally integrated (anaconda image is py36,
# nbdime checks for py35 at the moment, still the config below enables diffing
# notebooks with nbdiff (and nbdiff support in git diff command) after connecting
# to the container by "make exec" (or "docker-compose exec handson-ml bash")
# You may also try running:
# nbd NOTEBOOK_NAME.ipynb
# to get nbdiff between checkpointed version and current version of the given notebook
USER root
WORKDIR /
RUN conda install -y -c conda-forge nbdime
@ -62,10 +47,10 @@ WORKDIR ${workdir}
RUN git-nbdiffdriver config --enable --global
## INFO: Optionally uncomment any (one) of the following RUN commands below to ignore either
# INFO: Optionally uncomment any (one) of the following RUN commands below to ignore either
# metadata or details in nbdiff within git diff
#RUN git config --global diff.jupyternotebook.command 'git-nbdiffdriver diff --ignore-metadata'
#RUN git config --global diff.jupyternotebook.command 'git-nbdiffdriver diff --ignore-details'
RUN git config --global diff.jupyternotebook.command 'git-nbdiffdriver diff --ignore-details'
# INFO: Dirty nbdime patching
@ -85,12 +70,17 @@ COPY docker/bashrc /tmp/bashrc
RUN cat /tmp/bashrc >> ${HOME}/.bashrc
RUN sudo rm /tmp/bashrc
# INFO: Uncomment the RUN command below to disable git diff paging
#RUN git config --global core.pager ''
# INFO: Git filter testing
COPY docker/ipynb_cleaner.py /usr/bin/ipynb_cleaner
RUN mkdir -p ~/.config/git \
&& echo '*.ipynb filter=clean_ipynb' >> ~/.config/git/attributes \
&& git config --global filter.clean_ipynb.clean ipynb_cleaner \
&& git config --global filter.clean_ipynb.smudge cat
# && git config --global filter.clean_ipynb.clean 'ipynb_cleaner %f'
# INFO: Uncomment the RUN command below for easy and constant notebook URL (just localhost:8888)
# That will switch jupyter to using empty password instead of a token.
# To avoid making a security hole you SHOULD in fact not only uncomment but
# regenerate the hash for your own non-empty password and replace the hash below.
# You can compute a password hash in any notebook, just run the code:
# from notebook.auth import passwd
# passwd()
# and take the hash from the output
#RUN mkdir -p ${HOME}/.jupyter && \
# echo 'c.NotebookApp.password = u"sha1:c6bbcba2d04b:f969e403db876dcfbe26f47affe41909bd53392e"' \
# >> ${HOME}/.jupyter/jupyter_notebook_config.py

View File

@ -1,42 +0,0 @@
#!/usr/bin/env python
"""
********************************
DANGER - W.I.P. - TESTING ONLY!!
********************************
Clean jupyter notebook for git operations
Based on "Keeping IPython notebooks under Git version control"
(see:
https://gist.github.com/pbugnion/ea2797393033b54674af
http://pascalbugnion.net/blog/ipython-notebooks-and-git.html
http://stackoverflow.com/a/20844506/827862
)
"""
import sys
import json
sys.stderr.write("\n\nCAUTION ! W.I.P ! Only dropping some test metadata, don't commit!\n\n")
def log(x):
sys.stderr.write("\n\n[{}]\n\n\n".format(x))
def logj(x):
sys.stderr.write("\n\n")
json.dump(x, sys.stderr, sort_keys=True, indent=1, separators=(",",": "))
sys.stderr.write("\n\n")
log(sys.argv)
#sys.exit(17)
nb = sys.stdin.read()
json_in = json.loads(nb)
logj(json_in["metadata"])
del json_in["metadata"]["nav_menu"]
del json_in["metadata"]["toc"]
json_in["metadata"]["language_info"]["version"]="17.0"
logj(json_in["metadata"])
json.dump(json_in, sys.stdout, sort_keys=True, indent=1, separators=(",",": "))