feat: enhance logging

- remove `*` from stack log entry
- prefix log messages with arrow symbol for better readability
This commit is contained in:
Sebastian Mark 2023-12-22 22:22:02 +01:00
parent f889ff5050
commit 3bf7fc2255
2 changed files with 12 additions and 8 deletions

5
dc-ops
View file

@ -47,7 +47,7 @@ for stack in cfg["stacks"]:
# header # header
stackdir = stack["dir"] stackdir = stack["dir"]
log.info(f"* processing {stackdir}") log.info(f"processing: {stackdir}")
# update repo and check for new commits # update repo and check for new commits
if not update_git_repo(stackdir, args.ignore_git_status): if not update_git_repo(stackdir, args.ignore_git_status):
@ -55,6 +55,7 @@ for stack in cfg["stacks"]:
# run pre-command # run pre-command
if "pre" in stack: if "pre" in stack:
log.info("-> executing pre-command")
if not run_subprocess(stack["pre"], stackdir): if not run_subprocess(stack["pre"], stackdir):
continue continue
@ -62,6 +63,7 @@ for stack in cfg["stacks"]:
# (or just for the directory if no compose-file defined) # (or just for the directory if no compose-file defined)
composefiles = stack.get("compose-files", ["docker-compose.yml"]) composefiles = stack.get("compose-files", ["docker-compose.yml"])
for composefile in composefiles: for composefile in composefiles:
log.info(f"-> bringing up {composefile}")
if not run_subprocess( if not run_subprocess(
f"docker compose --file {composefile} up --detach {composeopts}", f"docker compose --file {composefile} up --detach {composeopts}",
stackdir, stackdir,
@ -70,5 +72,6 @@ for stack in cfg["stacks"]:
# run post-command # run post-command
if "post" in stack: if "post" in stack:
log.info("-> executing post-command")
if not run_subprocess(stack["post"], stackdir): if not run_subprocess(stack["post"], stackdir):
continue continue

View file

@ -16,9 +16,9 @@ def do_selfupdate():
log.error(str(e)) log.error(str(e))
return return
if pull_res.old_commit: if pull_res.old_commit:
log.info("selfupdate: successfully updated myself - exiting") log.info("SelfUpdate: successfully updated myself - exiting")
sys.exit(0) sys.exit(0)
log.info("selfupdate: no updates found for myself") log.info("SelfUpdate: no updates found for myself")
def run_subprocess(command: str, workdir: str) -> bool: def run_subprocess(command: str, workdir: str) -> bool:
@ -49,11 +49,12 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
Returns: Returns:
bool: False if any step fails bool: False if any step fails
""" """
# create repo instance if it exists # create repo instance if it exists
try: try:
repo = git.Repo(repo_path) repo = git.Repo(repo_path)
except git.exc.NoSuchPathError: except git.exc.NoSuchPathError:
log.error("directory not found") log.error("-> directory not found")
return False return False
if not ignore_git_status: if not ignore_git_status:
@ -61,19 +62,19 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
try: try:
fetch_res = repo.remotes.origin.fetch()[0] fetch_res = repo.remotes.origin.fetch()[0]
except git.exc.GitCommandError as e: except git.exc.GitCommandError as e:
log.error(str(e)) log.error("-> " + str(e))
return False return False
# check for new commits # check for new commits
if not fetch_res.old_commit: if not fetch_res.old_commit:
log.info("no changes - skipping") log.info("-> no changes - skipping")
return False return False
# pull remote changes to local branch # pull remote changes to local branch
try: try:
log.info(repo.git.pull()) log.info("-> " + repo.git.pull())
except git.exc.GitCommandError as e: except git.exc.GitCommandError as e:
log.error(str(e)) log.error("-> " + str(e))
return False return False
return True return True