Skip to content

Commit

Permalink
Update README.md (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tosfos authored Oct 22, 2024
1 parent 6eb7918 commit 2fd1bc9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 13 deletions.
76 changes: 63 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Wikiteq cron docker image
# WikiTeq Cron Docker Image

It is a Docker-based job scheduler that allows you to define and run cron jobs in Docker containers.
It uses https://github.com/aptible/supercronic as the job runner
<div align="center">
<img src="WikiTeq-docker-cron.webp" alt="WikiTeq Cron Mascot" width="300">
</div>

Key Features:
- **Cron-Like Syntax**: Similar to traditional cron jobs, you can define the schedule for each task using cron-like syntax.
- **Easy Configuration**: It uses the docker labels where you can define all your jobs.
- **Logging**: It provides logging of all job executions, making it easy to monitor and debug.
This is a Docker-based job scheduler that allows you to define and run cron jobs in Docker containers. It uses [Supercronic](https://github.com/aptible/supercronic) as the job runner to provide a flexible, reliable, and easy-to-configure cron experience.

## Example
## Key Features
- **Cron-Like Syntax**: Define and schedule tasks using familiar cron syntax.
- **Easy Configuration**: Define all your jobs using Docker labels, making configuration straightforward.
- **Logging**: Provides logging for all job executions, making monitoring and debugging simple.

## Getting Started

To start using this Docker image, you can create a `docker-compose.yml` configuration as shown in the example below.

### Example `docker-compose.yml`
```yaml
docker-compose.yml:

services:
cron:
image: ghcr.io/wikiteq/cron
Expand All @@ -31,12 +39,54 @@ services:
- cron.another_task.schedule="*/2 * * * *"
- cron.another_task.command="/usr/local/bin/another_app_script.sh"
```
This example shows how to schedule multiple cron jobs using cron syntax. The Docker container will run `/usr/local/bin/app_script.sh` every minute and `/usr/local/bin/another_app_script.sh` every two minutes, with logs stored in `/var/log/cron/`.

### Environment Variables
The `example_compose.yml` file uses several environment variables. Make sure to define these in a `.env` file in the root directory of your project:
- **`COMPOSE_PROJECT_NAME`**: Specifies the name of the Docker Compose project, allowing the cron to target jobs in that specific project. **Note**: If `COMPOSE_PROJECT_NAME` is not defined, the cron container will process jobs from *all* Docker Compose stacks on the computer. In this scenario, cron jobs may be executed multiple times if multiple cron containers are running without `COMPOSE_PROJECT_NAME` defined.
- **`DEBUG`**: Set to `true` to enable detailed output for debugging purposes.
- **`CRON_LOG_DIR`**: Defines the directory where cron stores log files for executed jobs, defaulting to `/var/log/cron`.
- **`TZ`**: The timezone used for scheduling cron jobs

### Volume Mounts
- **`/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.

## 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.

## Managing Cron Jobs

The image comes with several scripts to manage cron jobs:

- **`functions.sh`**: Contains helper functions for script operations.
- **`startup.sh`**: This script runs at container startup to initialize all required settings and start cron jobs.
- **`update_cron.sh`**: Used for updating cron jobs dynamically without restarting the container.

## Building and Running the Image

Pre-built Docker images are available for direct use. In the example, we use the latest version of the image: `ghcr.io/wikiteq/cron`. You can find all available images at: [WikiTeq Docker Cron Packages](https://github.com/WikiTeq/docker-cron/pkgs/container/cron).

To build the Docker image, use the following command:

```bash
docker build -t wikiteq/cron .
```
To run the Docker container, use:
```bash
docker run -d --name cron wikiteq/cron
```

Make sure to properly configure environment variables and volume mounts to suit your needs.

## Contributing
If you want to contribute to this project, please feel free to submit a pull request or open an issue on [GitHub](https://github.com/WikiTeq/docker-cron).

## Future Improvements
- **Non-Root User**: Modify the Dockerfile to run the container as a non-root user to enhance security and reduce potential risks.
- **Automated Testing**: Implement automated unit and integration testing to ensure code reliability and prevent issues during deployment.
- **Health Check Endpoint**: Add a health check mechanism to verify that cron jobs are running correctly and that the container is in a healthy state.

- `COMPOSE_PROJECT_NAME`: if defined, the cron looks for the jobs in this compose project only
- `DEBUG`: when it is `true`, it outputs more iformation for debugging
- `CRON_LOG_DIR`: the directory where cron puts the log files of the executed jobs, `/var/log/cron` by default
- `TZ` timezone used for scheduling the cron jobs
## Contact
For any questions or support, contact the maintainers at contact@wikiteq.com.
Binary file added WikiTeq-docker-cron.webp
Binary file not shown.

0 comments on commit 2fd1bc9

Please sign in to comment.