4 Commits
0.1.0 ... 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
d83f0b3a1b Merge pull request #4 from jamesfielder/master
Fix issue where container name is incorrectly generated when using docker swarm
2017-10-09 11:34:31 -06:00
a160036ba2 Fix issue where container name issue
Fix issue where docker swarm names are incorrectly generated when project option is set.
2017-10-09 11:03:39 +01:00
4 changed files with 18 additions and 15 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
.idea
*.iml
home_dir
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`.
## 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

View File

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

View File

@ -22,6 +22,9 @@ CRONTAB_FILE=/etc/crontabs/docker
# Ensure dir exist - in case of volume mapping
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() {
DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
@ -49,7 +52,7 @@ cat << EOF > ${HOME_DIR}/projects/${SCRIPT_NAME}.sh
#!/usr/bin/env bash
set -e
CONTAINERS=\$(docker ps --format '{{.Names}}' | grep -E "^${PROJECT}_${CONTAINER}_[0-9]+")
CONTAINERS=\$(docker ps --format '{{.Names}}' | grep -E "^${PROJECT}_${CONTAINER}.[0-9]+")
for CONTAINER_NAME in \$CONTAINERS; do
docker exec ${DOCKERARGS} \${CONTAINER_NAME} ${TMP_COMMAND}
done
@ -81,25 +84,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 +122,7 @@ parse_schedule() {
TOTAL=$(($TOTAL + ${D::-1} * 60 * 24))
fi
echo "*/${TOTAL} * * * * *"
echo "*/${TOTAL} * * * *"
;;
*)
echo "${@}"
@ -151,6 +154,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
@ -213,4 +217,4 @@ if [ "$1" = "crond" ]; then
fi
echo "$@"
exec "$@"
exec "$@"