#cron #cron-job #container-image #ofelia

bin+lib cfc

A crontab replacement for container environment

1 unstable release

0.1.0 Apr 29, 2024

#40 in #cron-job

Apache-2.0

51KB
956 lines

Cron for Containers

Crates.io Coverage status Apache License Documentation

Cron for Containers is a lightweight cron daemon for containers that aims to be an in-place replacement for ofelia wherever mail capabilities are not required.

Currently, only docker and podman are supported.

Installation

Install the executable with cargo:

cargo install cfc

Usage

You may either provide a configuration file or extract configuration from container labels.

The scheduling format is an "augmented" cron format inspired by go's implementation. E.g. @every 10m`` or 0 10 * * * *`.

Note: The cron format does not have to contain the seconds specifier

You can configure four different kind of jobs:

job-exec: Executed in a running container. job-run: Executed in a new container, using a specific image. job-local: Executed on the host running ofelia. job-service-run: Executed in a new "run-once" service, for running inside a swarm

INI-style config

[job-exec "job-executed-on-running-container"]
schedule = @hourly
container = my-container
command = touch /tmp/cfc

YAML-style config

job-executed-on-running-container:
    kind: job-exec
    schedule: "@hourly"
    container: my-container
    command: touch /tmp/cfc

Label-based config

docker run -it --rm \
  --label cfc.job-run.my-test-job.schedule="@every 5s" \
  --label cfc.job-run.my-test-job.command="echo Hello world" \
  alpine:latest sleep 9999

Ofelia compatibility

Add --ofelia to the command-line when running cfc to run in compatibility mode.

Note

Though both an executable and a library are made available, the library is only intended for consumption by the executable and its API should not be considered stable.

Dependencies

~14–27MB
~373K SLoC