a poor man's gitops
- add missing newlines for better readability - ensure consistent indentation in list items - update `systemctl` timer enable/start command |
||
|---|---|---|
| lib | ||
| .gitignore | ||
| config.yml.example | ||
| dc-ops | ||
| README.md | ||
| requirements.txt | ||
Docker Compose GitOps (dc-ops)
dc-ops is a simple python script that automates the update and deployment of multiple Docker Compose applications.
How does it work?
It reads a list of git repositories from a YAML configuration file (config.yml), pulls the latest changes for each repo, and runs docker compose up for each specified docker-compose.yml file.
Features
- Automatically checks for updates in git repositories
- Supports multiple Docker Compose files per repository
- Can be configured to skip certain repositories
Requirements
See requirements.txt
Usage
- Install the required Python packages:
pip install -r requirements.txt - Adapt
config.yml.exampleto your needs and save it asconfig.yml - Run
dc-opsfrom the shell or from a cron job
Cron
Recommended crontab usage:
*/15 * * * * python3 /opt/dc-ops/dc-ops 2>&1 | ts "\%FT\%H:\%M:\%S" >>/var/log/dc-ops.log
(do not forget logrotate)
Systemd
Recommended systemd usage:
# /etc/systemd/system/dc-ops.service
[Unit]
Description=Run dc-ops once
After=docker.target
[Service]
Type=simple
WorkingDirectory=/opt/dc-ops/
ExecStart=python3 dc-ops
# /etc/systemd/system/dc-ops.timer
[Unit]
Description=Start dc-ops service periodically
[Timer]
Persistent=true
OnCalendar=*:0/15
Unit=dc-ops.service
[Install]
WantedBy=timers.target
Enable and start the timer:
systemctl enable --now dc-ops.timer
Parameters
See dc-ops --help
Configuration Options
stacks: an array containing details for each repository. Each element is a dictionary containing the following keys:dir: the directory of the repository on your local machine.compose-files: (optional) array of paths (relative todir) to docker-compose files. Uses["docker-compose.yml"]by default if not set.enabled: (optional)falseif this repository should be skipped. Defaults totrueif not set.pre: (optional) a command to be run beforedocker compose up, executed indir.post: (optional) a command to be run afterdocker compose up, executed indir.
compose-opts: (optional) define additional parameters todocker compose up -d.loglevel: (optional) define loglevel. Defaults to "INFO" if not set.self-update: (optional) update this script on startup. Defaults tofalse.
Detailed process
For each enabled stack in the config file, the following process will be executed:
- Checking directory existence
- Fetching latest changes from remote repository
- If there is a new commit, it will pull the changes
- Running Docker Compose with the defined or default compose-file(s)