2 Commits
0.1.1 ... 0.2.0

Author SHA1 Message Date
d5f4764d25 Fix #7
slugifys name
2017-11-14 13:54:20 -07:00
61ef1db4bf Change documentation showing seconds in cron schedule in error 2017-10-23 09:45:24 -06:00
4 changed files with 16 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
.idea .idea
*.iml *.iml
home_dir
config.json config.json

View File

@ -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.

View File

@ -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"

View File

@ -22,6 +22,9 @@ 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
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 +84,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 +122,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 +154,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