From 4f9146b8f8fe22923beac43ad8be51b46a6febd5 Mon Sep 17 00:00:00 2001 From: Omar Ahmad Date: Tue, 3 Sep 2019 13:15:31 -0400 Subject: [PATCH] using tini, functions for most code in entrypoint --- Dockerfile | 4 ++-- docker-entrypoint | 48 ++++++++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1ca978c..a16b7cf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ FROM library/docker:stable ENV HOME_DIR=/opt/crontab -RUN apk add --no-cache --virtual .run-deps gettext bash py3-toml py3-yaml python3 jq \ +RUN apk add --no-cache --virtual .run-deps gettext bash py3-toml py3-yaml python3 jq tini \ && mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \ && adduser -S docker -D COPY docker-entrypoint / -ENTRYPOINT ["/docker-entrypoint"] +ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint"] HEALTHCHECK --interval=5s --timeout=3s \ CMD ps aux | grep '[c]rond' || exit 1 diff --git a/docker-entrypoint b/docker-entrypoint index 2ce5c01..bb4a752 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -15,20 +15,15 @@ if [ "${LOG_FILE}" == "" ]; then touch ${LOG_FILE} fi - -if [ -f "${HOME_DIR}/config.toml" ]; then - python3 -c "with open('${HOME_DIR}/config.toml') as ct, open('${HOME_DIR}/config.json', 'w') as cj: import toml; import json; json.dump(list(toml.load(ct).values()), cj)" -elif [ -f "${HOME_DIR}/config.yml" ]; then - python3 -c "with open('${HOME_DIR}/config.yml') as cy, open('${HOME_DIR}/config.json', 'w') as cj: import yaml; import json; json.dump(list(yaml.safe_load(cy).values()), cj)" -elif [ -f "${HOME_DIR}/config.yaml" ]; then - python3 -c "with open('${HOME_DIR}/config.yaml') as cy, open('${HOME_DIR}/config.json', 'w') as cj: import yaml; import json; json.dump(list(yaml.safe_load(cy).values()), cj)" -fi - -if [ -f "${HOME_DIR}/config.json" ]; then - CONFIG=${HOME_DIR}/config.json -else - echo "NO CONFIG FILE FOUND" -fi +get_config() { + if [ -f "${HOME_DIR}/config.toml" ]; then + python3 -c "with open('${HOME_DIR}/config.toml') as ct, open('${HOME_DIR}/config.json', 'w') as cj: import toml; import json; json.dump(list(toml.load(ct).values()), cj)" + elif [ -f "${HOME_DIR}/config.yml" ]; then + python3 -c "with open('${HOME_DIR}/config.yml') as cy, open('${HOME_DIR}/config.json', 'w') as cj: import yaml; import json; json.dump(list(yaml.safe_load(cy).values()), cj)" + elif [ -f "${HOME_DIR}/config.yaml" ]; then + python3 -c "with open('${HOME_DIR}/config.yaml') as cy, open('${HOME_DIR}/config.json', 'w') as cj: import yaml; import json; json.dump(list(yaml.safe_load(cy).values()), cj)" + fi +} DOCKER_SOCK=/var/run/docker.sock CRONTAB_FILE=/etc/crontabs/docker @@ -183,6 +178,7 @@ parse_schedule() { } function build_crontab() { + rm -rf ${CRONTAB_FILE} ONSTART=() @@ -260,15 +256,25 @@ EOF done } + ensure_docker_socket_accessible -if [ "$1" = "crond" ]; then - if [ -f ${CONFIG} ]; then - build_crontab +start_app() { + get_config + if [ -f "${HOME_DIR}/config.json" ]; then + export CONFIG=${HOME_DIR}/config.json else - echo "Unable to find ${CONFIG}" + echo "NO CONFIG FILE FOUND" fi -fi + if [ "$1" = "crond" ]; then + if [ -f ${CONFIG} ]; then + build_crontab + else + echo "Unable to find ${CONFIG}" + fi + fi + echo "$@" + exec "$@" +} -echo "$@" -exec "$@" +start_app "$@"