add ex to docs

This commit is contained in:
will Farrell 2017-02-14 07:44:14 -07:00
parent c88150ccb2
commit 11155c1f47
3 changed files with 36 additions and 10 deletions

View File

@ -30,19 +30,38 @@ A great project, don't get me wrong. It was just missing certain key enterprise
- `container`: Full container name or container alias if `project` is set. Ignored if `image` is included. Optional. - `container`: Full container name or container alias if `project` is set. Ignored if `image` is included. Optional.
- `dockerargs`: Command line docker `run`/`exec` arguments for full control. Defaults to ` `. - `dockerargs`: Command line docker `run`/`exec` arguments for full control. Defaults to ` `.
- `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. Default `false`. - `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.sample.json`](https://github.com/willfarrell/docker-crontab/blob/master/config.sample.json) for examples.
## Examples ```json
[{
"schedule":"@every 5m",
"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
}]
```
## How to use
### Command Line ### Command Line
```bash ```bash
docer build -t crontab . docer build -t crontab .
docker run -d \ docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \ -v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /usr/bin/docker:/usr/bin/docker \ -v /usr/bin/docker:/usr/bin/docker:ro \
-v /path/to/config/dir:/opt/crontab \ -v /path/to/config/dir:/opt/crontab:rw \
crontab crontab
``` ```
@ -65,7 +84,6 @@ CMD ["crond", "-f"]
``` ```
## TODO ## TODO
- [ ] Make smaller by using busybox?
- [ ] Have ability to auto regenerate crontab on file change (signal HUP?) - [ ] Have ability to auto regenerate crontab on file change (signal HUP?)
- [ ] Run commands on host machine (w/ --privileged?) - [ ] Run commands on host machine (w/ --privileged?)
- [ ] Write tests - [ ] Write tests

View File

@ -10,6 +10,6 @@ services:
build: . build: .
restart: always restart: always
volumes: volumes:
- "/var/run/docker.sock:/var/run/docker.sock" - "/var/run/docker.sock:/var/run/docker.sock:ro"
- "/usr/bin/docker:/usr/bin/docker" - "/usr/bin/docker:/usr/bin/docker:ro"
- "/Users/willfarrell/Development/docker/crontab/home_dir:/opt/crontab" - "/Users/willfarrell/Development/docker/crontab/home_dir:/opt/crontab:rw"

View File

@ -44,11 +44,19 @@ EOF
fi fi
} }
#make_host_cmd() {
# HOST_BINARY=$(echo ${1} | jq -r .host)
# TMP_COMMAND=$(echo ${1} | jq -r .command)
# echo "${HOST_BINARY} ${TMP_COMMAND}"
#}
make_cmd() { make_cmd() {
if [ "$(echo ${1} | jq -r .image)" != "null" ]; then if [ "$(echo ${1} | jq -r .image)" != "null" ]; then
make_image_cmd "$1" make_image_cmd "$1"
elif [ "$(echo ${1} | jq -r .container)" != "null" ]; then elif [ "$(echo ${1} | jq -r .container)" != "null" ]; then
make_container_cmd "$1" make_container_cmd "$1"
#elif [ "$(echo ${1} | jq -r .host)" != "null" ]; then
# make_host_cmd "$1"
else else
echo ${1} | jq -r .command echo ${1} | jq -r .command
fi fi
@ -153,7 +161,7 @@ function build_crontab() {
# Run onstart commands # Run onstart commands
for COMMAND in "${ONSTART}"; do for COMMAND in "${ONSTART}"; do
${COMMAND} ${COMMAND} &
done done
} }