compose-sync#
A tool to automatically sync and deploy Docker Compose stacks from a git repository, with multi-host support.
Overview#
compose-sync pulls changes from a git repository containing Docker Compose files and only deploys stacks that:
- Have changed since the last pull
- Are assigned to the current host
Repository Structure#
Your git repository should have the following structure:
stacks/
traefik/compose.yml
uptime-kuma/compose.yml
home-assistant/compose.yml
...
inventory.yml
The inventory.yml file at the root contains all hosts and their assigned stacks. For example:
hosts:
vps-1:
- traefik
- uptime-kuma
nas-1:
- home-assistant
- nextcloud
This format is compatible with Ansible inventory structures and provides a centralized view of all host assignments.
Installation#
go install github.com/aottr/compose-sync@latest
Alternatively build from source#
- Clone this repository
- Build the application:
go build -o compose-sync
Configuration#
- Copy
config.yml.exampletoconfig.yml - Edit
config.ymland setrepo_pathto the local path of your git repository
Usage#
Basic Usage#
./compose-sync
This will:
- Detect the current hostname
- Pull the latest changes from git
- Find changed stacks
- Deploy only changed stacks assigned to this host
Dry Run#
To see what would be deployed without actually deploying:
./compose-sync -dry-run
Custom Config Path#
./compose-sync -config /path/to/config.yml
How It Works#
- Host Detection: The tool uses the system hostname to identify the current host
- Stack Assignment: Reads
inventory.ymlto determine which stacks should be deployed on this host - Change Detection: Compares git commits before and after pulling to find changed stacks
- Selective Deployment: Only deploys stacks that both changed AND are assigned to this host
Requirements#
- Go 1.21 or later
- Git
- Docker and Docker Compose
- A git repository with the structure described above
License#
MIT