• Stars
    star
    278
  • Rank 144,071 (Top 3 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 7 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A docker job scheduler (aka. crontab for docker)

docker-crontab

A simple wrapper over docker to all complex cron job to be run in other containers.

Supported tags and Dockerfile links

Why?

Yes, I'm aware of 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.

Features

  • Easy to read schedule syntax allowed.
  • Allows for comments, cause we all need friendly reminders of what update_script.sh actually does.
  • Start an image using image.
  • Run command in a container using container.
  • Run command on a instances of a scaled container using project.
  • Ability to trigger scripts in other containers on completion cron job using trigger.

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.
  • 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.
  • command: Command to be run on in crontab container or docker container/image. Required.
  • image: Docker images name (ex library/alpine:3.5). Optional.
  • project: Docker Compose/Swarm project name. Optional, only applies when contain is included.
  • 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 .
  • 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.

See config-samples for examples.

[{
 	"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

docker build -t crontab .
docker run -d \
    -v /var/run/docker.sock:/var/run/docker.sock:ro \
    -v ./env:/opt/env:ro \
    -v /path/to/config/dir:/opt/crontab:rw \
    -v /path/to/logs:/var/log/crontab:rw \
    crontab

Use with docker-compose

  1. Figure out which network name used for your docker-compose containers
    • use docker network ls to see existing networks
    • if your docker-compose.yml is in my_dir directory, you probably has network my_dir_default
    • otherwise read the docker-compose docs
  2. Add dockerargs to your docker-crontab config.json
    • use --network NETWORK_NAME to connect new container into docker-compose network
    • use --rm --name NAME to use named container
    • e.g. "dockerargs": "--network my_dir_default --rm --name my-best-cron-job"

Dockerfile

FROM willfarrell/crontab

COPY config.json ${HOME_DIR}/

Logrotate Dockerfile

FROM willfarrell/crontab

RUN apk add --no-cache logrotate
RUN echo "*/5 *	* * *  /usr/sbin/logrotate /etc/logrotate.conf" >> /etc/crontabs/logrotate
COPY logrotate.conf /etc/logrotate.conf

CMD ["crond", "-f"]

Logging - In Dev

All stdout is captured, formatted, and saved to /var/log/crontab/jobs.log. Set LOG_FILE to /dev/null to disable logging.

example: e6ced859-1563-493b-b1b1-5a190b29e938 2017-06-18T01:27:10+0000 [info] Start Cronjob **map-a-vol** map a volume

grok: CRONTABLOG %{DATA:request_id} %{TIMESTAMP_ISO8601:timestamp} \[%{LOGLEVEL:severity}\] %{GREEDYDATA:message}

TODO

  • Have ability to auto regenerate crontab on file change (signal HUP?)
  • Run commands on host machine (w/ --privileged?)
  • Write tests
  • Setup TravisCI

More Repositories

1

alfred-workflows

Alfred Workflows for Developers
JavaScript
1,956
star
2

docker-autoheal

Monitor and restart unhealthy docker containers.
Shell
1,187
star
3

alfred-pkgman-workflow

Package Repo Search
PHP
694
star
4

alfred-encode-decode-workflow

Encoding and decoding a string into multiple variations.
PHP
529
star
5

alfred-caniuse-workflow

Alfred App Workflow for caniuse.com
PHP
408
star
6

alfred-dash-workflow

[Depreciated] Documentation Lookup
214
star
7

alfred-github-workflow

Searching Github repos.
PHP
209
star
8

Browsers

Collection of Browsers and Virtual Machines for web development on the Mac.
Python
94
star
9

alfred-hash-workflow

Hashing Strings
PHP
87
star
10

alfred-youtube-workflow

Search and Download YouTube Videos
Python
76
star
11

php

collection of php classes, libraries, and include files I use
PHP
73
star
12

alfred-cdn-workflow

Check which CDNs a package is hosted on.
PHP
65
star
13

angular-io-app

A web app wrapper for those who love AngularJS and Twitter Bootstrap.
JavaScript
37
star
14

ievms

IE VMs for VMWare Fusion
Shell
33
star
15

apidoc-plugin-schema

@apiSchema Plugin for apidoc
JavaScript
32
star
16

ansible-playbook-aws

ansible playbook to setup minimal VPC, EC2, ELB, RDS
Python
23
star
17

alfred-debugger

A little script to help you write your Alfred Workflows.
Shell
23
star
18

alfred-localhost-workflow

[Depreciated] Toggle Localhost Services
PHP
22
star
19

angular-modernizr

Collection of AngularJS fallbacks for less modern browsers.
JavaScript
22
star
20

alfred-blank-workflow

A template Alfred Workflow repo to get your next workflow started.
PHP
20
star
21

Leaflet.Clipper

Allows Union, Difference, Xor, and Intersection operations on two polygons.
JavaScript
15
star
22

docker-filebeat

Docker image for Elastic Filebeat
Shell
11
star
23

terraform-aws-template

Project temple for building out a full AWS application
HCL
10
star
24

dotCrontab

Easy access to Mac OS X crontab. Great for automatically updating brew or npm.
Shell
8
star
25

docker-letsencrypt

container to generate letsencrypt certs using dehydrated + lexicon
Dockerfile
8
star
26

dotVhosts

Lightweight VirtualHost manager for Mac.
PHP
8
star
27

csv-rex

🦖 A tiny and fast CSV parser & formatter for JavaScript.
JavaScript
7
star
28

aws-wishlist

List of features I'd love to see come to AWS
6
star
29

docker-ping

Container to continuously ping a server
Shell
6
star
30

node-semver-compare-range

Comparator for semver sorting.
JavaScript
5
star
31

docker-nginx

prebuild configs for nginx including letsencrypt bootstrapping
Shell
5
star
32

middy-jsonapi

JSONAPI middleware for middy
JavaScript
5
star
33

ansible-playbook-bastion

CentOS Bastion Host Setup
Shell
5
star
34

terraform-account-modules

Collection of global sub account modules
HCL
5
star
35

fluent-transpiler

Transpile Fluent (ftl) files into optomized, tree-shakable, JavaScript EcmaScript Modules (esm).
JavaScript
5
star
36

Coda-Plugins

A few Coda 2 Plugins
PHP
4
star
37

datastream

Commonly used stream patterns for Web Streams API and NodeJS Streams
JavaScript
4
star
38

secret-patterns

RegExp patterns for code secrets
Shell
4
star
39

angular-io

AngularIO - Collection of AngularJS modules worth checking out.
JavaScript
4
star
40

apidoc-plugin-example

@apiExample
JavaScript
4
star
41

documentation

Documentation for policies, process, and templates
4
star
42

Mac-OSX-Bash-Files

batch file to create a list of tv show (w/ ststs) from a nested folder structure
PHP
3
star
43

contribPlusPlus

Keeping Github green ... yeah, we like green.
3
star
44

middy-rds

Middy middleware for creating a db connection using knex
JavaScript
3
star
45

docker-kafka

kafka for docker v1.11+
Shell
2
star
46

ajv-ftl-i18n

Internationalized error messages for Ajv - superfast JSON validator for JSON Schema and JSON Type Definition.
Fluent
2
star
47

serverless-terraform

Convert serverless config into a terraform module
JavaScript
2
star
48

Coda-Dreamweaver-Color-Theme

The code color template smiliar to Dreamweaver for Coda
2
star
49

ajv-cmd

Transpile JSON-Schema (.json) files to JavaScript (.js or .mjs) using ajv
JavaScript
2
star
50

js

collection of js files I use often
JavaScript
2
star
51

accessibility

Collection of web design patterns
2
star
52

font-awesome-auto-sub-set

A PHP script to get a sub-set of Font-Awesome icons that are used in your app.
PHP
2
star
53

docker-vault-env

script to bootstrap ENV from vault
Shell
2
star
54

keyStorage.js

Simple wrapper for JavaScript localStorage
JavaScript
2
star
55

serverless-template

Boilerplate for serverless
JavaScript
2
star
56

terraform-waf-module

OWASP WAF
HCL
2
star
57

terraform-public-static-assets-module

Terraform Module: CloudFront, ACM, S3
HCL
2
star
58

lib.parse

parsing libraries for js and php
PHP
1
star
59

csv-benchmarks

Benchmarks of popular CSV libraries
JavaScript
1
star
60

workbee

A tiny ServiceWorker for secure web applications.
JavaScript
1
star
61

a11ychart

Accessibility focused charting library [WIP]
1
star
62

mac-ci

Scripts to autoset a Jenkins CI on a Mac. Great to put on a spare Mac mini.
Shell
1
star
63

docker-selfsigncert

Docker for creating self signed tls certificates
Shell
1
star
64

docker-redis

base redis with optimized configs + healthcheck
Shell
1
star
65

apidoc-plugins

Collection of plugins for apidoc and a place to request new ones.
1
star
66

docker-elasticsearch-curator

delete old logs
Shell
1
star
67

terraform-vpc-module

VPC w/ NATs
HCL
1
star
68

terraform-state-module

Terraform module: Set up state backend using S3 & DynamoDB
HCL
1
star
69

prettier-standard

Just a simple wrapper around Prettier & Standard with auto-fix enabled.
Shell
1
star
70

ansible-role-sshd

Setup user accounts on CentOS
1
star