2023-12-19 09:55:34 +00:00
# Docker Compose GitOps (dc-ops)
2023-12-15 19:49:46 +00:00
2023-12-19 09:55:34 +00:00
`dc-ops` is a simple python script that automates the update and deployment of multiple Docker Compose applications.
2023-12-15 19:49:46 +00:00
## How does it work?
2023-12-19 09:55:34 +00:00
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.
2023-12-15 19:49:46 +00:00
2023-12-19 09:55:34 +00:00
## Features
- Automatically checks for updates in git repositories
- Supports multiple Docker Compose files per repository
- Can be configured to skip certain repositories
2023-12-15 19:49:46 +00:00
2023-12-19 09:55:34 +00:00
## Requirements
See `requirements.txt`
2023-12-15 19:49:46 +00:00
## Usage
2023-12-19 09:55:34 +00:00
1. Install the required Python packages: `pip install -r requirements.txt`
2. Adapt `config.yml.example` to your needs and save it as `config.yml`
3. Run `dc-ops` from the shell or from a cron job
2023-12-15 19:49:46 +00:00
2024-01-05 21:13:36 +00:00
### 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)
2024-09-01 18:16:09 +00:00
### Systemd
Recommended systemd usage:
```toml
# /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
```
```toml
# /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 dc-ops.timer
systemctl start dc-ops.timer
```
2023-12-21 14:54:55 +00:00
## Parameters
See `dc-ops --help`
2023-12-19 21:24:51 +00:00
## 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 to `dir` ) to docker-compose files. Uses `["docker-compose.yml"]` by default if not set.
- `enabled` : (optional) `false` if this repository should be skipped. Defaults to `true` if not set.
2023-12-21 18:15:58 +00:00
- `pre` : (optional) a command to be run before `docker compose up` , executed in `dir` .
- `post` : (optional) a command to be run after `docker compose up` , executed in `dir` .
- `compose-opts` : (optional) define additional parameters to `docker compose up -d` .
- `loglevel` : (optional) define loglevel. Defaults to "INFO" if not set.
- `self-update` : (optional) update this script on startup. Defaults to `false` .
2023-12-19 21:24:51 +00:00
2023-12-19 09:55:34 +00:00
## Detailed process
For each enabled stack in the config file, the following process will be executed:
1. Checking directory existence
2. Fetching latest changes from remote repository
3. If there is a new commit, it will pull the changes
4. Running Docker Compose with the defined or default compose-file(s)