-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(!untested!) add Dockerfile, docker-compose, scripts. change dir struct.
- Loading branch information
EsGeh
authored and
EsGeh
committed
Nov 12, 2019
1 parent
fa97c34
commit a6b0d41
Showing
172 changed files
with
519 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
output | ||
/input/ | ||
/output/ | ||
examples | ||
|
||
# Byte-compiled / optimized / DLL files | ||
|
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,24 @@ | ||
FROM python:3 | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
ENV SHELL /bin/bash | ||
|
||
# ------------------------------------------ | ||
# install necessary packages via apt-get: | ||
# ------------------------------------------ | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
graphicsmagick \ | ||
pandoc \ | ||
pandoc-citeproc \ | ||
curl \ | ||
texlive-xetex | ||
|
||
# this is supposed to save memory: | ||
RUN rm -rf /var/lib/apt/lists/* | ||
|
||
# ------------------------------------------ | ||
# install python dependencies: | ||
# ------------------------------------------ | ||
COPY requirements.txt "$INSTALL_DIR/" | ||
RUN pip install -r requirements.txt |
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,20 @@ | ||
version: '3.7' | ||
|
||
services: | ||
|
||
eoa_skripts: | ||
build: . | ||
image: ${IMAGE_NAME} | ||
container_name: ${CONTAINER_NAME} | ||
command: bash -c 'while :; do :; done & kill -STOP $$! && wait $$!' | ||
volumes: | ||
- ./${SRC_DIR}:${SRC_DIR_IN_CONTAINER} | ||
- ./${INPUT_DIR}:${INPUT_DIR_IN_CONTAINER} | ||
- ./${OUTPUT_DIR}:${OUTPUT_DIR_IN_CONTAINER} | ||
working_dir: ${SRC_DIR_IN_CONTAINER} | ||
environment: | ||
- INPUT_DIR=${INPUT_DIR_IN_CONTAINER} | ||
- OUTPUT_DIR=${OUTPUT_DIR_IN_CONTAINER} | ||
- INSTALL_DIR=${SRC_DIR_IN_CONTAINER} | ||
ports: [] | ||
user: ${USER}:${GROUP} |
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,25 @@ | ||
[config] | ||
|
||
################################################### | ||
# container names: | ||
################################################### | ||
|
||
IMAGE_NAME=eoa_skripts | ||
CONTAINER_NAME=eoa_skripts | ||
|
||
|
||
################################################### | ||
# volumes: | ||
################################################### | ||
|
||
SRC_DIR=src | ||
SRC_DIR_IN_CONTAINER=/eoa/skripts | ||
INPUT_DIR=input | ||
INPUT_DIR_IN_CONTAINER=/eoa/input | ||
OUTPUT_DIR=output | ||
OUTPUT_DIR_IN_CONTAINER=/eoa/output | ||
|
||
################################################### | ||
# user and group: | ||
# USER=$(id -u) | ||
# GROUP=$(id -g) |
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,26 @@ | ||
#!/bin/fish | ||
|
||
if not set -q SCRIPT_DIR | ||
echo "ERROR in (status -m): \$SCRIPT_DIR is undefined!" | ||
exit 1 | ||
end | ||
set BASE_DIR "$SCRIPT_DIR/.." | ||
|
||
####################################### | ||
# actual script | ||
####################################### | ||
|
||
set RUNTIME_DIR "runtime_data" | ||
|
||
################################################### | ||
# export all these variables, so | ||
# they can be referenced in the docker-compose.yaml | ||
################################################### | ||
|
||
# convert bash syntax to fish syntax: | ||
set commands (cat ./scripts/config/env.conf | grep -E --invert-match '^#|^[[:space:]]*$' | sed 's/^\(.*\)=\(.*\)/set -x \1 \2/' | sed 's/\$(/(/g') | ||
|
||
for cmd in $commands | ||
echo "cmd: $cmd" | ||
eval "$cmd" | ||
end |
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,25 @@ | ||
#!/bin/bash | ||
|
||
if [[ "$SCRIPT_DIR" == "" ]]; then | ||
echo "ERROR in ./scripts/config/load_env.sh: \$SCRIPT_DIR is undefined!" | ||
exit 1 | ||
fi | ||
BASE_DIR="$SCRIPT_DIR/.." | ||
|
||
####################################### | ||
# actual script | ||
####################################### | ||
|
||
|
||
# these are the default settings used by all scripts: | ||
|
||
RUNTIME_DIR=runtime_data | ||
|
||
################################################### | ||
# export all these variables, so | ||
# they can be referenced in the docker-compose.yaml | ||
################################################### | ||
set -a | ||
source $SCRIPT_DIR/config/env.conf | ||
set -a | ||
# (stop exporting variables) |
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,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from utils.settings import BASE_DIR, load_config | ||
from utils.functions import exec_in_container | ||
|
||
from pathlib import Path | ||
import os | ||
|
||
if __name__ == '__main__': | ||
|
||
from argparse import ArgumentParser | ||
|
||
config = load_config() | ||
|
||
parser = ArgumentParser( | ||
description="open bash to the container, optionally exec CMD there" | ||
) | ||
parser.add_argument( | ||
"CMD", | ||
nargs='*', | ||
) | ||
args = parser.parse_args() | ||
|
||
CMDS= \ | ||
(vars(args)['CMD']) | ||
|
||
print( CMDS ) | ||
|
||
exec_in_container( | ||
*CMDS, | ||
env=config | ||
) |
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,58 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from utils.settings import BASE_DIR, load_config | ||
|
||
from pathlib import Path | ||
import shutil | ||
import os | ||
|
||
def rm_dirs( config ): | ||
path = Path( BASE_DIR, config['INPUT_DIR'] ) | ||
print( "removing dir '{}'".format( path ) ) | ||
shutil.rmtree( | ||
path, | ||
ignore_errors=True | ||
) | ||
# os.system('rm -rf "{}"'.format( path )) | ||
|
||
path = Path( BASE_DIR, config['OUTPUT_DIR'] ) | ||
print( "removing dir '{}'".format( path ) ) | ||
shutil.rmtree( | ||
path, | ||
ignore_errors=True | ||
) | ||
# os.system('rm -rf "{}"'.format( path )) | ||
|
||
def rm_docker_env_file( config ): | ||
path = Path( | ||
BASE_DIR / ".env" | ||
) | ||
print( "removing '{}'".format( path ) ) | ||
path.unlink() | ||
|
||
if __name__ == '__main__': | ||
|
||
from argparse import ArgumentParser | ||
|
||
config = load_config() | ||
|
||
parser = ArgumentParser( | ||
description="clean up the repository" | ||
) | ||
parser.add_argument( | ||
"--env-file", | ||
action = "store_true" | ||
) | ||
parser.add_argument( | ||
"--all", | ||
action = "store_true" | ||
) | ||
args = parser.parse_args() | ||
|
||
from stop import stop | ||
|
||
stop( config ) | ||
|
||
rm_dirs( config ) | ||
if args.env_file or args.all: | ||
rm_docker_env_file( config ) |
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,103 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from utils.settings import BASE_DIR, load_config, create_docker_env_file | ||
from utils.functions import exec_in_container, run | ||
|
||
from pathlib import Path | ||
import shlex | ||
import shutil | ||
import pwd | ||
import os | ||
import subprocess | ||
from time import sleep | ||
|
||
BASE_DIR = Path( __file__ ).parent.parent | ||
DEP_DIR = BASE_DIR / "dependencies" | ||
|
||
|
||
SQLDB_WAIT_TIME=20 | ||
|
||
def create_dir(dir): | ||
print( "creating dir '{}'".format( dir ) ) | ||
Path(dir).mkdir( | ||
parents = True, | ||
exist_ok = True | ||
) | ||
|
||
def copy_dir(src, dst): | ||
print( "'{}' -> '{}'".format( src, dst ) ) | ||
if Path(dst).exists(): | ||
shutil.rmtree( | ||
dst | ||
) | ||
shutil.copytree( | ||
src=src, | ||
dst=dst | ||
) | ||
|
||
def create_dirs( config ): | ||
create_dir( | ||
BASE_DIR / config['INPUT_DIR'] | ||
) | ||
create_dir( | ||
BASE_DIR / config['OUTPUT_DIR'] | ||
) | ||
|
||
def install_git_dep( | ||
repo_name, | ||
repo_uri, | ||
repo_hash, | ||
init_script = None | ||
): | ||
if (DEP_DIR / repo_name).exists(): | ||
shutil.rmtree( DEP_DIR / repo_name ) | ||
|
||
subprocess.check_call( | ||
["git", "clone", repo_uri, DEP_DIR / repo_name] | ||
) | ||
subprocess.check_call( | ||
["git", "checkout", repo_hash], | ||
cwd = DEP_DIR / repo_name | ||
) | ||
if init_script is not None: | ||
subprocess.check_call( | ||
shlex.split( init_script ), | ||
cwd = DEP_DIR / repo_name | ||
) | ||
|
||
if __name__ == '__main__': | ||
|
||
from argparse import ArgumentParser | ||
|
||
parser = ArgumentParser( | ||
description="initialize the repository: download git deps, create directories, etc" | ||
) | ||
parser.add_argument( | ||
"--build", | ||
action = "store_true" | ||
) | ||
args = parser.parse_args() | ||
|
||
# orig_config_file -> env_file: | ||
create_docker_env_file() | ||
|
||
# load env_file: | ||
config = load_config() | ||
|
||
## install git dependencies: | ||
''' | ||
install_git_dep( | ||
repo_name = "eoa-publication-model", | ||
repo_uri = "https://github.molgen.mpg.de/EditionOpenAccess/eoa-publication-model.git", | ||
repo_hash = "d76a81feef1ebb708a90376d3f5a7eccb51807b0" | ||
) | ||
''' | ||
|
||
create_dirs( config ) | ||
|
||
# rebuild docker image: | ||
if args.build: | ||
run( | ||
env = config, | ||
build = True, | ||
) |
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,37 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from utils.settings import BASE_DIR, load_config | ||
from utils.functions import run | ||
|
||
import subprocess | ||
import shlex | ||
import os | ||
from time import sleep | ||
|
||
if __name__ == '__main__': | ||
|
||
from argparse import ArgumentParser | ||
|
||
config = load_config() | ||
|
||
parser = ArgumentParser( | ||
description="run the container" | ||
) | ||
parser.add_argument( | ||
"--build", | ||
action = "store_true" | ||
) | ||
parser.add_argument( | ||
"CMD", | ||
nargs="*" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
CMD= \ | ||
(vars(args)['CMD']) | ||
run( | ||
env=config, | ||
build = args.build, | ||
cmd=CMD | ||
) |
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,28 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from utils.settings import BASE_DIR, load_config | ||
|
||
import subprocess | ||
import os | ||
|
||
|
||
def stop( env ): | ||
# run application | ||
subprocess.call( | ||
"docker-compose down", | ||
shell=True, | ||
env=env | ||
) | ||
|
||
if __name__ == '__main__': | ||
|
||
from argparse import ArgumentParser | ||
|
||
config = load_config() | ||
|
||
parser = ArgumentParser( | ||
description="stop the webserver" | ||
) | ||
args = parser.parse_args() | ||
|
||
stop( config ) |
Oops, something went wrong.