mirror of
https://github.com/willfarrell/docker-crontab.git
synced 2025-04-19 12:49:48 +02:00
Compare commits
No commits in common. "main" and "0.6.0" have entirely different histories.
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -21,7 +21,6 @@ jobs:
|
|||||||
uses: docker/setup-qemu-action@v1
|
uses: docker/setup-qemu-action@v1
|
||||||
-
|
-
|
||||||
name: Set up Docker Buildx
|
name: Set up Docker Buildx
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
-
|
-
|
||||||
name: Login to DockerHub
|
name: Login to DockerHub
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,5 +2,3 @@
|
|||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
config.json
|
config.json
|
||||||
.vscode
|
|
||||||
.DS_Store
|
|
||||||
|
16
Dockerfile
16
Dockerfile
@ -1,24 +1,12 @@
|
|||||||
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 jq bash tini \
|
RUN apk add --no-cache --virtual .run-deps gettext bash jq \
|
||||||
&& 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 ["/sbin/tini", "--", "/docker-entrypoint"]
|
ENTRYPOINT ["/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
|
||||||
|
10
README.md
10
README.md
@ -5,13 +5,12 @@ 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)
|
- [`0.6.0` (*Dockerfile*)](https://github.com/willfarrell/docker-crontab/blob/0.6.0/Dockerfile)
|
||||||
|
|
||||||
 [](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) (>250MB when this was created), it was the main inspiration for this project.
|
Yes, I'm aware of [mcuadros/ofelia](https://github.com/mcuadros/ofelia) (~10MB), 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
|
||||||
@ -22,10 +21,7 @@ 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 file
|
## Config.json
|
||||||
|
|
||||||
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.
|
||||||
@ -37,7 +33,7 @@ The config file can be specifed in any of `json`, `toml`, or `yaml`, and can be
|
|||||||
- `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-samples`](config-samples) for examples.
|
See [`config.sample.json`](https://github.com/willfarrell/docker-crontab/blob/master/config.sample.json) for examples.
|
||||||
|
|
||||||
```json
|
```json
|
||||||
[{
|
[{
|
||||||
|
@ -1,60 +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
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,50 +0,0 @@
|
|||||||
{
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
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
|
|
@ -1,50 +0,0 @@
|
|||||||
# 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"
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
|||||||
- 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
|
|
47
config.sample.json
Normal file
47
config.sample.json
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
[{
|
||||||
|
"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,4 +11,5 @@ 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"
|
||||||
- "${PWD}/config-samples/config.sample.mapping.json:/opt/crontab/config.json:rw"
|
# - "/usr/bin/docker:/usr/bin/docker:ro"
|
||||||
|
- "/Users/willfarrell/Development/docker/docker-crontab/config.json:/opt/crontab/config.json:rw"
|
||||||
|
@ -15,18 +15,7 @@ if [ "${LOG_FILE}" == "" ]; then
|
|||||||
touch ${LOG_FILE}
|
touch ${LOG_FILE}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
get_config() {
|
CONFIG=${HOME_DIR}/config.json
|
||||||
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
|
||||||
|
|
||||||
@ -60,22 +49,7 @@ 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}"
|
||||||
@ -106,7 +80,6 @@ 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
|
||||||
@ -180,7 +153,6 @@ parse_schedule() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function build_crontab() {
|
function build_crontab() {
|
||||||
|
|
||||||
rm -rf ${CRONTAB_FILE}
|
rm -rf ${CRONTAB_FILE}
|
||||||
|
|
||||||
ONSTART=()
|
ONSTART=()
|
||||||
@ -258,27 +230,15 @@ EOF
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ensure_docker_socket_accessible
|
ensure_docker_socket_accessible
|
||||||
|
|
||||||
start_app() {
|
if [ "$1" = "crond" ]; then
|
||||||
get_config
|
if [ -f ${CONFIG} ]; then
|
||||||
if [ -f "${HOME_DIR}/config.working.json" ]; then
|
build_crontab
|
||||||
export CONFIG=${HOME_DIR}/config.working.json
|
|
||||||
elif [ -f "${HOME_DIR}/config.json" ]; then
|
|
||||||
export CONFIG=${HOME_DIR}/config.json
|
|
||||||
else
|
else
|
||||||
echo "NO CONFIG FILE FOUND"
|
echo "Unable to find ${HOME_DIR}/config.json"
|
||||||
fi
|
fi
|
||||||
if [ "$1" = "crond" ]; then
|
fi
|
||||||
if [ -f ${CONFIG} ]; then
|
|
||||||
build_crontab
|
|
||||||
else
|
|
||||||
echo "Unable to find ${CONFIG}"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
echo "$@"
|
|
||||||
exec "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
start_app "$@"
|
echo "$@"
|
||||||
|
exec "$@"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user