diff --git a/config.yml.example b/config.yml.example index 4cb1875..b1ff0b4 100644 --- a/config.yml.example +++ b/config.yml.example @@ -9,4 +9,7 @@ stacks: - subdirA/docker-compose.yml - subdirB/docker-compose.yml - dir: /path/to/fourth-repo + pre: "make" + post: "make clean" + - dir: /path/to/fifth-repo enabled: false diff --git a/dc-ops b/dc-ops index 4db1d61..6cf6a04 100755 --- a/dc-ops +++ b/dc-ops @@ -57,6 +57,18 @@ for stack in cfg["stacks"]: log.error(str(e)) 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 # (or just for the directory if no compose-file defined) composefiles = stack.get("compose-files", ["docker-compose.yml"]) @@ -70,3 +82,17 @@ for stack in cfg["stacks"]: ) except subprocess.CalledProcessError: pass + + # run post-command + if "post" in stack: + try: + print( + subprocess.run( + stack["post"], + cwd=stackdir, + shell=True, + text=True, + ) + ) + except subprocess.CalledProcessError: + continue