Skip to content
/ cd-gun Public

A lightweight, universal CD/GitOps service for deploying anything to anywhere. CD-Gun is a systemd-based agent that monitors git repositories and executes actions when changes are detected.

License

Notifications You must be signed in to change notification settings

omnorm/cd-gun

CD-Gun: Universal CD/GitOps Agent

License Go Version

A lightweight, universal CD/GitOps service for deploying anything to anywhere. CD-Gun is a systemd-based agent that monitors git repositories and executes actions when changes are detected.

Status: πŸš€ v0.1.1 (Early Development)

About

This project was developed with the assistance of GitHub Copilot. While the concept, architecture, design decisions, and comprehensive testing were provided by the project author, the implementation code was generated and refined using AI assistance. This approach demonstrates modern collaborative development practices combining human creativity with AI-powered code generation.

Features

  • 🌍 Universal: Works with any git-compatible repository (GitHub, GitLab, Gitea, self-hosted, etc.)
  • πŸ”§ Flexible: Define custom actions in shell scripts
  • πŸͺΆ Lightweight: ~6MB binary, minimal resource usage
  • πŸ”Œ Independent: No dependencies on Kubernetes, Docker, or specific platforms
  • πŸ“‹ Simple: Easy to configure with YAML
  • πŸ›‘οΈ Secure: Runs as unprivileged systemd service

Quick Start

Installation

git clone https://github.com/omnorm/cd-gun.git
cd cd-gun

make build
sudo make install

# Start the service
systemctl start cd-gun

Basic Usage

  1. Create a config file /etc/cd-gun/config.yaml:
agent:
  name: "cd-gun-agent"
  log_level: "info"
  log_file: "/var/log/cd-gun.log"  # Optional: omit to log to stdout/journalctl
  state_dir: "/var/lib/cd-gun"
  cache_dir: "/var/cache/cd-gun/repos"
  poll_interval: "5m"

repositories:
  - name: "my-app"
    url: "https://github.com/myorg/app.git"
    branch: "main"
    watch_paths:
      - "src/"
      - "package.json"
    poll_interval: "5m"
    action:
      type: "shell"
      script: "/opt/cd-gun/scripts/deploy.sh"
      timeout: "10m"
  1. Create a deployment script /opt/cd-gun/scripts/deploy.sh:
#!/bin/bash
set -e

echo "Deploying $CDGUN_REPO_NAME from $CDGUN_OLD_HASH to $CDGUN_NEW_HASH"

cd "$CDGUN_REPO_PATH"
npm ci
npm run build
rsync -av dist/ /var/www/app/
systemctl reload nginx

echo "Deployment successful!"
  1. Check status:
systemctl status cd-gun
journalctl -u cd-gun -f

Environment Variables for Scripts

When executing your deployment scripts, CD-Gun provides these variables:

Variable Description
CDGUN_REPO_NAME Repository name from config
CDGUN_REPO_URL Repository URL
CDGUN_REPO_PATH Local cache path
CDGUN_BRANCH Branch being monitored
CDGUN_CHANGED_FILES Changed files (comma-separated)
CDGUN_OLD_HASH Previous commit hash
CDGUN_NEW_HASH Current commit hash

Full reference: docs/ENVIRONMENT_VARIABLES.md

Control Signals

# Reload configuration
kill -HUP $(pgrep cd-gun-agent)

# Force check all repositories
kill -USR1 $(pgrep cd-gun-agent)

# Graceful shutdown
systemctl stop cd-gun

Build & Development

# Build
make build

# Run locally for testing
./bin/cd-gun-agent -config examples/simple-deploy.yaml -log-level debug

# Run tests
make test

# Clean
make clean

Project Structure

cmd/cd-gun-agent/      # Application entry point
internal/
β”œβ”€β”€ app/                # Main application & event loop
β”œβ”€β”€ config/             # Configuration management
β”œβ”€β”€ executor/           # Action execution
β”œβ”€β”€ monitor/            # Repository monitoring
β”œβ”€β”€ state/              # State management
└── logger/             # Logging
examples/               # Example configurations
deployments/            # systemd service file
docs/                   # Documentation

Documentation

Common Use Cases

  • Web application deployment β€” Auto-deploy on git push
  • Configuration management β€” Auto-update service configs
  • Multi-repo coordination β€” Monitor and sync multiple repositories
  • Custom deployment pipelines β€” Run any shell script on changes

Compared to Alternatives

If you're wondering how CD-Gun compares to other tools:

Tool Best For vs CD-Gun
Argo CD / Flux Kubernetes clusters CD-Gun is simpler, works on plain servers without K8s
Jenkins / GitHub Actions Full CI/CD pipelines CD-Gun is lighter, uses pull model instead of webhooks
Ansible pull Config management Similar pull-based approach, but CD-Gun is script-agnostic
Webhook services Git β†’ script execution CD-Gun polls instead of requiring open webhooks; works with private networks

CD-Gun is best for: Single/multiple servers, simple deployments, no K8s, minimal dependencies, custom bash-based workflows.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License β€” see the LICENSE file for details.

Copyright (c) 2025 Permishen Denaev

About

A lightweight, universal CD/GitOps service for deploying anything to anywhere. CD-Gun is a systemd-based agent that monitors git repositories and executes actions when changes are detected.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks