From 4ee278dd863f3b51eb804e3c1c6d2fc109eeca06 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Tue, 19 Dec 2023 22:24:35 +0100 Subject: [PATCH] feat: add pre and post commands support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 🤖 --- config.yml.example | 3 +++ dc-ops | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) 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