feat: add pre and post commands support
- add pre-command execution before running docker compose
- add post-command execution after running docker compose
- update config.yml.example to include pre and post commands
🤖
This commit is contained in:
parent
18cce050e2
commit
4ee278dd86
2 changed files with 29 additions and 0 deletions
|
@ -9,4 +9,7 @@ stacks:
|
||||||
- subdirA/docker-compose.yml
|
- subdirA/docker-compose.yml
|
||||||
- subdirB/docker-compose.yml
|
- subdirB/docker-compose.yml
|
||||||
- dir: /path/to/fourth-repo
|
- dir: /path/to/fourth-repo
|
||||||
|
pre: "make"
|
||||||
|
post: "make clean"
|
||||||
|
- dir: /path/to/fifth-repo
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
26
dc-ops
26
dc-ops
|
@ -57,6 +57,18 @@ for stack in cfg["stacks"]:
|
||||||
log.error(str(e))
|
log.error(str(e))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# run pre-command
|
||||||
|
if "pre" in stack:
|
||||||
|
try:
|
||||||
|
subprocess.run(
|
||||||
|
stack["pre"],
|
||||||
|
cwd=stackdir,
|
||||||
|
shell=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
continue
|
||||||
|
|
||||||
# run `docker compose` for all compose-files
|
# run `docker compose` for all compose-files
|
||||||
# (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"])
|
||||||
|
@ -70,3 +82,17 @@ for stack in cfg["stacks"]:
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# run post-command
|
||||||
|
if "post" in stack:
|
||||||
|
try:
|
||||||
|
print(
|
||||||
|
subprocess.run(
|
||||||
|
stack["post"],
|
||||||
|
cwd=stackdir,
|
||||||
|
shell=True,
|
||||||
|
text=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
continue
|
||||||
|
|
Loading…
Reference in a new issue