From ed23bbc041ac5c3eb5c00722ae81a349ea474fff Mon Sep 17 00:00:00 2001 From: EsGeh Date: Mon, 25 Nov 2019 19:36:47 +0100 Subject: [PATCH 1/3] fix problems with user rights in "home directory" --- .gitignore | 4 +--- .init-container.sh | 5 +---- Dockerfile | 11 ++--------- docker-compose.yaml | 5 ++++- scripts/config/env.conf | 13 ++++++++----- scripts/init.py | 17 ++++++++++++++++- 6 files changed, 32 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index a1b4284..21eb53f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ -/input/ -/output/ +/runtime/ /dependencies/ -examples # Byte-compiled / optimized / DLL files __pycache__/ diff --git a/.init-container.sh b/.init-container.sh index 005716d..acff572 100755 --- a/.init-container.sh +++ b/.init-container.sh @@ -1,10 +1,7 @@ #!/bin/bash -echo 'export PATH="$EOA_SCRIPTS_DIR:$PATH"' >> ~/.bashrc - -ln -s $INPUT_DIR input -ln -s $OUTPUT_DIR output +echo 'export PATH="$EOA_SCRIPTS_DIR:$PATH"' > ./.bashrc # wait, keep container running: bash -c 'while :; do :; done & kill -STOP $! && wait $!' diff --git a/Dockerfile b/Dockerfile index fef6597..a070e1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -104,12 +104,5 @@ RUN echo '#!/bin/bash' > $UTILS_BIN_DIR/saxon RUN echo 'java -jar $UTILS_BIN_DIR/saxon9he.jar "$@"' >> $UTILS_BIN_DIR/saxon RUN chmod ugo+x $UTILS_BIN_DIR/saxon -# create a HOME and reasonable environment settings for the user: -ENV HOME /home/user -RUN useradd --create-home user -WORKDIR ${HOME} - -COPY ".init-container.sh" "$HOME/init_container.sh" -RUN chmod ugo+x "$HOME/init_container.sh" - -USER user +COPY ".init-container.sh" "$UTILS_BIN_DIR/init_container.sh" +RUN chmod ugo+x "$UTILS_BIN_DIR/init_container.sh" diff --git a/docker-compose.yaml b/docker-compose.yaml index 3ebf31f..5d9b0a8 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,16 +6,19 @@ services: build: . image: ${IMAGE_NAME} container_name: ${CONTAINER_NAME} - command: "/home/user/init_container.sh" + command: "/eoa/bin/init_container.sh" volumes: - ./${SRC_DIR}:${SRC_DIR_IN_CONTAINER} + - ./${HOME_DIR}:${HOME_DIR_IN_CONTAINER} - ./${INPUT_DIR}:${INPUT_DIR_IN_CONTAINER} - ./${OUTPUT_DIR}:${OUTPUT_DIR_IN_CONTAINER} environment: + - HOME=${HOME_DIR_IN_CONTAINER} - INPUT_DIR=${INPUT_DIR_IN_CONTAINER} - OUTPUT_DIR=${OUTPUT_DIR_IN_CONTAINER} - DEPENDENCIES_DIR=${DEPENDENCIES_DIR_IN_CONTAINER} - EOA_SCRIPTS_DIR=${SRC_DIR_IN_CONTAINER} ports: [] user: ${USER}:${GROUP} + working_dir: ${HOME_DIR_IN_CONTAINER} tty: true diff --git a/scripts/config/env.conf b/scripts/config/env.conf index a31514c..b9bcfe0 100644 --- a/scripts/config/env.conf +++ b/scripts/config/env.conf @@ -15,15 +15,18 @@ CONTAINER_NAME=eoa_skripts SRC_DIR=src SRC_DIR_IN_CONTAINER=/eoa/skripts -INPUT_DIR=input +DEPENDENCIES_DIR=dependencies +DEPENDENCIES_DIR_IN_CONTAINER=/eoa/dependencies + +HOME_DIR=runtime/work_dir +HOME_DIR_IN_CONTAINER=/home/work_dir + +INPUT_DIR=runtime/input INPUT_DIR_IN_CONTAINER=/eoa/input -OUTPUT_DIR=output +OUTPUT_DIR=runtime/output OUTPUT_DIR_IN_CONTAINER=/eoa/output -DEPENDENCIES_DIR=dependencies -DEPENDENCIES_DIR_IN_CONTAINER=/eoa/dependencies - ################################################### # user and group: # USER=$(id -u) diff --git a/scripts/init.py b/scripts/init.py index 6d15b1f..d20d282 100755 --- a/scripts/init.py +++ b/scripts/init.py @@ -37,12 +37,27 @@ def create_dirs( config ): create_dir( BASE_DIR / config['DEPENDENCIES_DIR'] ) + create_dir( + BASE_DIR / config['HOME_DIR'] + ) create_dir( BASE_DIR / config['INPUT_DIR'] ) create_dir( BASE_DIR / config['OUTPUT_DIR'] ) + in_link = Path(BASE_DIR / config['HOME_DIR'] / 'input' ) + if not(in_link.is_symlink()) and not(in_link.exists()): + in_link . symlink_to( + config['INPUT_DIR_IN_CONTAINER'], + target_is_directory = True, + ) + out_link = Path(BASE_DIR / config['HOME_DIR'] / 'output' ) + if not(out_link.is_symlink()) and not(out_link.exists()): + out_link . symlink_to( + config['OUTPUT_DIR_IN_CONTAINER'], + target_is_directory = True, + ) def install_git_dep( repo_name, @@ -126,7 +141,7 @@ def install_git_dep( env = config, ) - # copy example publication to $INPUT_DIR + # copy example publication to $INPUT_DIR: copy_dir( BASE_DIR / config['DEPENDENCIES_DIR'] / 'eoa-publication-model/examples', BASE_DIR / config['INPUT_DIR'] / 'example' From 59f96e2de535767dd5a42ab5aab5fcbe0b2c273f Mon Sep 17 00:00:00 2001 From: EsGeh Date: Tue, 26 Nov 2019 11:59:19 +0100 Subject: [PATCH 2/3] fixed paths in readme --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d358ea4..493d321 100644 --- a/README.md +++ b/README.md @@ -55,11 +55,11 @@ Docker images are not deleted though. # General Usage Information -The `input` directory is for unprocessed publications as you might have received them from authors or editors. -The `output` directory is for processed publications and intermediate data. +The `runtime/input` directory is for unprocessed publications as you might have received them from authors or editors. +The `runtime/output` directory is for processed publications and intermediate data. When entering the docker container conversion scripts are in your $PATH, and can executed like any other executable. -In your `HOME` directory you'll find `input` and `output` directories, which are docker volumes mirroring the directories of the same name outside of the container. -In order to compile a publication, just copy them into `./input`, enter the docker container, and call the necessary scripts. +In your `HOME` directory you'll find `input` and `output` directories, which are docker volumes mirroring the directories in `runtime/` outside of the container. +In order to compile a publication, just copy them into `runtime/input`, enter the docker container, and call the necessary scripts. For an example, see chapter "Workflows". ## Configuration @@ -83,8 +83,8 @@ Compiling your documents involves following a workflow which can consist of seve ## The LaTeX workflow (eoatex -> pdf, django, epub) -The following description uses the example publication in `input/example` (from the `eoa-publication-model` repository). -In order to apply the workflow to any other publication copy it into the `input/` directory and adjust paths in the description accordingly. +The following description uses the example publication in `runtime/input/example` (copied from the `eoa-publication-model` repository). +In order to apply the workflow to any other publication copy it into the `runtime/input/` directory and adjust paths in the description accordingly. 1. enter the docker container From 09b509a659d786a367176793216c4dd5d16c1f46 Mon Sep 17 00:00:00 2001 From: EsGeh Date: Tue, 26 Nov 2019 12:04:41 +0100 Subject: [PATCH 3/3] tweak init and exit scripts --- scripts/config/{env.conf => env_default.conf} | 8 ++- scripts/exit.py | 57 ++++++++++++------- scripts/init.py | 13 ++++- scripts/utils/settings.py | 2 +- 4 files changed, 53 insertions(+), 27 deletions(-) rename scripts/config/{env.conf => env_default.conf} (84%) diff --git a/scripts/config/env.conf b/scripts/config/env_default.conf similarity index 84% rename from scripts/config/env.conf rename to scripts/config/env_default.conf index b9bcfe0..c3d36a8 100644 --- a/scripts/config/env.conf +++ b/scripts/config/env_default.conf @@ -18,13 +18,15 @@ SRC_DIR_IN_CONTAINER=/eoa/skripts DEPENDENCIES_DIR=dependencies DEPENDENCIES_DIR_IN_CONTAINER=/eoa/dependencies -HOME_DIR=runtime/work_dir +RUNTIME_DIR=runtime + +HOME_DIR=${RUNTIME_DIR}/work_dir HOME_DIR_IN_CONTAINER=/home/work_dir -INPUT_DIR=runtime/input +INPUT_DIR=${RUNTIME_DIR}/input INPUT_DIR_IN_CONTAINER=/eoa/input -OUTPUT_DIR=runtime/output +OUTPUT_DIR=${RUNTIME_DIR}/output OUTPUT_DIR_IN_CONTAINER=/eoa/output ################################################### diff --git a/scripts/exit.py b/scripts/exit.py index 26e25ec..9cc8d77 100755 --- a/scripts/exit.py +++ b/scripts/exit.py @@ -1,46 +1,57 @@ #!/usr/bin/env python3 -from utils.settings import BASE_DIR, load_config +from utils.settings import env_file, BASE_DIR, load_config, create_docker_env_file from pathlib import Path import shutil import os -def rm_dirs( config, rm_deps): - path = Path( BASE_DIR, config['DEPENDENCIES_DIR'] ) +def rm_dir( + path +): print( "removing dir '{}'".format( path ) ) shutil.rmtree( path, ignore_errors=True ) -def rm_docker_env_file( config ): - path = Path( - BASE_DIR / ".env" - ) - print( "removing '{}'".format( path ) ) - path.unlink() +def rm_file( + path +): + if path.is_file(): + print( "removing file '{}'".format( path ) ) + path.unlink() if __name__ == '__main__': from argparse import ArgumentParser + if not env_file.exists(): + create_docker_env_file() config = load_config() parser = ArgumentParser( description="clean up the repository" ) parser.add_argument( - "--rm-deps", - action = "store_true" + "-d", "--deps", + action = "store_true", + help = "remove dependencies", + ) + parser.add_argument( + "-r", "--runtime", + action = "store_true", + help = "remove '{rt_dir}'".format( rt_dir = BASE_DIR / config['RUNTIME_DIR'] ), ) parser.add_argument( - "--env-file", - action = "store_true" + "-e", "--env", + action = "store_true", + help = "remove existing .env file", ) parser.add_argument( "--all", - action = "store_true" + action = "store_true", + help = "purge in every way", ) args = parser.parse_args() @@ -48,9 +59,15 @@ def rm_docker_env_file( config ): stop( config ) - rm_dirs( - config, - rm_deps = args.rm_deps or args.all - ) - if args.env_file or args.all: - rm_docker_env_file( config ) + if args.deps or args.all: + rm_dir( + path = BASE_DIR / config['DEPENDENCIES_DIR'] + ) + if args.runtime or args.all: + rm_dir( + path = BASE_DIR / config['RUNTIME_DIR'] + ) + if args.env or args.all: + rm_file( + env_file + ) diff --git a/scripts/init.py b/scripts/init.py index d20d282..db60ef7 100755 --- a/scripts/init.py +++ b/scripts/init.py @@ -94,12 +94,19 @@ def install_git_dep( description="initialize the repository: download git deps, create directories, etc" ) parser.add_argument( - "--force-deps", - action = "store_true" + "-d", "--force-deps", + action = "store_true", + help = "download dependencies, even if yet existing", ) parser.add_argument( "--build", - action = "store_true" + action = "store_true", + help = "rebuild docker image from Dockerfile", + ) + parser.add_argument( + "-e", "--env", + action = "store_true", + help = "overwrite existing .env file", ) args = parser.parse_args() diff --git a/scripts/utils/settings.py b/scripts/utils/settings.py index 23409cb..9eeaa4d 100644 --- a/scripts/utils/settings.py +++ b/scripts/utils/settings.py @@ -8,7 +8,7 @@ BASE_DIR = Path( __file__ ).parent.parent.parent SCRIPT_DIR = Path( __file__ ).parent.parent -orig_config_file = SCRIPT_DIR / "config" / "env.conf" +orig_config_file = SCRIPT_DIR / "config" / "env_default.conf" env_file = BASE_DIR / ".env"