Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
(!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
Show file tree
Hide file tree
Showing 172 changed files with 519 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,4 +1,5 @@
output
/input/
/output/
examples

# Byte-compiled / optimized / DLL files
Expand Down
24 changes: 24 additions & 0 deletions Dockerfile
@@ -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
20 changes: 20 additions & 0 deletions docker-compose.yaml
@@ -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}
25 changes: 25 additions & 0 deletions scripts/config/env.conf
@@ -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)
26 changes: 26 additions & 0 deletions scripts/config/load_env.fish
@@ -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
25 changes: 25 additions & 0 deletions scripts/config/load_env.sh
@@ -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)
32 changes: 32 additions & 0 deletions scripts/exec_in_container.py
@@ -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
)
58 changes: 58 additions & 0 deletions scripts/exit.py
@@ -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 )
103 changes: 103 additions & 0 deletions scripts/init.py
@@ -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,
)
37 changes: 37 additions & 0 deletions scripts/run.py
@@ -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
)
28 changes: 28 additions & 0 deletions scripts/stop.py
@@ -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 )

0 comments on commit a6b0d41

Please sign in to comment.