mirror of
				https://github.com/willfarrell/docker-crontab.git
				synced 2025-10-30 21:27:18 +01:00 
			
		
		
		
	Updating README, adding JSON mapping support for consistency
This commit is contained in:
		| @@ -21,7 +21,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 +36,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 | ||||||
|  |   } | ||||||
|  | ] | ||||||
							
								
								
									
										60
									
								
								config-samples/config.sample.mapping.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								config-samples/config.sample.mapping.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 | ||||||
|  |   } | ||||||
|  | ] | ||||||
							
								
								
									
										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 | ||||||
| @@ -1,3 +1,4 @@ | |||||||
|  | # toml files can only have top-loevl mappings, so this is the only sample | ||||||
| ["cron with triggered commands"] | ["cron with triggered commands"] | ||||||
| comment = "cron with triggered commands" | comment = "cron with triggered commands" | ||||||
| schedule = "* * * * *" | schedule = "* * * * *" | ||||||
| @@ -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" | ||||||
|      - "${PWD}/config.json:/opt/crontab/config.json:rw" |  | ||||||
|   | |||||||
| @@ -16,7 +16,11 @@ if [ "${LOG_FILE}" == "" ]; then | |||||||
| fi | fi | ||||||
|  |  | ||||||
| get_config() { | get_config() { | ||||||
|     if [ -f "${HOME_DIR}/config.toml" ]; then |     if [ -f "${HOME_DIR}/config.json" ]; then | ||||||
|  |         cp ${HOME_DIR}/config.json ${HOME_DIR}/config.json.old | ||||||
|  |         jq 'map(.)' ${HOME_DIR}/config.json.old > ${HOME_DIR}/config.json | ||||||
|  |         rm ${HOME_DIR}/config.json.old | ||||||
|  |     elif [ -f "${HOME_DIR}/config.toml" ]; then | ||||||
|         rq -t <<< $(cat ${HOME_DIR}/config.toml) | jq 'map(.)' > ${HOME_DIR}/config.json |         rq -t <<< $(cat ${HOME_DIR}/config.toml) | jq 'map(.)' > ${HOME_DIR}/config.json | ||||||
|     elif [ -f "${HOME_DIR}/config.yml" ]; then |     elif [ -f "${HOME_DIR}/config.yml" ]; then | ||||||
|         rq -y <<< $(cat ${HOME_DIR}/config.yml) | jq 'map(.)' > ${HOME_DIR}/config.json |         rq -y <<< $(cat ${HOME_DIR}/config.yml) | jq 'map(.)' > ${HOME_DIR}/config.json | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user