Skip to content

Commit 0ef54cc

Browse files
author
Omar Ahmad
committed
Updating README, adding JSON mapping support for consistency
1 parent 18e9954 commit 0ef54cc

9 files changed

+178
-52
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ A great project, don't get me wrong. It was just missing certain key enterprise
2121
- Run command on a instances of a scaled container using `project`.
2222
- Ability to trigger scripts in other containers on completion cron job using `trigger`.
2323

24-
## Config.json
24+
## Config file
25+
26+
The config file can be specifed in any of `json`, `toml`, or `yaml`, and can be defined as either an array or mapping (top-level keys will be ignored; can be useful for organizing commands)
27+
2528
- `name`: Human readable name that will be used as the job filename. Will be converted into a slug. Optional.
2629
- `comment`: Comments to be included with crontab entry. Optional.
2730
- `schedule`: Crontab schedule syntax as described in https://en.wikipedia.org/wiki/Cron. Ex `@hourly`, `@every 1h30m`, `* * * * *`. Required.
@@ -33,7 +36,7 @@ A great project, don't get me wrong. It was just missing certain key enterprise
3336
- `trigger`: Array of docker-crontab subset objects. Subset includes: `image`,`project`,`container`,`command`,`dockerargs`
3437
- `onstart`: Run the command on `crontab` container start, set to `true`. Optional, defaults to falsey.
3538

36-
See [`config.sample.json`](https://github.com/willfarrell/docker-crontab/blob/master/config.sample.json) for examples.
39+
See [`config-samples`](config-samples) for examples.
3740

3841
```json
3942
[{

config-samples/config.sample.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[
2+
{
3+
"comment": "cron with triggered commands",
4+
"schedule": "* * * * *",
5+
"command": "echo hello",
6+
"project": "crontab",
7+
"container": "myapp",
8+
"trigger": [
9+
{
10+
"command": "echo world",
11+
"container": "crontab_myapp_1"
12+
}
13+
]
14+
},
15+
{
16+
"comment": "map a volume",
17+
"schedule": "* * * * *",
18+
"dockerargs": "-d -v /tmp:/tmp",
19+
"command": "echo new",
20+
"image": "alpine:3.5"
21+
},
22+
{
23+
"comment": "use an ENV from inside a container",
24+
"schedule": "@hourly",
25+
"dockerargs": "-d -e FOO=BAR",
26+
"command": "sh -c 'echo hourly ${FOO}'",
27+
"image": "alpine:3.5"
28+
},
29+
{
30+
"comment": "trigger every 2 min",
31+
"schedule": "@every 2m",
32+
"command": "echo 2 minute",
33+
"image": "alpine:3.5",
34+
"trigger": [
35+
{
36+
"command": "echo world",
37+
"container": "crontab_myapp_1"
38+
}
39+
]
40+
},
41+
{
42+
"schedule": "*/5 * * * *",
43+
"command": "/usr/sbin/logrotate /etc/logrotate.conf"
44+
},
45+
{
46+
"comment": "Regenerate Certificate then reload nginx",
47+
"schedule": "43 6,18 * * *",
48+
"command": "sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'",
49+
"dockerargs": "--env-file /opt/crontab/env/letsencrypt.env -v webapp_nginx_tls_cert:/etc/ssl -v webapp_nginx_acme_challenge:/var/www/.well-known/acme-challenge",
50+
"image": "willfarrell/letsencrypt",
51+
"trigger": [
52+
{
53+
"command": "sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && /usr/sbin/nginx -s reload'",
54+
"project": "conduit",
55+
"container": "nginx"
56+
}
57+
],
58+
"onstart": true
59+
}
60+
]
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[
2+
{
3+
"comment": "cron with triggered commands",
4+
"schedule": "* * * * *",
5+
"command": "echo hello",
6+
"project": "crontab",
7+
"container": "myapp",
8+
"trigger": [
9+
{
10+
"command": "echo world",
11+
"container": "crontab_myapp_1"
12+
}
13+
]
14+
},
15+
{
16+
"comment": "map a volume",
17+
"schedule": "* * * * *",
18+
"dockerargs": "-d -v /tmp:/tmp",
19+
"command": "echo new",
20+
"image": "alpine:3.5"
21+
},
22+
{
23+
"comment": "use an ENV from inside a container",
24+
"schedule": "@hourly",
25+
"dockerargs": "-d -e FOO=BAR",
26+
"command": "sh -c 'echo hourly ${FOO}'",
27+
"image": "alpine:3.5"
28+
},
29+
{
30+
"comment": "trigger every 2 min",
31+
"schedule": "@every 2m",
32+
"command": "echo 2 minute",
33+
"image": "alpine:3.5",
34+
"trigger": [
35+
{
36+
"command": "echo world",
37+
"container": "crontab_myapp_1"
38+
}
39+
]
40+
},
41+
{
42+
"schedule": "*/5 * * * *",
43+
"command": "/usr/sbin/logrotate /etc/logrotate.conf"
44+
},
45+
{
46+
"comment": "Regenerate Certificate then reload nginx",
47+
"schedule": "43 6,18 * * *",
48+
"command": "sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'",
49+
"dockerargs": "--env-file /opt/crontab/env/letsencrypt.env -v webapp_nginx_tls_cert:/etc/ssl -v webapp_nginx_acme_challenge:/var/www/.well-known/acme-challenge",
50+
"image": "willfarrell/letsencrypt",
51+
"trigger": [
52+
{
53+
"command": "sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && /usr/sbin/nginx -s reload'",
54+
"project": "conduit",
55+
"container": "nginx"
56+
}
57+
],
58+
"onstart": true
59+
}
60+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cron with triggered commands:
2+
command: echo hello
3+
comment: cron with triggered commands
4+
container: myapp
5+
project: crontab
6+
schedule: '* * * * *'
7+
trigger:
8+
- command: echo world
9+
container: crontab_myapp_1
10+
map a volume:
11+
command: echo new
12+
comment: map a volume
13+
dockerargs: -d -v /tmp:/tmp
14+
image: alpine:3.5
15+
schedule: '* * * * *'
16+
use an ENV from inside a container:
17+
command: sh -c 'echo hourly ${FOO}'
18+
comment: use an ENV from inside a container
19+
dockerargs: -d -e FOO=BAR
20+
image: alpine:3.5
21+
schedule: '@hourly'
22+
trigger every 2 min:
23+
command: echo 2 minute
24+
comment: trigger every 2 min
25+
image: alpine:3.5
26+
schedule: '@every 2m'
27+
trigger:
28+
- command: echo world
29+
container: crontab_myapp_1
30+
null:
31+
command: /usr/sbin/logrotate /etc/logrotate.conf
32+
schedule: '*/5 * * * *'
33+
Regenerate Certificate then reload nginx:
34+
command: sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge
35+
dns-01 --hook dehydrated-dns'
36+
comment: Regenerate Certificate then reload nginx
37+
dockerargs: --env-file /opt/crontab/env/letsencrypt.env -v webapp_nginx_tls_cert:/etc/ssl
38+
-v webapp_nginx_acme_challenge:/var/www/.well-known/acme-challenge
39+
image: willfarrell/letsencrypt
40+
onstart: true
41+
schedule: 43 6,18 * * *
42+
trigger:
43+
- command: sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t &&
44+
/usr/sbin/nginx -s reload'
45+
container: nginx
46+
project: conduit

config.toml renamed to config-samples/config.sample.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# toml files can only have top-loevl mappings, so this is the only sample
12
["cron with triggered commands"]
23
comment = "cron with triggered commands"
34
schedule = "* * * * *"
File renamed without changes.

config.sample.json

Lines changed: 0 additions & 47 deletions
This file was deleted.

docker-compose.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ services:
1111
restart: always
1212
volumes:
1313
- "/var/run/docker.sock:/var/run/docker.sock:ro"
14-
# - "/usr/bin/docker:/usr/bin/docker:ro"
15-
- "${PWD}/config.json:/opt/crontab/config.json:rw"
14+
- "${PWD}/config-samples/config.sample.mapping.json:/opt/crontab/config.json:rw"

docker-entrypoint

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ if [ "${LOG_FILE}" == "" ]; then
1616
fi
1717

1818
get_config() {
19-
if [ -f "${HOME_DIR}/config.toml" ]; then
19+
if [ -f "${HOME_DIR}/config.json" ]; then
20+
cp ${HOME_DIR}/config.json ${HOME_DIR}/config.json.old
21+
jq 'map(.)' ${HOME_DIR}/config.json.old > ${HOME_DIR}/config.json
22+
rm ${HOME_DIR}/config.json.old
23+
elif [ -f "${HOME_DIR}/config.toml" ]; then
2024
rq -t <<< $(cat ${HOME_DIR}/config.toml) | jq 'map(.)' > ${HOME_DIR}/config.json
2125
elif [ -f "${HOME_DIR}/config.yml" ]; then
2226
rq -y <<< $(cat ${HOME_DIR}/config.yml) | jq 'map(.)' > ${HOME_DIR}/config.json

0 commit comments

Comments
 (0)