11 Commits
0.1.0 ... 0.4.0

Author SHA1 Message Date
02a89f6dac fix: clean up logic and only apply group if needed 2018-06-30 15:23:27 -06:00
b89e312569 fix: Change group id
Change group id to not conflict with host common id

Fix #13
2018-02-27 23:44:47 -07:00
f601ca262d Merge pull request #11 from kendokan/master
fixed failure if docker group already existed
2018-01-11 09:15:18 -07:00
b52842b07a fixed failure if docker group already existed
This error prevents the container from restarting.
2018-01-11 08:13:11 -08:00
147e900f8b Merge pull request #10 from kendokan/master
fixed https://github.com/willfarrell/docker-crontab/issues/9
2018-01-09 20:16:50 -07:00
40b8b93c2a fixed https://github.com/willfarrell/docker-crontab/issues/9 2018-01-09 13:17:49 -08:00
d5cfe3bc76 #6 Added adduser to the build script 2017-11-14 14:04:30 -07:00
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
6 changed files with 34 additions and 17 deletions

1
.gitignore vendored
View File

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

View File

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

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,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)
@ -49,7 +63,7 @@ cat << EOF > ${HOME_DIR}/projects/${SCRIPT_NAME}.sh
#!/usr/bin/env bash #!/usr/bin/env bash
set -e 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 for CONTAINER_NAME in \$CONTAINERS; do
docker exec ${DOCKERARGS} \${CONTAINER_NAME} ${TMP_COMMAND} docker exec ${DOCKERARGS} \${CONTAINER_NAME} ${TMP_COMMAND}
done done
@ -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

View File

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