mirror of
https://github.com/willfarrell/docker-crontab.git
synced 2025-04-04 14:05:11 +02:00
using tini, functions for most code in entrypoint
This commit is contained in:
parent
4a0d85f51a
commit
4f9146b8f8
@ -1,12 +1,12 @@
|
|||||||
FROM library/docker:stable
|
FROM library/docker:stable
|
||||||
|
|
||||||
ENV HOME_DIR=/opt/crontab
|
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 \
|
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \
|
||||||
&& adduser -S docker -D
|
&& adduser -S docker -D
|
||||||
|
|
||||||
COPY docker-entrypoint /
|
COPY docker-entrypoint /
|
||||||
ENTRYPOINT ["/docker-entrypoint"]
|
ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint"]
|
||||||
|
|
||||||
HEALTHCHECK --interval=5s --timeout=3s \
|
HEALTHCHECK --interval=5s --timeout=3s \
|
||||||
CMD ps aux | grep '[c]rond' || exit 1
|
CMD ps aux | grep '[c]rond' || exit 1
|
||||||
|
@ -15,20 +15,15 @@ if [ "${LOG_FILE}" == "" ]; then
|
|||||||
touch ${LOG_FILE}
|
touch ${LOG_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
get_config() {
|
||||||
if [ -f "${HOME_DIR}/config.toml" ]; then
|
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)"
|
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
|
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)"
|
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
|
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)"
|
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
|
fi
|
||||||
|
}
|
||||||
if [ -f "${HOME_DIR}/config.json" ]; then
|
|
||||||
CONFIG=${HOME_DIR}/config.json
|
|
||||||
else
|
|
||||||
echo "NO CONFIG FILE FOUND"
|
|
||||||
fi
|
|
||||||
|
|
||||||
DOCKER_SOCK=/var/run/docker.sock
|
DOCKER_SOCK=/var/run/docker.sock
|
||||||
CRONTAB_FILE=/etc/crontabs/docker
|
CRONTAB_FILE=/etc/crontabs/docker
|
||||||
@ -183,6 +178,7 @@ parse_schedule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function build_crontab() {
|
function build_crontab() {
|
||||||
|
|
||||||
rm -rf ${CRONTAB_FILE}
|
rm -rf ${CRONTAB_FILE}
|
||||||
|
|
||||||
ONSTART=()
|
ONSTART=()
|
||||||
@ -260,15 +256,25 @@ EOF
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ensure_docker_socket_accessible
|
ensure_docker_socket_accessible
|
||||||
|
|
||||||
if [ "$1" = "crond" ]; then
|
start_app() {
|
||||||
if [ -f ${CONFIG} ]; then
|
get_config
|
||||||
build_crontab
|
if [ -f "${HOME_DIR}/config.json" ]; then
|
||||||
|
export CONFIG=${HOME_DIR}/config.json
|
||||||
else
|
else
|
||||||
echo "Unable to find ${CONFIG}"
|
echo "NO CONFIG FILE FOUND"
|
||||||
fi
|
fi
|
||||||
fi
|
if [ "$1" = "crond" ]; then
|
||||||
|
if [ -f ${CONFIG} ]; then
|
||||||
|
build_crontab
|
||||||
|
else
|
||||||
|
echo "Unable to find ${CONFIG}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "$@"
|
||||||
|
exec "$@"
|
||||||
|
}
|
||||||
|
|
||||||
echo "$@"
|
start_app "$@"
|
||||||
exec "$@"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user