mirror of
https://github.com/willfarrell/docker-crontab.git
synced 2025-06-25 21:34:06 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
02a89f6dac | |||
b89e312569 | |||
f601ca262d | |||
b52842b07a | |||
147e900f8b | |||
40b8b93c2a | |||
d5cfe3bc76 | |||
d5f4764d25 | |||
61ef1db4bf |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
home_dir
|
|
||||||
config.json
|
config.json
|
||||||
|
@ -2,7 +2,8 @@ FROM library/docker:stable
|
|||||||
|
|
||||||
ENV HOME_DIR=/opt/crontab
|
ENV HOME_DIR=/opt/crontab
|
||||||
RUN apk add --no-cache --virtual .run-deps bash jq \
|
RUN apk add --no-cache --virtual .run-deps bash jq \
|
||||||
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects
|
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \
|
||||||
|
&& adduser -S docker -D
|
||||||
|
|
||||||
COPY docker-entrypoint /
|
COPY docker-entrypoint /
|
||||||
ENTRYPOINT ["/docker-entrypoint"]
|
ENTRYPOINT ["/docker-entrypoint"]
|
||||||
|
@ -22,9 +22,9 @@ A great project, don't get me wrong. It was just missing certain key enterprise
|
|||||||
- Ability to trigger scripts in other containers on completion cron job using `trigger`.
|
- Ability to trigger scripts in other containers on completion cron job using `trigger`.
|
||||||
|
|
||||||
## Config.json
|
## Config.json
|
||||||
- `name`: Human readable name that will be used as teh job filename. Optional.
|
- `name`: Human readable name that will be used as the job filename. Will be converted into a slug. Optional.
|
||||||
- `comment`: Comments to be included with crontab entry. Optional.
|
- `comment`: Comments to be included with crontab entry. Optional.
|
||||||
- `schedule`: Crontab schedule syntax as described in https://godoc.org/github.com/robfig/cron. Ex `@hourly`, `@every 1h30m`, `* * * * * *`. Required.
|
- `schedule`: Crontab schedule syntax as described in https://en.wikipedia.org/wiki/Cron. Ex `@hourly`, `@every 1h30m`, `* * * * *`. Required.
|
||||||
- `command`: Command to be run on in crontab container or docker container/image. Required.
|
- `command`: Command to be run on in crontab container or docker container/image. Required.
|
||||||
- `image`: Docker images name (ex `library/alpine:3.5`). Optional.
|
- `image`: Docker images name (ex `library/alpine:3.5`). Optional.
|
||||||
- `project`: Docker Compose/Swarm project name. Optional, only applies when `contain` is included.
|
- `project`: Docker Compose/Swarm project name. Optional, only applies when `contain` is included.
|
||||||
|
@ -12,4 +12,4 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
- "/var/run/docker.sock:/var/run/docker.sock:ro"
|
||||||
# - "/usr/bin/docker:/usr/bin/docker:ro"
|
# - "/usr/bin/docker:/usr/bin/docker:ro"
|
||||||
- "/Users/willfarrell/Development/docker/docker-crontab/home_dir:/opt/crontab:rw"
|
- "/Users/willfarrell/Development/docker/docker-crontab/config.json:/opt/crontab/config.json:rw"
|
||||||
|
@ -22,6 +22,20 @@ CRONTAB_FILE=/etc/crontabs/docker
|
|||||||
# Ensure dir exist - in case of volume mapping
|
# Ensure dir exist - in case of volume mapping
|
||||||
mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects
|
mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects
|
||||||
|
|
||||||
|
# Create docker group using correct gid from host, and add docker user to it
|
||||||
|
if ! grep -q "^docker:" /etc/group; then
|
||||||
|
DOCKER_GID=$(stat -c '%g' ${DOCKER_SOCK})
|
||||||
|
if [ "${DOCKER_GID}" != "0" ]; then
|
||||||
|
addgroup -g ${DOCKER_GID} docker
|
||||||
|
adduser docker docker
|
||||||
|
else
|
||||||
|
adduser docker root
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
slugify() {
|
||||||
|
echo "$@" | iconv -t ascii | sed -r s/[~\^]+//g | sed -r s/[^a-zA-Z0-9]+/-/g | sed -r s/^-+\|-+$//g | tr A-Z a-z
|
||||||
|
}
|
||||||
|
|
||||||
make_image_cmd() {
|
make_image_cmd() {
|
||||||
DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
|
DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
|
||||||
@ -81,25 +95,25 @@ make_cmd() {
|
|||||||
parse_schedule() {
|
parse_schedule() {
|
||||||
case $1 in
|
case $1 in
|
||||||
"@yearly")
|
"@yearly")
|
||||||
echo "0 0 0 1 1 *"
|
echo "0 0 1 1 *"
|
||||||
;;
|
;;
|
||||||
"@annually")
|
"@annually")
|
||||||
echo "0 0 0 1 1 *"
|
echo "0 0 1 1 *"
|
||||||
;;
|
;;
|
||||||
"@monthly")
|
"@monthly")
|
||||||
echo "0 0 0 1 * *"
|
echo "0 0 1 * *"
|
||||||
;;
|
;;
|
||||||
"@weekly")
|
"@weekly")
|
||||||
echo "0 0 0 * * 0"
|
echo "0 0 * * 0"
|
||||||
;;
|
;;
|
||||||
"@daily")
|
"@daily")
|
||||||
echo "0 0 0 * * *"
|
echo "0 0 * * *"
|
||||||
;;
|
;;
|
||||||
"@midnight")
|
"@midnight")
|
||||||
echo "0 0 0 * * *"
|
echo "0 0 * * *"
|
||||||
;;
|
;;
|
||||||
"@hourly")
|
"@hourly")
|
||||||
echo "0 0 * * * *"
|
echo "0 * * * *"
|
||||||
;;
|
;;
|
||||||
"@every")
|
"@every")
|
||||||
TIME=$2
|
TIME=$2
|
||||||
@ -119,7 +133,7 @@ parse_schedule() {
|
|||||||
TOTAL=$(($TOTAL + ${D::-1} * 60 * 24))
|
TOTAL=$(($TOTAL + ${D::-1} * 60 * 24))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "*/${TOTAL} * * * * *"
|
echo "*/${TOTAL} * * * *"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "${@}"
|
echo "${@}"
|
||||||
@ -151,6 +165,7 @@ function build_crontab() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
SCRIPT_NAME=$(jq -r .[$i].name ${CONFIG})
|
SCRIPT_NAME=$(jq -r .[$i].name ${CONFIG})
|
||||||
|
SCRIPT_NAME=$(slugify $SCRIPT_NAME)
|
||||||
if [ "${SCRIPT_NAME}" == "null" ]; then
|
if [ "${SCRIPT_NAME}" == "null" ]; then
|
||||||
SCRIPT_NAME=$(cat /proc/sys/kernel/random/uuid)
|
SCRIPT_NAME=$(cat /proc/sys/kernel/random/uuid)
|
||||||
fi
|
fi
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
# This file is for testing the logging of docker output #8
|
||||||
|
|
||||||
LOG_FILE=./jobs.log
|
LOG_FILE=./jobs.log
|
||||||
touch ${LOG_FILE}
|
touch ${LOG_FILE}
|
||||||
UUID="xxxxxxxxxxxxxxxxx"
|
UUID="xxxxxxxxxxxxxxxxx"
|
Reference in New Issue
Block a user