Sebastian Mark
3bf7fc2255
- remove `*` from stack log entry - prefix log messages with arrow symbol for better readability
77 lines
2.2 KiB
Python
Executable file
77 lines
2.2 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 argparse
|
|
import logging as log
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
from lib.helper import run_subprocess, update_git_repo, do_selfupdate
|
|
|
|
# read config file
|
|
configfile = Path(__file__).with_name("config.yml")
|
|
with configfile.open("r") as f:
|
|
cfg = yaml.safe_load(f.read())
|
|
|
|
# fmt: off
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--ignore-git-status", action="store_true", help="continue even if there are no new commits") # noqa
|
|
parser.add_argument("--loglevel", help="set loglevel (overrides config file)")
|
|
args = parser.parse_args()
|
|
# fmt: on
|
|
|
|
# init logging
|
|
loglevel = cfg.get("loglevel", "INFO").upper()
|
|
if args.loglevel:
|
|
loglevel = args.loglevel
|
|
log.basicConfig(format="%(message)s", level=loglevel)
|
|
|
|
# define docker compose parameters
|
|
composeopts = cfg.get("compose-opts", "")
|
|
|
|
# check for updates of myself
|
|
allow_self_update = cfg.get("self-update", False)
|
|
if allow_self_update:
|
|
do_selfupdate()
|
|
|
|
# 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, args.ignore_git_status):
|
|
continue
|
|
|
|
# run pre-command
|
|
if "pre" in stack:
|
|
log.info("-> executing pre-command")
|
|
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:
|
|
log.info(f"-> bringing up {composefile}")
|
|
if not run_subprocess(
|
|
f"docker compose --file {composefile} up --detach {composeopts}",
|
|
stackdir,
|
|
):
|
|
pass
|
|
|
|
# run post-command
|
|
if "post" in stack:
|
|
log.info("-> executing post-command")
|
|
if not run_subprocess(stack["post"], stackdir):
|
|
continue
|