Sebastian Mark
9c1fa801e0
- add new configuration option `compose-opts` to define additional parameters
- update `README.md` to include `compose-opts` in Configuration Options
🤖
59 lines
1.6 KiB
Python
Executable file
59 lines
1.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8; py-indent-offset: 4 -*-
|
|
|
|
# Author: Sebastian Mark
|
|
# CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
|
|
# for civil use only
|
|
|
|
import logging as log
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
from lib.helper import run_subprocess, update_git_repo
|
|
|
|
# read config file
|
|
configfile = Path(__file__).with_name("config.yml")
|
|
with configfile.open("r") as f:
|
|
cfg = yaml.safe_load(f.read())
|
|
|
|
# init logging
|
|
loglevel = cfg.get("loglevel", "INFO").upper()
|
|
log.basicConfig(format="%(message)s", level=loglevel)
|
|
|
|
# define docker compose parameters
|
|
composeopts = cfg.get("compose-opts", "")
|
|
|
|
# iterate all stacks
|
|
for stack in cfg["stacks"]:
|
|
# skip disabled stacks
|
|
if "enabled" in stack and not stack["enabled"]:
|
|
continue
|
|
|
|
# header
|
|
stackdir = stack["dir"]
|
|
log.info(f"* processing {stackdir}")
|
|
|
|
# update repo and check for new commits
|
|
if not update_git_repo(stackdir):
|
|
continue
|
|
|
|
# run pre-command
|
|
if "pre" in stack:
|
|
if not run_subprocess(stack["pre"], stackdir):
|
|
continue
|
|
|
|
# run `docker compose` for all compose-files
|
|
# (or just for the directory if no compose-file defined)
|
|
composefiles = stack.get("compose-files", ["docker-compose.yml"])
|
|
for composefile in composefiles:
|
|
if not run_subprocess(
|
|
f"docker compose --file {composefile} up --detach {composeopts}",
|
|
stackdir,
|
|
):
|
|
pass
|
|
|
|
# run post-command
|
|
if "post" in stack:
|
|
if not run_subprocess(stack["post"], stackdir):
|
|
continue
|