mirror of
https://github.com/willfarrell/docker-crontab.git
synced 2025-06-25 13:23:55 +02:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
f601ca262d | |||
b52842b07a | |||
147e900f8b | |||
40b8b93c2a | |||
d5cfe3bc76 | |||
d5f4764d25 | |||
61ef1db4bf |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,5 +1,4 @@
|
||||
.idea
|
||||
*.iml
|
||||
|
||||
home_dir
|
||||
config.json
|
||||
|
@ -2,7 +2,8 @@ FROM library/docker:stable
|
||||
|
||||
ENV HOME_DIR=/opt/crontab
|
||||
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 /
|
||||
ENTRYPOINT ["/docker-entrypoint"]
|
||||
@ -10,4 +11,4 @@ ENTRYPOINT ["/docker-entrypoint"]
|
||||
HEALTHCHECK --interval=5s --timeout=3s \
|
||||
CMD ps aux | grep '[c]rond' || exit 1
|
||||
|
||||
CMD ["crond","-f"]
|
||||
CMD ["crond","-f"]
|
||||
|
@ -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`.
|
||||
|
||||
## 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.
|
||||
- `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.
|
||||
- `image`: Docker images name (ex `library/alpine:3.5`). Optional.
|
||||
- `project`: Docker Compose/Swarm project name. Optional, only applies when `contain` is included.
|
||||
@ -98,4 +98,4 @@ grok: `CRONTABLOG %{DATA:request_id} %{TIMESTAMP_ISO8601:timestamp} \[%{LOGLEVEL
|
||||
- [ ] Have ability to auto regenerate crontab on file change (signal HUP?)
|
||||
- [ ] Run commands on host machine (w/ --privileged?)
|
||||
- [ ] Write tests
|
||||
- [ ] Setup TravisCI
|
||||
- [ ] Setup TravisCI
|
||||
|
@ -12,4 +12,4 @@ services:
|
||||
volumes:
|
||||
- "/var/run/docker.sock:/var/run/docker.sock: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,16 @@ CRONTAB_FILE=/etc/crontabs/docker
|
||||
# Ensure dir exist - in case of volume mapping
|
||||
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})
|
||||
addgroup -g ${DOCKER_GID} docker
|
||||
adduser docker docker
|
||||
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() {
|
||||
DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
|
||||
@ -81,25 +91,25 @@ make_cmd() {
|
||||
parse_schedule() {
|
||||
case $1 in
|
||||
"@yearly")
|
||||
echo "0 0 0 1 1 *"
|
||||
echo "0 0 1 1 *"
|
||||
;;
|
||||
"@annually")
|
||||
echo "0 0 0 1 1 *"
|
||||
echo "0 0 1 1 *"
|
||||
;;
|
||||
"@monthly")
|
||||
echo "0 0 0 1 * *"
|
||||
echo "0 0 1 * *"
|
||||
;;
|
||||
"@weekly")
|
||||
echo "0 0 0 * * 0"
|
||||
echo "0 0 * * 0"
|
||||
;;
|
||||
"@daily")
|
||||
echo "0 0 0 * * *"
|
||||
echo "0 0 * * *"
|
||||
;;
|
||||
"@midnight")
|
||||
echo "0 0 0 * * *"
|
||||
echo "0 0 * * *"
|
||||
;;
|
||||
"@hourly")
|
||||
echo "0 0 * * * *"
|
||||
echo "0 * * * *"
|
||||
;;
|
||||
"@every")
|
||||
TIME=$2
|
||||
@ -119,7 +129,7 @@ parse_schedule() {
|
||||
TOTAL=$(($TOTAL + ${D::-1} * 60 * 24))
|
||||
fi
|
||||
|
||||
echo "*/${TOTAL} * * * * *"
|
||||
echo "*/${TOTAL} * * * *"
|
||||
;;
|
||||
*)
|
||||
echo "${@}"
|
||||
@ -151,6 +161,7 @@ function build_crontab() {
|
||||
fi
|
||||
|
||||
SCRIPT_NAME=$(jq -r .[$i].name ${CONFIG})
|
||||
SCRIPT_NAME=$(slugify $SCRIPT_NAME)
|
||||
if [ "${SCRIPT_NAME}" == "null" ]; then
|
||||
SCRIPT_NAME=$(cat /proc/sys/kernel/random/uuid)
|
||||
fi
|
||||
|
@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# This file is for testing the logging of docker output #8
|
||||
|
||||
LOG_FILE=./jobs.log
|
||||
touch ${LOG_FILE}
|
||||
UUID="xxxxxxxxxxxxxxxxx"
|
Reference in New Issue
Block a user