Skip to content

Commit c2331fc

Browse files
authored
Merge pull request #40 from chiqomar/master
Adding python conversion for TOML and YAML
2 parents d9b4cec + 88bed2b commit c2331fc

File tree

11 files changed

+316
-61
lines changed

11 files changed

+316
-61
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.iml
33

44
config.json
5+
.vscode
6+
.DS_Store

Dockerfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
FROM alpine:3.12 as rq-build
2+
3+
ENV RQ_VERSION=1.0.2
4+
WORKDIR /root/
5+
6+
RUN apk --update add upx \
7+
&& wget https://github.com/dflemstr/rq/releases/download/v${RQ_VERSION}/rq-v${RQ_VERSION}-x86_64-unknown-linux-musl.tar.gz \
8+
&& tar -xvf rq-v1.0.2-x86_64-unknown-linux-musl.tar.gz \
9+
&& upx --brute rq
10+
111
FROM library/docker:stable
212

13+
COPY --from=rq-build /root/rq /usr/local/bin
14+
315
ENV HOME_DIR=/opt/crontab
4-
RUN apk add --no-cache --virtual .run-deps gettext bash jq \
16+
RUN apk add --no-cache --virtual .run-deps gettext jq bash tini \
517
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \
618
&& adduser -S docker -D
719

820
COPY docker-entrypoint /
9-
ENTRYPOINT ["/docker-entrypoint"]
21+
ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint"]
1022

1123
HEALTHCHECK --interval=5s --timeout=3s \
1224
CMD ps aux | grep '[c]rond' || exit 1

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

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

config-samples/config.sample.yml

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

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-
- "/Users/willfarrell/Development/docker/docker-crontab/config.json:/opt/crontab/config.json:rw"
14+
- "${PWD}/config-samples/config.sample.mapping.json:/opt/crontab/config.json:rw"

0 commit comments

Comments
 (0)