Skip to content

Commit 18e9954

Browse files
author
Omar Ahmad
committed
Using RQ to change toml and yaml to JSON, removing all python stuff
1 parent b9bbeac commit 18e9954

File tree

4 files changed

+57
-5
lines changed

4 files changed

+57
-5
lines changed

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
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 py3-toml py3-yaml python3 jq tini \
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

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

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ services:
1212
volumes:
1313
- "/var/run/docker.sock:/var/run/docker.sock:ro"
1414
# - "/usr/bin/docker:/usr/bin/docker:ro"
15-
- "/Users/willfarrell/Development/docker/docker-crontab/config.json:/opt/crontab/config.json:rw"
15+
- "${PWD}/config.json:/opt/crontab/config.json:rw"

docker-entrypoint

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ fi
1717

1818
get_config() {
1919
if [ -f "${HOME_DIR}/config.toml" ]; then
20-
python3 -c "with open('${HOME_DIR}/config.toml') as ct, open('${HOME_DIR}/config.json', 'w') as cj: import toml; import json; json.dump(list(toml.load(ct).values()), cj)"
20+
rq -t <<< $(cat ${HOME_DIR}/config.toml) | jq 'map(.)' > ${HOME_DIR}/config.json
2121
elif [ -f "${HOME_DIR}/config.yml" ]; then
22-
python3 -c "with open('${HOME_DIR}/config.yml') as cy, open('${HOME_DIR}/config.json', 'w') as cj: import yaml; import json; json.dump(list(yaml.safe_load(cy).values()), cj)"
22+
rq -y <<< $(cat ${HOME_DIR}/config.yml) | jq 'map(.)' > ${HOME_DIR}/config.json
2323
elif [ -f "${HOME_DIR}/config.yaml" ]; then
24-
python3 -c "with open('${HOME_DIR}/config.yaml') as cy, open('${HOME_DIR}/config.json', 'w') as cj: import yaml; import json; json.dump(list(yaml.safe_load(cy).values()), cj)"
24+
rq -y <<< $(cat ${HOME_DIR}/config.yaml) | jq 'map(.)' > ${HOME_DIR}/config.json
2525
fi
2626
}
2727

0 commit comments

Comments
 (0)