Skip to content

Commit

Permalink
Docker build reorder and update
Browse files Browse the repository at this point in the history
  • Loading branch information
garethkennedy committed Nov 7, 2018
1 parent 843a272 commit 8acc896
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 15 deletions.
10 changes: 8 additions & 2 deletions Dockerfile
Expand Up @@ -38,8 +38,8 @@ echo "c.NotebookApp.ip = '*'" >> /root/.jupyter/jupyter_notebook_config.py
WORKDIR /usr/local/

# setup scripts and python codes - these are to be automatically updated on the github
ADD https://github.com/garethkennedy/MECSim_Analytics/archive/master.tar.gz /usr/local/git_codes.tar.gz
RUN tar xvfz git_codes.tar.gz
#ADD https://github.com/garethkennedy/MECSim_Analytics/archive/master.tar.gz /usr/local/git_codes.tar.gz
#RUN tar xvfz git_codes.tar.gz
# outputs to ~/MECSim_Analytics-master
RUN rm -rf git_codes.tar.gz
#RUN mv MECSim_Analytics-master/* .
Expand All @@ -54,6 +54,7 @@ WORKDIR /usr/local/MECSim_Analytics-master/
# copy required directories
COPY input/* /usr/local/input/
COPY python/* /usr/local/python/
COPY docs/* /usr/local/docs/
COPY input_templates/* /usr/local/input_templates/
COPY script/* /usr/local/script/
# copy specific files
Expand All @@ -76,6 +77,9 @@ RUN ./MECSim.exe
RUN head output/log.txt
RUN tail output/log.txt

# create py versions of default notebooks
RUN jupyter nbconvert --to python --template=python.tpl python/*

# prepare and test entry script
#COPY MECSim_Analytics-master/entry_script/entry_script.sh .
RUN chmod +x entry_script.sh
Expand All @@ -90,6 +94,8 @@ WORKDIR /usr/local/external/
RUN mkdir input
RUN mkdir python
RUN mkdir script
RUN mkdir input_templates
RUN mkdir docs

WORKDIR /usr/local/

Expand Down
Binary file added docs/TemplateReactions.pdf
Binary file not shown.
Binary file added docs/UserGuide.pdf
Binary file not shown.
44 changes: 34 additions & 10 deletions entry_script/entry_script.sh
Expand Up @@ -10,15 +10,13 @@ ls -lrt external/*
echo "User prompting? Changes saved?"

cp external/input/* input/
cp external/input_templates/* input_templates/
cp external/docs/* docs/
cp external/python/* python/
cp external/script/* script/
# 2: copy back to the mapped directories. Thus they will have the most up to date versions AND any gaps filled in with default files stored in the docker image
cp input/* external/input/
cp python/* external/python/
cp script/* external/script/
# only done in jupyter mode - note that this could cause unexpected behaviour if user was using incorrect dir to update and use script mode?

# convert all ipynb to py
jupyter nbconvert --to python --template=python.tpl python/*

# Entry point script for MECSim docker.

Expand All @@ -27,6 +25,10 @@ if [ "$1" == "--script" ]; then
ls -lrt script/*
dos2unix script/*.sh
chmod +x script/*.sh

# convert all ipynb to py
jupyter nbconvert --to python --template=python.tpl python/*

./script/run_mecsim_script.sh
elif [ "$1" == "--single" ]; then
echo "Running a single MECSim experiment:"
Expand All @@ -39,16 +41,38 @@ elif [ "$1" == "--single" ]; then
[[ -e MECSimOutput_Pot.txt ]] && cp MECSimOutput_Pot.txt output/
elif [ "$1" == "--jupyter" ]; then
echo "Running a jupyter notebook env:"
# 2: copy back to the mapped directories (from above)
cp input/* external/input/
cp input_templates/* external/input_templates/
cp docs/* external/docs/
cp python/* external/python/
cp script/* external/script/

# convert all ipynb to py
jupyter nbconvert --to python --template=python.tpl python/*

dos2unix script/*.sh
chmod +x script/*.sh
./script/run_jupyter_script.sh
elif [ "$1" == "--update" ]; then
echo "Updating all python and jupyter notebooks in your local python directory using latest versions from the github repository ( https://github.com/garethkennedy/MECSim_Analytics/tree/master/python ). CAUTION this will overwrite any notebooks with the same names in your local python directory. As a failsafe the existing contents of python/ are copied to python/backup"
cd python
mkdir backup
cp * backup
curl -L https://codeload.github.com/garethkennedy/MECSim_Analytics/tar.gz/master | tar -xz --strip=2 MECSim_Analytics-master/python
cd ..
# 2: copy back to the mapped directories (from above)
cp input/* external/input/
cp input_templates/* external/input_templates/
cp docs/* external/docs/
cp python/* external/python/
cp script/* external/script/

backup_dirs='python
input_templates'
for this_dir in $backup_dirs;
do
cd $this_dir
mkdir backup
cp * backup
curl -L https://codeload.github.com/garethkennedy/MECSim_Analytics/tar.gz/master | tar -xz --strip=2 MECSim_Analytics-master/$this_dir
cd ..
done
else
echo "Welcome to MECSim docker"
echo ""
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions prepare_docker_build.sh
@@ -0,0 +1,29 @@
#!/bin/bash
docker='/c/gfk/EChem/StatisticalAnalysis/Docker_build/MECSim'

# copy docker build instructions file
cp Dockerfile $docker
# scripts includes running jupyter (run_jupyter_script.sh) and a default run_mecsim_script.sh
# also a sample skeleton file (Master.sk)
mkdir $docker/script
cp script/* $docker/script
# sample skeleton files for different mechanisms (copy over Master.sk)
mkdir $docker/input_templates
cp input_templates/* $docker/input_templates
# documentation (updatable via github via docker)
mkdir $docker/docs
cp docs/* $docker/docs
# sample single run MECSim input file (Master.inp)
mkdir $docker/input
cp input/* $docker/input
# MECSim source code for build (removed from docker container post-compile)
mkdir $docker/src
cp src/* $docker/src
# script to specify docker container functionality at run time
mkdir $docker/entry_script
cp entry_script/* $docker/entry_script
# python scripts that can be editted by user or updated from git
mkdir $docker/python
cp python/*.ipynb $docker/python

# what about the scripts to run the docker container correctly?
2 changes: 1 addition & 1 deletion run_docker_win_cmd_jupyter.bat
@@ -1 +1 @@
docker run -v %cd%/input:/usr/local/external/input -v %cd%/output:/usr/local/output -v %cd%/python:/usr/local/external/python -v %cd%/script:/usr/local/external/script --rm --name mecsim_container -p 8888:8888 -it mecsim --jupyter
docker run -v %cd%/input:/usr/local/external/input -v %cd%/output:/usr/local/output -v %cd%/python:/usr/local/external/python -v %cd%/docs:/usr/local/external/docs -v %cd%/input_templates:/usr/local/external/input_templates -v %cd%/script:/usr/local/external/script --rm --name mecsim_container -p 8888:8888 -it mecsim --jupyter
2 changes: 1 addition & 1 deletion run_docker_win_cmd_single.bat
@@ -1 +1 @@
docker run -v %cd%/input:/usr/local/input -v %cd%/output:/usr/local/output -v %cd%/python:/usr/local/python -v %cd%/script:/usr/local/script -it mecsim --single
docker run -v %cd%/input:/usr/local/input -v %cd%/output:/usr/local/output -it mecsim --single
3 changes: 2 additions & 1 deletion script/run_jupyter_script.sh
@@ -1,10 +1,11 @@
#!/bin/bash

PYTHON_CODE_DIR='python/'
EXTERNAL_DIR='external/'

# Script to run a single MECSim execution. Working directory of wherever this script is called (/ in docker)
echo "In sample customizable MECSim script..."
echo "Any python codes to be put in $PYTHON_CODE_DIR"
echo "jupyter notebook test"
#jupyter notebook --port=80 --no-browser --ip=0.0.0.0 --allow-root
jupyter notebook --port=8888 --no-browser --allow-root
jupyter notebook --notebook-dir=$EXTERNAL_DIR --port=8888 --no-browser --allow-root

0 comments on commit 8acc896

Please sign in to comment.