feat: enhance logging
- remove `*` from stack log entry - prefix log messages with arrow symbol for better readability
This commit is contained in:
parent
f889ff5050
commit
3bf7fc2255
2 changed files with 12 additions and 8 deletions
5
dc-ops
5
dc-ops
|
@ -47,7 +47,7 @@ for stack in cfg["stacks"]:
|
|||
|
||||
# header
|
||||
stackdir = stack["dir"]
|
||||
log.info(f"* processing {stackdir}")
|
||||
log.info(f"processing: {stackdir}")
|
||||
|
||||
# update repo and check for new commits
|
||||
if not update_git_repo(stackdir, args.ignore_git_status):
|
||||
|
@ -55,6 +55,7 @@ for stack in cfg["stacks"]:
|
|||
|
||||
# run pre-command
|
||||
if "pre" in stack:
|
||||
log.info("-> executing pre-command")
|
||||
if not run_subprocess(stack["pre"], stackdir):
|
||||
continue
|
||||
|
||||
|
@ -62,6 +63,7 @@ for stack in cfg["stacks"]:
|
|||
# (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,
|
||||
|
@ -70,5 +72,6 @@ for stack in cfg["stacks"]:
|
|||
|
||||
# run post-command
|
||||
if "post" in stack:
|
||||
log.info("-> executing post-command")
|
||||
if not run_subprocess(stack["post"], stackdir):
|
||||
continue
|
||||
|
|
|
@ -16,9 +16,9 @@ def do_selfupdate():
|
|||
log.error(str(e))
|
||||
return
|
||||
if pull_res.old_commit:
|
||||
log.info("selfupdate: successfully updated myself - exiting")
|
||||
log.info("SelfUpdate: successfully updated myself - exiting")
|
||||
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:
|
||||
|
@ -49,11 +49,12 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
|
|||
Returns:
|
||||
bool: False if any step fails
|
||||
"""
|
||||
|
||||
# create repo instance if it exists
|
||||
try:
|
||||
repo = git.Repo(repo_path)
|
||||
except git.exc.NoSuchPathError:
|
||||
log.error("directory not found")
|
||||
log.error("-> directory not found")
|
||||
return False
|
||||
|
||||
if not ignore_git_status:
|
||||
|
@ -61,19 +62,19 @@ def update_git_repo(repo_path: str, ignore_git_status: bool) -> bool:
|
|||
try:
|
||||
fetch_res = repo.remotes.origin.fetch()[0]
|
||||
except git.exc.GitCommandError as e:
|
||||
log.error(str(e))
|
||||
log.error("-> " + str(e))
|
||||
return False
|
||||
|
||||
# check for new commits
|
||||
if not fetch_res.old_commit:
|
||||
log.info("no changes - skipping")
|
||||
log.info("-> no changes - skipping")
|
||||
return False
|
||||
|
||||
# pull remote changes to local branch
|
||||
try:
|
||||
log.info(repo.git.pull())
|
||||
log.info("-> " + repo.git.pull())
|
||||
except git.exc.GitCommandError as e:
|
||||
log.error(str(e))
|
||||
log.error("-> " + str(e))
|
||||
return False
|
||||
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue