Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
LABEL org.opencontainers.image.source=https://github.com/WikiTeq/docker-cron

# Install required tools
RUN apk add --no-cache jq curl docker-cli tzdata
RUN apk add --no-cache jq curl docker-cli tzdata bash

Check failure on line 7 in Dockerfile

View workflow job for this annotation

GitHub Actions / test

DL3018 warning: Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`

# Latest releases available at https://github.com/aptible/supercronic/releases
ENV SUPERCRONIC_URL=https://github.com/aptible/supercronic/releases/download/v0.2.32/supercronic-linux-amd64 \
Expand All @@ -28,5 +28,12 @@
COPY update_cron.sh /usr/local/bin/update_cron.sh
RUN chmod +x /usr/local/bin/update_cron.sh

COPY archive-cron-logs-functions.sh /usr/local/bin/archive-cron-logs-functions.sh
RUN chmod +x /usr/local/bin/archive-cron-logs-functions.sh

# Copy the log archiving script into the container
COPY archive-cron-logs.sh /usr/local/bin/archive-cron-logs
RUN chmod +x /usr/local/bin/archive-cron-logs

# Run the startup script at container startup
CMD ["/usr/local/bin/startup.sh"]
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This is a Docker-based job scheduler that allows you to define and run cron jobs
- **Flexible Filtering**: Supports filtering containers based on `COMPOSE_PROJECT_NAME`, space-separated filters in the `FILTER` variable, or both.
- **Easy Configuration**: Define all your jobs using Docker labels, making configuration straightforward.
- **Logging**: Provides logging for all job executions, making monitoring and debugging simple.
- **Log Archiving**: Includes an archiving utility that compacts older logs into monthly/daily/hourly/minute archives according to completeness, keeping only a configurable number of the newest logs.

## Getting Started

Expand Down Expand Up @@ -57,6 +58,26 @@ This example shows how to schedule multiple cron jobs using cron syntax. The Doc
- **`/var/run/docker.sock`**: This is used to enable the Docker client inside the container to communicate with the Docker daemon running on the host. Be careful when using this as it provides elevated privileges.
- **`./logs/cron:/var/log/cron`**: Mount a directory to store the cron logs.

## Log Archiving

The image ships with `archive-cron-logs`, a log archiving script designed for the timestamped log files produced by this image.

- **Invocation**: `archive-cron-logs <target_count>` where `target_count` is the desired number of log files per period (granularity) to trigger creating an archive. Example: `archive-cron-logs 20`.
- The script processes logs from oldest to newest and groups them by time periods (year, month, day, hour, minute, second).
- When the current period accumulates `target_count` files, an archive for that period is created, and those files are removed.
- Additional archives for adjacent periods are created so archived ranges do not intersect the active period.
- **Recent logs preservation**: The script skips the newest `target_count` log files to keep the latest logs easy to read.
- **Naming**: When all files in a group belong to the same task, the task name is appended to the archive name as shown above.

You can schedule archiving via container labels, for example in `docker-compose`:

```yaml
labels:
- cron.enabled=true
- cron.rotate_cron_logs.schedule=@daily
- cron.rotate_cron_logs.command=archive-cron-logs 20
```

## Supercronic Integration

This image uses [Supercronic](https://github.com/aptible/supercronic) to run cron jobs in a more Docker-friendly way. Supercronic provides better logging, fewer overheads, and can be easily integrated with Docker containers, making it a better alternative to the traditional `cron` utility.
Expand Down
Loading