Skip to content

Run any Python script on a custom cronjob schedule with environment-based configuration and logging.

Notifications You must be signed in to change notification settings

gurkiratm/python-cron-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ•’ Python Cron Runner

Run any Python script on a custom cron schedule with environment-based control and logging.

Docker Image: gurkiratm/python-cron

Pull command:

docker pull gurkiratm/python-cron:latest

πŸ“¦ About

This image runs any user-supplied Python script on a recurring schedule using cron, with parameters passed via environment variables. It installs dependencies at runtime and logs output to a configurable or timestamped file inside the container.


πŸš€ Features

  • βœ… Run any script via PYTHON_SCRIPT_PATH
  • βœ… Schedule via CRON_SCHEDULE (default: 0 9 * * *)
  • βœ… Logs to dynamic or custom LOG_FILE
  • βœ… Virtualenv auto-created at /app/.venv
  • βœ… Installs requirements.txt via REQUIREMENTS_FILE (default: /app/requirements.txt)
  • βœ… Lightweight Alpine base image
  • βœ… Uses busybox crond running in foreground for clean logs

πŸ”§ Environment Variables

Variable Required Description
PYTHON_SCRIPT_PATH βœ… Yes Full path to the Python script inside the container
CRON_SCHEDULE ❌ No Cron format schedule (default: 0 9 * * *)
LOG_FILE_PATH ❌ No Log file name (Default: /app/script_python_dYYYYMMDD_tHHMMSS.log)
REQUIREMENTS_FILE ❌ No Path to requirements.txt (Default: /app/requirements.txt : empty)

πŸ“ Volume Mounts

Mount your Python script and any inputs:

-v $(pwd)/scripts:/data:Z

πŸ“„ Example Usage

docker run --rm \
  -v $(pwd)/scripts:/data:Z \
  -e PYTHON_SCRIPT_PATH="/data/myscript.py" \
  -e CRON_SCHEDULE="*/10 * * * *" \
  -e REQUIREMENTS_FILE="/data/requirements.txt" \
  -e LOG_FILE_PATH="myscript.logs" \
  gurkiratm/python-cron

πŸ“ Logs

Script output will be logged to:

${LOG_FILE_PATH} if provided

Or the default: /app/script_python_dYYYYMMDD_tHHMMSS.log

To view logs:

docker exec <container-name> cat <LOG-FILE-PATH>
docker logs <container-name>

πŸ›  Build Locally

docker build -t python-cron-runner .


πŸ‘¨β€πŸ’» Maintainer

Gurkirat Singh

About

Run any Python script on a custom cronjob schedule with environment-based configuration and logging.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published