Skip to content
 
 

Repository files navigation

Auto-Committer

The Auto-Committer is a Dockerized Python application designed to automatically commit and push changes to a Git repository at regular intervals. This tool helps keep repositories up to date without manual intervention ensuring that your codebase remains current with minimal effort. This version has been extended to offer a few additional features from the forked version.

Contents

Features

  • Automatic Commits: Regularly commits and pushes changes to a specified Git repository LAB_REPO_NAME.
  • Configurable Intervals: Allows you to set the interval at which commits are made COMMIT_INTERVAL_SECONDS.
  • Logging: Keeps track of commit activities and errors in a log file LAB_LOG_FILE_PATH.
  • Dockerized: Easily deployable with Docker and Docker Compose.

NEW: Use AUTO_COMMIT_PATTERNS to specify which files to track, or leave it unset to commit everything!

REMOVED: COMMIT_SPECIFIC_DIRECTORY as option clashed with AUTO_COMMIT_PATTERNS pattern matching and deemed redundant.

Install

Installation via Docker Compose

Quick Start

  1. Setup Git repository :
   cd /path/to/your/repo
   git init
   git remote add origin https://github.com/yourusername/yourrepo.git
  1. Create docker project directory:
   mkdir auto-committer && cd auto-committer
  1. Create compose.yaml:
  services:
    auto-committer:
      container_name: auto-committer
      image: ghcr.io/iamdabe/auto-committer:latest
      restart: unless-stopped
      ports:
        - "5009:5009"
      env_file:
        - .env
      volumes:
        - /path/to/your/repo:/repo
  1. Create .env file:
   # Required
   AUTO_COMMIT_REPO_PATH=/repo
   GITHUB_TOKEN=github_pat_token
   LAB_REPO_OWNER=github_repo_owners_username
   LAB_REPO_NAME=github_reponame
   USEREMAIL=you@example.com
   USERNAME=github_username
   
   # Optional
   COMMITTER=MYSERVER
   COMMIT_INTERVAL_SECONDS=300
   AUTO_COMMIT_PATTERNS=
  1. Deploy:
   docker compose up -d

Building from Source

If you prefer to build locally:

  services:
    auto-committer:
      build: .
      container_name: auto-committer
      restart: unless-stopped
      ports:
        - "5009:5009"
      env_file:
        - .env
      volumes:
        - /path/to/your/repo:/repo

Then run:

docker compose up -d --build

Volume Configuration

The AUTO_COMMIT_REPO_PATH environment variable should point to the mount point inside the container, not the host path.

Default: /repo (recommended)

volumes:
  - /host/path/to/your/repo:/repo  # Maps host path to /repo in container
  
# Then in .env:
AUTO_COMMIT_REPO_PATH=/repo  # Uses the container path

Environment Variables

Required Variables

AUTO_COMMIT_REPO_PATH=/repo              # Path to git repository inside container
GITHUB_TOKEN=ghp_pap_your_token          # Github personal access token
LAB_REPO_OWNER=your_git_username         # Github repository owner
LAB_REPO_NAME=your_git_reponame          # Github repository name
USEREMAIL=you@example.com                # Github committer email
USERNAME=Your Name                       # Github committer name

Optional Variables

# Committer identifier for commit messages (default: 'AUTO')
COMMITTER=MYSERVER

# Interval between checks in seconds (default: 300 = 5 minutes)
COMMIT_INTERVAL_SECONDS=300

# Log file path (default: /tmp/auto_committer.log)
LAB_LOG_FILE_PATH=/var/log/auto_committer.log

# File patterns to monitor (comma-separated glob patterns)
# If NOT SET or COMMENTED OUT: Commits ALL changes (default behavior)
# If SET: Only commits files matching these patterns
# Examples:
#   Only Docker Compose files:
#     AUTO_COMMIT_PATTERNS=*/compose.yaml,*/.env
AUTO_COMMIT_PATTERNS=

Pattern Usage Examples

In your .env:

Example 1: Commit Everything (Default Behavior)

 AUTO_COMMIT_PATTERNS=   ← Leave unset or comment out

Result: Commits all changes in the repository (like git add --all)

Example 2: Only Docker Compose and .env files in subfolders (for compose stack backup versioning)

AUTO_COMMIT_PATTERNS=*/compose.yaml,*/.env

Result: Only tracks compose.yaml and .env files in any subdirectory

Example 3: Specific File Types

AUTO_COMMIT_PATTERNS=*.py,*.js,*.md

Result: Only tracks Python, JavaScript, and Markdown files

Example 4: Multiple Patterns

AUTO_COMMIT_PATTERNS=*/Dockerfile,*/compose.yaml,*/.env,*.md

Result: Tracks Dockerfiles, compose files, .env files, and markdown files

Example 5: Specific Directories

AUTO_COMMIT_PATTERNS=configs/*,scripts/*.sh

Result: Only tracks files in configs/ dir and .sh files in scripts/ dir

Pattern Syntax

Uses Python's glob patterns:

  • * - matches any characters in a single directory level
  • ** - matches any characters across multiple directory levels
  • ? - matches a single character
  • [abc] - matches any character in brackets

Examples:

# Single level wildcard
*.txt                    # All .txt files in root
*/config.yaml           # config.yaml in any immediate subdirectory

# Recursive wildcard  
**/*.py                 # All .py files in any subdirectory (any depth)

# Multiple patterns (comma-separated)
*.md,*.txt              # All markdown and text files

# Specific paths
docker/*/compose.yaml   # compose.yaml files in docker subdirectories

How It Works

With Patterns Set:

  1. Scans repository for files matching your patterns
  2. Only adds matching files with git add <file>
  3. git commit and pushes only those files

Without Patterns (Default):

  1. Runs git add --all
  2. git commit and pushes all changes

Don't ignore .gitignore

This script does not override your .gitignore file - Git's ignore rules are still respected. It's best practice to maintain a .gitignore file in your repository to prevent sensitive files, logs and unwanted data from being accidentally committed even when using pattern filtering.

Important Notes

  • Patterns are case-sensitive
  • The .git directory is always excluded
  • If patterns don't match any files, nothing will be committed
  • Patterns use forward slashes / even on Windows
  • Multiple patterns are OR'd together (any match qualifies)

Troubleshooting

  1. Ensure Docker and Docker Compose are installed and running.
  2. Verify that the .env file is correctly configured.
  3. Check the log file specified by LAB_LOG_FILE_PATH for any errors.

License

This project is licensed under the Apache License. See the LICENSE file for details.

Forked from hanisntsolo/auto-committer.

About

The Auto-Committer is a Dockerized Python application designed to automatically commit and push changes to a Git repository at regular intervals. This tool helps in keeping repositories up-to-date without manual intervention, ensuring that your codebase remains current with minimal effort.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages