From 3ab192d7fe0097bf4f2a3dd49d10db0fdbb60be1 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Fri, 7 Oct 2022 06:48:30 -0600 Subject: [PATCH 1/2] Rename cluster -> pod --- README.md | 2 +- app/deploy_system.py | 11 ++++++----- cluster-list.txt => pod-list.txt | 0 3 files changed, 7 insertions(+), 6 deletions(-) rename cluster-list.txt => pod-list.txt (100%) diff --git a/README.md b/README.md index df9bc966..4c6adaf8 100644 --- a/README.md +++ b/README.md @@ -148,7 +148,7 @@ the list of container image names, while `clister-list.txt` specifies the set of Files required to build each container image are stored under `./container-build/` Files required at deploy-time are stored under `./config/` ``` -├── cluster-list.txt +├── pod-list.txt ├── compose │   ├── docker-compose-contract.yml │   ├── docker-compose-db-sharding.yml diff --git a/app/deploy_system.py b/app/deploy_system.py index 48aef089..f79595ff 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -24,9 +24,10 @@ from .util import include_exclude_check @click.command() @click.option("--include", help="only start these components") @click.option("--exclude", help="don\'t start these components") +@click.option("--cluster", help="specify a non-default cluster name") @click.argument('command') # help: command: up|down|ps @click.pass_context -def command(ctx, include, exclude, command): +def command(ctx, include, exclude, cluster, command): '''deploy a stack''' # TODO: implement option exclusion and command value constraint lost with the move from argparse to click @@ -35,16 +36,16 @@ def command(ctx, include, exclude, command): verbose = ctx.obj.verbose dry_run = ctx.obj.dry_run - with open("cluster-list.txt") as cluster_list_file: - clusters = cluster_list_file.read().splitlines() + with open("pod-list.txt") as pod_list_file: + pods = pod_list_file.read().splitlines() if verbose: - print(f'Cluster components: {clusters}') + print(f'Cluster components: {pods}') # Construct a docker compose command suitable for our purpose compose_files = [] - for cluster in clusters: + for pod in pods: if include_exclude_check(cluster, include, exclude): compose_file_name = os.path.join("compose", f"docker-compose-{cluster}.yml") compose_files.append(compose_file_name) diff --git a/cluster-list.txt b/pod-list.txt similarity index 100% rename from cluster-list.txt rename to pod-list.txt From 367de932f9e987a019126e0850b7b66d4a2c2f76 Mon Sep 17 00:00:00 2001 From: David Boreham Date: Fri, 7 Oct 2022 07:12:43 -0600 Subject: [PATCH 2/2] Clusters --- app/deploy_system.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/deploy_system.py b/app/deploy_system.py index f79595ff..7a5a417e 100644 --- a/app/deploy_system.py +++ b/app/deploy_system.py @@ -15,7 +15,9 @@ # Deploys the system components using docker-compose +import hashlib import os +import sys from python_on_whales import DockerClient import click from .util import include_exclude_check @@ -36,28 +38,37 @@ def command(ctx, include, exclude, cluster, command): verbose = ctx.obj.verbose dry_run = ctx.obj.dry_run + if cluster is None: + # Create default unique, stable cluster name from confile file path + # TODO: change this to the config file path + path = os.path.realpath(sys.argv[0]) + hash = hashlib.md5(path.encode()).hexdigest() + cluster = f"laconic-{hash}" + if verbose: + print(f"Using cluster name: {cluster}") + with open("pod-list.txt") as pod_list_file: pods = pod_list_file.read().splitlines() if verbose: - print(f'Cluster components: {pods}') + print(f'Pods: {pods}') # Construct a docker compose command suitable for our purpose compose_files = [] for pod in pods: - if include_exclude_check(cluster, include, exclude): - compose_file_name = os.path.join("compose", f"docker-compose-{cluster}.yml") + if include_exclude_check(pod, include, exclude): + compose_file_name = os.path.join("compose", f"docker-compose-{pod}.yml") compose_files.append(compose_file_name) else: if not quiet: - print(f"Excluding: {cluster}") + print(f"Excluding: {pod}") if verbose: print(f"files: {compose_files}") # See: https://gabrieldemarmiesse.github.io/python-on-whales/sub-commands/compose/ - docker = DockerClient(compose_files=compose_files) + docker = DockerClient(compose_files=compose_files, compose_project_name=cluster) if not dry_run: if command == "up":