From 155c443167a2f39941475408b32ea63b8838d6a7 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Sat, 13 Aug 2022 22:58:13 -0600 Subject: [PATCH] Add include and exclude --- deploy-system.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/deploy-system.py b/deploy-system.py index 354c80fe..86e56e8a 100644 --- a/deploy-system.py +++ b/deploy-system.py @@ -5,6 +5,16 @@ import argparse from decouple import config from python_on_whales import DockerClient +def include_exclude_check(s, args): + if args.include == None and args.exclude == None: + return True + if args.include != None: + include_list = args.include.split(",") + return s in include_list + if args.exclude != None: + exclude_list = args.exclude.split(",") + return s not in exclude_list + parser = argparse.ArgumentParser( description="deploy the complete stack" ) @@ -12,8 +22,9 @@ parser.add_argument("--verbose", action="store_true", help="increase output verb parser.add_argument("--quiet", action="store_true", help="don\'t print informational output") parser.add_argument("--check-only", action="store_true", help="looks at what\'s already there and checks if it looks good") parser.add_argument("--dry-run", action="store_true", help="don\'t do anything, just print the commands that would be executed") -parser.add_argument("--exclude", type=str, help="don\'t start these components") -parser.add_argument("--include", type=str, help="only start these components") +group = parser.add_mutually_exclusive_group() +group.add_argument("--exclude", type=str, help="don\'t start these components") +group.add_argument("--include", type=str, help="only start these components") args = parser.parse_args() @@ -32,10 +43,15 @@ if verbose: compose_files = [] for cluster in clusters: - compose_file_name = os.path.join("compose", f"docker-compose-{cluster}.yml") - compose_files.append(compose_file_name) + if include_exclude_check(cluster, args): + compose_file_name = os.path.join("compose", f"docker-compose-{cluster}.yml") + compose_files.append(compose_file_name) + else: + if not quiet: + print(f"Excluding: {cluster}") -print(f"files: {compose_files}") +if verbose: + print(f"files: {compose_files}") # See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/ docker = DockerClient(compose_files=compose_files)