mirror of
https://github.com/willfarrell/docker-crontab.git
synced 2025-04-12 01:10:24 +02:00
Compare commits
41 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
be97512ec2 | ||
|
89cf941fea | ||
|
5611ac5014 | ||
|
b29a6bb3b3 | ||
|
c2331fc9e7 | ||
|
88bed2bc4a | ||
|
0ef54cc06b | ||
|
d9b4cecea0 | ||
|
e55dba16d7 | ||
|
18e9954d74 | ||
|
b9bbeacae1 | ||
|
a4e4227327 | ||
|
ef29a8dadc | ||
|
e28e8dbd2f | ||
|
cba326b800 | ||
|
16396988c2 | ||
|
22900fddd1 | ||
|
ff6fde0e5b | ||
|
5f5abd5251 | ||
|
84ce659f86 | ||
|
92d2c91227 | ||
|
0ef158253f | ||
|
af7994a740 | ||
|
1af64f5f7d | ||
|
44a4708123 | ||
|
85a0ecf368 | ||
|
cdf3f1a005 | ||
|
e81c5c7fb9 | ||
|
71b0bf9ac2 | ||
|
61149875ae | ||
|
2c633af586 | ||
|
8940b3300e | ||
|
6406e1f6e4 | ||
|
9349a92372 | ||
|
c82354e261 | ||
|
200cd1313f | ||
|
5013ecbc3f | ||
|
4f9146b8f8 | ||
|
4a0d85f51a | ||
|
21e58d0588 | ||
|
911eed81f6 |
12
.github/FUNDING.yml
vendored
Normal file
12
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: [willfarrell]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
49
.github/workflows/build.yml
vendored
Normal file
49
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
schedule:
|
||||||
|
- cron: '0 0 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
multi:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
-
|
||||||
|
name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v1
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
id: buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
-
|
||||||
|
name: Login to DockerHub
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- if: github.ref == 'refs/heads/main'
|
||||||
|
name: Conditional(Set tag as `latest`)
|
||||||
|
run: echo "tag=willfarrell/crontab:latest" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- if: startsWith(github.ref, 'refs/tags/')
|
||||||
|
name: Conditional(Set tag as `{version}`)
|
||||||
|
run: echo "tag=willfarrell/crontab:${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: ./Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ env.tag }}
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
|||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
config.json
|
config.json
|
||||||
|
.vscode
|
||||||
|
.DS_Store
|
||||||
|
16
Dockerfile
16
Dockerfile
@ -1,12 +1,24 @@
|
|||||||
|
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
|
FROM library/docker:stable
|
||||||
|
|
||||||
|
COPY --from=rq-build /root/rq /usr/local/bin
|
||||||
|
|
||||||
ENV HOME_DIR=/opt/crontab
|
ENV HOME_DIR=/opt/crontab
|
||||||
RUN apk add --no-cache --virtual .run-deps gettext bash jq \
|
RUN apk add --no-cache --virtual .run-deps gettext jq bash tini \
|
||||||
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \
|
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects \
|
||||||
&& adduser -S docker -D
|
&& adduser -S docker -D
|
||||||
|
|
||||||
COPY docker-entrypoint /
|
COPY docker-entrypoint /
|
||||||
ENTRYPOINT ["/docker-entrypoint"]
|
ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint"]
|
||||||
|
|
||||||
HEALTHCHECK --interval=5s --timeout=3s \
|
HEALTHCHECK --interval=5s --timeout=3s \
|
||||||
CMD ps aux | grep '[c]rond' || exit 1
|
CMD ps aux | grep '[c]rond' || exit 1
|
||||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2019 will Farrell
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
14
README.md
14
README.md
@ -5,12 +5,13 @@ A simple wrapper over `docker` to all complex cron job to be run in other contai
|
|||||||
## Supported tags and Dockerfile links
|
## Supported tags and Dockerfile links
|
||||||
|
|
||||||
- [`latest` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/master/Dockerfile)
|
- [`latest` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/master/Dockerfile)
|
||||||
|
- [`1.0.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/1.0.0/Dockerfile)
|
||||||
|
- [`0.6.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/0.6.0/Dockerfile)
|
||||||
|
|
||||||
[](http://microbadger.com/images/willfarrell/crontab "Get your own version badge on microbadger.com") [](http://microbadger.com/images/willfarrell/crontab "Get your own image badge on microbadger.com")
|
 [](http://microbadger.com/images/willfarrell/crontab "Get your own image badge on microbadger.com")
|
||||||
|
|
||||||
|
|
||||||
## Why?
|
## Why?
|
||||||
Yes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (280MB), it was the main inspiration for this project.
|
Yes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (>250MB when this was created), it was the main inspiration for this project.
|
||||||
A great project, don't get me wrong. It was just missing certain key enterprise features I felt were required to support where docker is heading.
|
A great project, don't get me wrong. It was just missing certain key enterprise features I felt were required to support where docker is heading.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@ -21,7 +22,10 @@ A great project, don't get me wrong. It was just missing certain key enterprise
|
|||||||
- Run command on a instances of a scaled container using `project`.
|
- Run command on a instances of a scaled container using `project`.
|
||||||
- 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 file
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
- `name`: Human readable name that will be used as the job filename. Will be converted into a slug. 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://en.wikipedia.org/wiki/Cron. Ex `@hourly`, `@every 1h30m`, `* * * * *`. Required.
|
- `schedule`: Crontab schedule syntax as described in https://en.wikipedia.org/wiki/Cron. Ex `@hourly`, `@every 1h30m`, `* * * * *`. Required.
|
||||||
@ -33,7 +37,7 @@ A great project, don't get me wrong. It was just missing certain key enterprise
|
|||||||
- `trigger`: Array of docker-crontab subset objects. Subset includes: `image`,`project`,`container`,`command`,`dockerargs`
|
- `trigger`: Array of docker-crontab subset objects. Subset includes: `image`,`project`,`container`,`command`,`dockerargs`
|
||||||
- `onstart`: Run the command on `crontab` container start, set to `true`. Optional, defaults to falsey.
|
- `onstart`: Run the command on `crontab` container start, set to `true`. Optional, defaults to falsey.
|
||||||
|
|
||||||
See [`config.sample.json`](https://github.com/willfarrell/docker-crontab/blob/master/config.sample.json) for examples.
|
See [`config-samples`](config-samples) for examples.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[{
|
[{
|
||||||
|
60
config-samples/config.sample.json
Normal file
60
config-samples/config.sample.json
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"comment": "cron with triggered commands",
|
||||||
|
"schedule": "* * * * *",
|
||||||
|
"command": "echo hello",
|
||||||
|
"project": "crontab",
|
||||||
|
"container": "myapp",
|
||||||
|
"trigger": [
|
||||||
|
{
|
||||||
|
"command": "echo world",
|
||||||
|
"container": "crontab_myapp_1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "map a volume",
|
||||||
|
"schedule": "* * * * *",
|
||||||
|
"dockerargs": "-d -v /tmp:/tmp",
|
||||||
|
"command": "echo new",
|
||||||
|
"image": "alpine:3.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "use an ENV from inside a container",
|
||||||
|
"schedule": "@hourly",
|
||||||
|
"dockerargs": "-d -e FOO=BAR",
|
||||||
|
"command": "sh -c 'echo hourly ${FOO}'",
|
||||||
|
"image": "alpine:3.5"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "trigger every 2 min",
|
||||||
|
"schedule": "@every 2m",
|
||||||
|
"command": "echo 2 minute",
|
||||||
|
"image": "alpine:3.5",
|
||||||
|
"trigger": [
|
||||||
|
{
|
||||||
|
"command": "echo world",
|
||||||
|
"container": "crontab_myapp_1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"schedule": "*/5 * * * *",
|
||||||
|
"command": "/usr/sbin/logrotate /etc/logrotate.conf"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "Regenerate Certificate then reload nginx",
|
||||||
|
"schedule": "43 6,18 * * *",
|
||||||
|
"command": "sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'",
|
||||||
|
"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",
|
||||||
|
"trigger": [
|
||||||
|
{
|
||||||
|
"command": "sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && /usr/sbin/nginx -s reload'",
|
||||||
|
"project": "conduit",
|
||||||
|
"container": "nginx"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onstart": true
|
||||||
|
}
|
||||||
|
]
|
50
config-samples/config.sample.mapping.json
Normal file
50
config-samples/config.sample.mapping.json
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
{
|
||||||
|
"cron with triggered commands": {
|
||||||
|
"comment": "cron with triggered commands",
|
||||||
|
"schedule": "* * * * *",
|
||||||
|
"command": "echo hello",
|
||||||
|
"project": "crontab",
|
||||||
|
"container": "myapp",
|
||||||
|
"trigger": [{ "command": "echo world", "container": "crontab_myapp_1" }]
|
||||||
|
},
|
||||||
|
"map a volume": {
|
||||||
|
"comment": "map a volume",
|
||||||
|
"schedule": "* * * * *",
|
||||||
|
"dockerargs": "-d -v /tmp:/tmp",
|
||||||
|
"command": "echo new",
|
||||||
|
"image": "alpine:3.5"
|
||||||
|
},
|
||||||
|
"use an ENV from inside a container": {
|
||||||
|
"comment": "use an ENV from inside a container",
|
||||||
|
"schedule": "@hourly",
|
||||||
|
"dockerargs": "-d -e FOO=BAR",
|
||||||
|
"command": "sh -c 'echo hourly ${FOO}'",
|
||||||
|
"image": "alpine:3.5"
|
||||||
|
},
|
||||||
|
"trigger every 2 min": {
|
||||||
|
"comment": "trigger every 2 min",
|
||||||
|
"schedule": "@every 2m",
|
||||||
|
"command": "echo 2 minute",
|
||||||
|
"image": "alpine:3.5",
|
||||||
|
"trigger": [{ "command": "echo world", "container": "crontab_myapp_1" }]
|
||||||
|
},
|
||||||
|
"null": {
|
||||||
|
"schedule": "*/5 * * * *",
|
||||||
|
"command": "/usr/sbin/logrotate /etc/logrotate.conf"
|
||||||
|
},
|
||||||
|
"Regenerate Certificate then reload nginx": {
|
||||||
|
"comment": "Regenerate Certificate then reload nginx",
|
||||||
|
"schedule": "43 6,18 * * *",
|
||||||
|
"command": "sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'",
|
||||||
|
"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",
|
||||||
|
"trigger": [
|
||||||
|
{
|
||||||
|
"command": "sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && /usr/sbin/nginx -s reload'",
|
||||||
|
"project": "conduit",
|
||||||
|
"container": "nginx"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"onstart": true
|
||||||
|
}
|
||||||
|
}
|
46
config-samples/config.sample.mapping.yml
Normal file
46
config-samples/config.sample.mapping.yml
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
cron with triggered commands:
|
||||||
|
command: echo hello
|
||||||
|
comment: cron with triggered commands
|
||||||
|
container: myapp
|
||||||
|
project: crontab
|
||||||
|
schedule: '* * * * *'
|
||||||
|
trigger:
|
||||||
|
- command: echo world
|
||||||
|
container: crontab_myapp_1
|
||||||
|
map a volume:
|
||||||
|
command: echo new
|
||||||
|
comment: map a volume
|
||||||
|
dockerargs: -d -v /tmp:/tmp
|
||||||
|
image: alpine:3.5
|
||||||
|
schedule: '* * * * *'
|
||||||
|
use an ENV from inside a container:
|
||||||
|
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'
|
||||||
|
trigger every 2 min:
|
||||||
|
command: echo 2 minute
|
||||||
|
comment: trigger every 2 min
|
||||||
|
image: alpine:3.5
|
||||||
|
schedule: '@every 2m'
|
||||||
|
trigger:
|
||||||
|
- command: echo world
|
||||||
|
container: crontab_myapp_1
|
||||||
|
null:
|
||||||
|
command: /usr/sbin/logrotate /etc/logrotate.conf
|
||||||
|
schedule: '*/5 * * * *'
|
||||||
|
Regenerate Certificate then reload nginx:
|
||||||
|
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
|
50
config-samples/config.sample.toml
Normal file
50
config-samples/config.sample.toml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# toml files can only have top-loevl mappings, so this is the only sample
|
||||||
|
["cron with triggered commands"]
|
||||||
|
comment = "cron with triggered commands"
|
||||||
|
schedule = "* * * * *"
|
||||||
|
command = "echo hello"
|
||||||
|
project = "crontab"
|
||||||
|
container = "myapp"
|
||||||
|
[["cron with triggered commands".trigger]]
|
||||||
|
command = "echo world"
|
||||||
|
container = "crontab_myapp_1"
|
||||||
|
|
||||||
|
["map a volume"]
|
||||||
|
comment = "map a volume"
|
||||||
|
schedule = "* * * * *"
|
||||||
|
dockerargs = "-d -v /tmp:/tmp"
|
||||||
|
command = "echo new"
|
||||||
|
image = "alpine:3.5"
|
||||||
|
|
||||||
|
["use an ENV from inside a container"]
|
||||||
|
comment = "use an ENV from inside a container"
|
||||||
|
schedule = "@hourly"
|
||||||
|
dockerargs = "-d -e FOO=BAR"
|
||||||
|
command = "sh -c 'echo hourly ${FOO}'"
|
||||||
|
image = "alpine:3.5"
|
||||||
|
|
||||||
|
["trigger every 2 min"]
|
||||||
|
comment = "trigger every 2 min"
|
||||||
|
schedule = "@every 2m"
|
||||||
|
command = "echo 2 minute"
|
||||||
|
image = "alpine:3.5"
|
||||||
|
[["trigger every 2 min".trigger]]
|
||||||
|
command = "echo world"
|
||||||
|
container = "crontab_myapp_1"
|
||||||
|
|
||||||
|
["? /usr/sbin/logrotate /etc/logrotate.conf*/5 * * * *"]
|
||||||
|
schedule = "*/5 * * * *"
|
||||||
|
command = "/usr/sbin/logrotate /etc/logrotate.conf"
|
||||||
|
|
||||||
|
["Regenerate Certificate then reload nginx"]
|
||||||
|
comment = "Regenerate Certificate then reload nginx"
|
||||||
|
schedule = "43 6,18 * * *"
|
||||||
|
command = "sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'"
|
||||||
|
dockerargs = "--env-file /opt/crontab/env/letsencrypt.env -v ${PWD}:/etc/ssl -v webapp_nginx_acme_challenge:/var/www/.well-known/acme-challenge"
|
||||||
|
image = "willfarrell/letsencrypt"
|
||||||
|
onstart = true
|
||||||
|
[["Regenerate Certificate then reload nginx".trigger]]
|
||||||
|
command = "sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && /usr/sbin/nginx -s reload'"
|
||||||
|
project = "conduit"
|
||||||
|
container = "nginx"
|
||||||
|
|
40
config-samples/config.sample.yml
Normal file
40
config-samples/config.sample.yml
Normal file
@ -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
|
@ -1,47 +0,0 @@
|
|||||||
[{
|
|
||||||
"comment":"cron with triggered commands",
|
|
||||||
"schedule":"* * * * *",
|
|
||||||
"command":"echo hello",
|
|
||||||
"project":"crontab",
|
|
||||||
"container":"myapp",
|
|
||||||
"trigger":[{
|
|
||||||
"command":"echo world",
|
|
||||||
"container":"crontab_myapp_1"
|
|
||||||
}]
|
|
||||||
},{
|
|
||||||
"comment":"map a volume",
|
|
||||||
"schedule":"* * * * *",
|
|
||||||
"dockerargs":"-d -v /tmp:/tmp",
|
|
||||||
"command":"echo new",
|
|
||||||
"image":"alpine:3.5"
|
|
||||||
},{
|
|
||||||
"comment":"use an ENV from inside a container",
|
|
||||||
"schedule":"@hourly",
|
|
||||||
"dockerargs":"-d -e FOO=BAR",
|
|
||||||
"command":"sh -c 'echo hourly ${FOO}'",
|
|
||||||
"image":"alpine:3.5"
|
|
||||||
},{
|
|
||||||
"comment":"trigger every 2 min",
|
|
||||||
"schedule":"@every 2m",
|
|
||||||
"command":"echo 2 minute",
|
|
||||||
"image":"alpine:3.5",
|
|
||||||
"trigger":[{
|
|
||||||
"command":"echo world",
|
|
||||||
"container":"crontab_myapp_1"
|
|
||||||
}]
|
|
||||||
},{
|
|
||||||
"schedule":"*/5 * * * *",
|
|
||||||
"command":"/usr/sbin/logrotate /etc/logrotate.conf"
|
|
||||||
},{
|
|
||||||
"comment":"Regenerate Certificate then reload nginx",
|
|
||||||
"schedule":"43 6,18 * * *",
|
|
||||||
"command":"sh -c 'dehydrated --cron --out /etc/ssl --domain ${LE_DOMAIN} --challenge dns-01 --hook dehydrated-dns'",
|
|
||||||
"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",
|
|
||||||
"trigger":[{
|
|
||||||
"command":"sh -c '/etc/scripts/make_hpkp ${NGINX_DOMAIN} && /usr/sbin/nginx -t && /usr/sbin/nginx -s reload'",
|
|
||||||
"project":"conduit",
|
|
||||||
"container":"nginx"
|
|
||||||
}],
|
|
||||||
"onstart":true
|
|
||||||
}]
|
|
@ -11,5 +11,4 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
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"
|
- "${PWD}/config-samples/config.sample.mapping.json:/opt/crontab/config.json:rw"
|
||||||
- "/Users/willfarrell/Development/docker/docker-crontab/config.json:/opt/crontab/config.json:rw"
|
|
||||||
|
@ -15,7 +15,18 @@ if [ "${LOG_FILE}" == "" ]; then
|
|||||||
touch ${LOG_FILE}
|
touch ${LOG_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CONFIG=${HOME_DIR}/config.json
|
get_config() {
|
||||||
|
if [ -f "${HOME_DIR}/config.json" ]; then
|
||||||
|
jq 'map(.)' ${HOME_DIR}/config.json > ${HOME_DIR}/config.working.json
|
||||||
|
elif [ -f "${HOME_DIR}/config.toml" ]; then
|
||||||
|
rq -t <<< $(cat ${HOME_DIR}/config.toml) | jq 'map(.)' > ${HOME_DIR}/config.json
|
||||||
|
elif [ -f "${HOME_DIR}/config.yml" ]; then
|
||||||
|
rq -y <<< $(cat ${HOME_DIR}/config.yml) | jq 'map(.)' > ${HOME_DIR}/config.json
|
||||||
|
elif [ -f "${HOME_DIR}/config.yaml" ]; then
|
||||||
|
rq -y <<< $(cat ${HOME_DIR}/config.yaml) | jq 'map(.)' > ${HOME_DIR}/config.json
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
DOCKER_SOCK=/var/run/docker.sock
|
DOCKER_SOCK=/var/run/docker.sock
|
||||||
CRONTAB_FILE=/etc/crontabs/docker
|
CRONTAB_FILE=/etc/crontabs/docker
|
||||||
|
|
||||||
@ -49,7 +60,22 @@ slugify() {
|
|||||||
|
|
||||||
make_image_cmd() {
|
make_image_cmd() {
|
||||||
DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
|
DOCKERARGS=$(echo ${1} | jq -r .dockerargs)
|
||||||
|
VOLUMES=$(echo ${1} | jq -r '.volumes | map(" -v " + .) | join("")')
|
||||||
|
PORTS=$(echo ${1} | jq -r '.ports | map(" -p " + .) | join("")')
|
||||||
|
EXPOSE=$(echo ${1} | jq -r '.expose | map(" --expose " + .) | join("")')
|
||||||
|
# We'll add name in, if it exists
|
||||||
|
NAME=$(echo ${1} | jq -r 'select(.name != null) | .name')
|
||||||
|
NETWORK=$(echo ${1} | jq -r 'select(.network != null) | .network')
|
||||||
|
ENVIRONMENT=$(echo ${1} | jq -r '.environment | map(" -e " + .) | join("")')
|
||||||
|
# echo ${1} | jq -r '.environment | join("\n")' > ${PWD}/${NAME}.env
|
||||||
|
# ENVIRONMENT=" --env-file ${PWD}/${NAME}.env"
|
||||||
if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi
|
if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi
|
||||||
|
if [ ! -z "${NAME}" ]; then DOCKERARGS="${DOCKERARGS} --rm --name ${NAME} "; fi
|
||||||
|
if [ ! -z "${NETWORK}" ]; then DOCKERARGS="${DOCKERARGS} --network ${NETWORK} "; fi
|
||||||
|
if [ ! -z "${VOLUMES}" ]; then DOCKERARGS="${DOCKERARGS}${VOLUMES}"; fi
|
||||||
|
if [ ! -z "${ENVIRONMENT}" ]; then DOCKERARGS="${DOCKERARGS}${ENVIRONMENT}"; fi
|
||||||
|
if [ ! -z "${PORTS}" ]; then DOCKERARGS="${DOCKERARGS}${PORTS}"; fi
|
||||||
|
if [ ! -z "${EXPOSE}" ]; then DOCKERARGS="${DOCKERARGS}${EXPOSE}"; fi
|
||||||
IMAGE=$(echo ${1} | jq -r .image | envsubst)
|
IMAGE=$(echo ${1} | jq -r .image | envsubst)
|
||||||
TMP_COMMAND=$(echo ${1} | jq -r .command)
|
TMP_COMMAND=$(echo ${1} | jq -r .command)
|
||||||
echo "docker run ${DOCKERARGS} ${IMAGE} ${TMP_COMMAND}"
|
echo "docker run ${DOCKERARGS} ${IMAGE} ${TMP_COMMAND}"
|
||||||
@ -80,6 +106,7 @@ for CONTAINER_NAME in \$CONTAINERS; do
|
|||||||
done
|
done
|
||||||
EOF
|
EOF
|
||||||
echo "/bin/bash ${HOME_DIR}/projects/${SCRIPT_NAME}.sh"
|
echo "/bin/bash ${HOME_DIR}/projects/${SCRIPT_NAME}.sh"
|
||||||
|
# cat "/bin/bash ${HOME_DIR}/projects/${SCRIPT_NAME}.sh"
|
||||||
else
|
else
|
||||||
echo "docker exec ${DOCKERARGS} ${CONTAINER} ${TMP_COMMAND}"
|
echo "docker exec ${DOCKERARGS} ${CONTAINER} ${TMP_COMMAND}"
|
||||||
fi
|
fi
|
||||||
@ -153,6 +180,7 @@ parse_schedule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function build_crontab() {
|
function build_crontab() {
|
||||||
|
|
||||||
rm -rf ${CRONTAB_FILE}
|
rm -rf ${CRONTAB_FILE}
|
||||||
|
|
||||||
ONSTART=()
|
ONSTART=()
|
||||||
@ -230,15 +258,27 @@ EOF
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ensure_docker_socket_accessible
|
ensure_docker_socket_accessible
|
||||||
|
|
||||||
if [ "$1" = "crond" ]; then
|
start_app() {
|
||||||
if [ -f ${CONFIG} ]; then
|
get_config
|
||||||
build_crontab
|
if [ -f "${HOME_DIR}/config.working.json" ]; then
|
||||||
|
export CONFIG=${HOME_DIR}/config.working.json
|
||||||
|
elif [ -f "${HOME_DIR}/config.json" ]; then
|
||||||
|
export CONFIG=${HOME_DIR}/config.json
|
||||||
else
|
else
|
||||||
echo "Unable to find ${HOME_DIR}/config.json"
|
echo "NO CONFIG FILE FOUND"
|
||||||
fi
|
fi
|
||||||
fi
|
if [ "$1" = "crond" ]; then
|
||||||
|
if [ -f ${CONFIG} ]; then
|
||||||
|
build_crontab
|
||||||
|
else
|
||||||
|
echo "Unable to find ${CONFIG}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "$@"
|
||||||
|
exec "$@"
|
||||||
|
}
|
||||||
|
|
||||||
echo "$@"
|
start_app "$@"
|
||||||
exec "$@"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user