diff --git a/Dockerfile b/Dockerfile index a16b7cf..0685c21 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,19 @@ +FROM alpine:3.12 as rq-build + +ENV RQ_VERSION=1.0.2 +WORKDIR /root/ + +RUN apk --update add upx \ + && wget https://github.com/dflemstr/rq/releases/download/v${RQ_VERSION}/rq-v${RQ_VERSION}-x86_64-unknown-linux-musl.tar.gz \ + && tar -xvf rq-v1.0.2-x86_64-unknown-linux-musl.tar.gz \ + && upx --brute rq + FROM library/docker:stable +COPY --from=rq-build /root/rq /usr/local/bin + ENV HOME_DIR=/opt/crontab -RUN apk add --no-cache --virtual .run-deps gettext bash py3-toml py3-yaml python3 jq tini \ +RUN apk add --no-cache --virtual .run-deps gettext jq bash tini \ && mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \ && adduser -S docker -D diff --git a/config.yml b/config.yml index e69de29..7016114 100644 --- a/config.yml +++ b/config.yml @@ -0,0 +1,40 @@ +- command: echo hello + comment: cron with triggered commands + container: myapp + project: crontab + schedule: '* * * * *' + trigger: + - command: echo world + container: crontab_myapp_1 +- command: echo new + comment: map a volume + dockerargs: -d -v /tmp:/tmp + image: alpine:3.5 + schedule: '* * * * *' +- command: sh -c 'echo hourly ${FOO}' + comment: use an ENV from inside a container + dockerargs: -d -e FOO=BAR + image: alpine:3.5 + schedule: '@hourly' +- command: echo 2 minute + comment: trigger every 2 min + image: alpine:3.5 + schedule: '@every 2m' + trigger: + - command: echo world + container: crontab_myapp_1 +- command: /usr/sbin/logrotate /etc/logrotate.conf + schedule: '*/5 * * * *' +- command: sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge + dns-01 --hook dehydrated-dns' + comment: Regenerate Certificate then reload nginx + 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 + image: willfarrell/letsencrypt + onstart: true + schedule: 43 6,18 * * * + trigger: + - command: sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && + /usr/sbin/nginx -s reload' + container: nginx + project: conduit diff --git a/docker-compose.yml b/docker-compose.yml index 493ec84..b0bc434 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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/config.json:/opt/crontab/config.json:rw" + - "${PWD}/config.json:/opt/crontab/config.json:rw" diff --git a/docker-entrypoint b/docker-entrypoint index bb4a752..d43d878 100755 --- a/docker-entrypoint +++ b/docker-entrypoint @@ -17,11 +17,11 @@ fi get_config() { if [ -f "${HOME_DIR}/config.toml" ]; then - 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)" + rq -t <<< $(cat ${HOME_DIR}/config.toml) | jq 'map(.)' > ${HOME_DIR}/config.json elif [ -f "${HOME_DIR}/config.yml" ]; then - 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)" + rq -y <<< $(cat ${HOME_DIR}/config.yml) | jq 'map(.)' > ${HOME_DIR}/config.json elif [ -f "${HOME_DIR}/config.yaml" ]; then - 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)" + rq -y <<< $(cat ${HOME_DIR}/config.yaml) | jq 'map(.)' > ${HOME_DIR}/config.json fi }