From f7eb8b9a38e324cb632c692e111f7a669b581a2d Mon Sep 17 00:00:00 2001 From: David Boreham Date: Tue, 24 Oct 2023 22:13:09 -0600 Subject: [PATCH] Rearrange files (#605) --- .gitignore | 2 +- app/base.py | 2 +- app/build/__init__.py | 0 app/{ => build}/build_containers.py | 2 +- app/{ => build}/build_npms.py | 0 .../stacks/mainnet-laconic/deploy/commands.py | 6 ++-- app/data/stacks/test/deploy/commands.py | 6 ++-- app/deploy/__init__.py | 0 app/deploy/compose/__init__.py | 0 app/{ => deploy/compose}/deploy_docker.py | 2 +- app/{ => deploy}/deploy.py | 34 +++++++++---------- app/{ => deploy}/deploy_types.py | 2 +- app/{ => deploy}/deploy_util.py | 2 +- app/{ => deploy}/deployer.py | 0 app/{ => deploy}/deployer_factory.py | 4 +-- app/{ => deploy}/deployment.py | 8 ++--- app/{ => deploy}/deployment_create.py | 4 +-- app/deploy/k8s/__init__.py | 0 app/{ => deploy/k8s}/deploy_k8s.py | 2 +- app/{ => deploy}/spec.py | 0 app/{ => deploy}/stack.py | 0 app/{ => deploy}/stack_state.py | 0 app/repos/__init__.py | 0 app/{ => repos}/setup_repositories.py | 2 +- cli.py | 10 +++--- 25 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 app/build/__init__.py rename app/{ => build}/build_containers.py (98%) rename app/{ => build}/build_npms.py (100%) create mode 100644 app/deploy/__init__.py create mode 100644 app/deploy/compose/__init__.py rename app/{ => deploy/compose}/deploy_docker.py (97%) rename app/{ => deploy}/deploy.py (92%) rename app/{ => deploy}/deploy_types.py (97%) rename app/{ => deploy}/deploy_util.py (97%) rename app/{ => deploy}/deployer.py (100%) rename app/{ => deploy}/deployer_factory.py (90%) rename app/{ => deploy}/deployment.py (95%) rename app/{ => deploy}/deployment_create.py (99%) create mode 100644 app/deploy/k8s/__init__.py rename app/{ => deploy/k8s}/deploy_k8s.py (97%) rename app/{ => deploy}/spec.py (100%) rename app/{ => deploy}/stack.py (100%) rename app/{ => deploy}/stack_state.py (100%) create mode 100644 app/repos/__init__.py rename app/{ => repos}/setup_repositories.py (98%) diff --git a/.gitignore b/.gitignore index 0e253ae4..35a9c9ec 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ __pycache__ *~ package app/data/build_tag.txt -build +/build diff --git a/app/base.py b/app/base.py index cc20da1b..ba3504ba 100644 --- a/app/base.py +++ b/app/base.py @@ -15,7 +15,7 @@ import os from abc import ABC, abstractmethod -from app.deploy import get_stack_status +from app.deploy.deploy import get_stack_status from decouple import config diff --git a/app/build/__init__.py b/app/build/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/build_containers.py b/app/build/build_containers.py similarity index 98% rename from app/build_containers.py rename to app/build/build_containers.py index 0187bb5e..ee74b807 100644 --- a/app/build_containers.py +++ b/app/build/build_containers.py @@ -52,7 +52,7 @@ def command(ctx, include, exclude, force_rebuild, extra_build_args): continue_on_error = ctx.obj.continue_on_error # See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure - container_build_dir = Path(__file__).absolute().parent.joinpath("data", "container-build") + container_build_dir = Path(__file__).absolute().parent.parent.joinpath("data", "container-build") if local_stack: dev_root_path = os.getcwd()[0:os.getcwd().rindex("stack-orchestrator")] diff --git a/app/build_npms.py b/app/build/build_npms.py similarity index 100% rename from app/build_npms.py rename to app/build/build_npms.py diff --git a/app/data/stacks/mainnet-laconic/deploy/commands.py b/app/data/stacks/mainnet-laconic/deploy/commands.py index 3a62b42d..030200f1 100644 --- a/app/data/stacks/mainnet-laconic/deploy/commands.py +++ b/app/data/stacks/mainnet-laconic/deploy/commands.py @@ -14,9 +14,9 @@ # along with this program. If not, see . from app.util import get_yaml -from app.deploy_types import DeployCommandContext, LaconicStackSetupCommand, DeploymentContext -from app.stack_state import State -from app.deploy_util import VolumeMapping, run_container_command +from app.deploy.deploy_types import DeployCommandContext, LaconicStackSetupCommand, DeploymentContext +from app.deploy.stack_state import State +from app.deploy.deploy_util import VolumeMapping, run_container_command from app.command_types import CommandOptions from enum import Enum from pathlib import Path diff --git a/app/data/stacks/test/deploy/commands.py b/app/data/stacks/test/deploy/commands.py index fbb9a8ea..2eebeea2 100644 --- a/app/data/stacks/test/deploy/commands.py +++ b/app/data/stacks/test/deploy/commands.py @@ -14,9 +14,9 @@ # along with this program. If not, see . from app.util import get_yaml -from app.deploy_types import DeployCommandContext -from app.stack_state import State -from app.deploy_util import VolumeMapping, run_container_command +from app.deploy.deploy_types import DeployCommandContext +from app.deploy.stack_state import State +from app.deploy.deploy_util import VolumeMapping, run_container_command from pathlib import Path default_spec_file_content = """config: diff --git a/app/deploy/__init__.py b/app/deploy/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/deploy/compose/__init__.py b/app/deploy/compose/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/deploy_docker.py b/app/deploy/compose/deploy_docker.py similarity index 97% rename from app/deploy_docker.py rename to app/deploy/compose/deploy_docker.py index 5b20d46c..03306346 100644 --- a/app/deploy_docker.py +++ b/app/deploy/compose/deploy_docker.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from python_on_whales import DockerClient, DockerException -from app.deployer import Deployer, DeployerException +from app.deploy.deployer import Deployer, DeployerException class DockerDeployer(Deployer): diff --git a/app/deploy.py b/app/deploy/deploy.py similarity index 92% rename from app/deploy.py rename to app/deploy/deploy.py index 75859f59..40cd0a8d 100644 --- a/app/deploy.py +++ b/app/deploy/deploy.py @@ -25,12 +25,12 @@ import subprocess import click from pathlib import Path from app.util import include_exclude_check, get_parsed_stack_config, global_options2, get_dev_root_path -from app.deployer import Deployer, DeployerException -from app.deployer_factory import getDeployer -from app.deploy_types import ClusterContext, DeployCommandContext -from app.deployment_create import create as deployment_create -from app.deployment_create import init as deployment_init -from app.deployment_create import setup as deployment_setup +from app.deploy.deployer import Deployer, DeployerException +from app.deploy.deployer_factory import getDeployer +from app.deploy.deploy_types import ClusterContext, DeployCommandContext +from app.deploy.deployment_create import create as deployment_create +from app.deploy.deployment_create import init as deployment_init +from app.deploy.deployment_create import setup as deployment_setup @click.group() @@ -258,7 +258,7 @@ def _make_cluster_context(ctx, stack, include, exclude, cluster, env_file): deployment = True else: # See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure - compose_dir = Path(__file__).absolute().parent.joinpath("data", "compose") + compose_dir = Path(__file__).absolute().parent.parent.joinpath("data", "compose") if cluster is None: # Create default unique, stable cluster name from confile file path and stack name if provided @@ -397,11 +397,11 @@ def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_en source_value = None try: source_value = deployer.execute(pd.source_container, - ["sh", "-c", - "sh /docker-entrypoint-scripts.d/export-" - f"{pd.source_variable}.sh"], - tty=False, - envs=container_exec_env) + ["sh", "-c", + "sh /docker-entrypoint-scripts.d/export-" + f"{pd.source_variable}.sh"], + tty=False, + envs=container_exec_env) except DeployerException as error: if ctx.debug: print(f"Docker exception reading config source: {error}") @@ -418,11 +418,11 @@ def _orchestrate_cluster_config(ctx, cluster_config, deployer, container_exec_en if ctx.debug: print(f"fetched source value: {source_value}") destination_output = deployer.execute(pd.destination_container, - ["sh", "-c", - f"sh /scripts/import-{pd.destination_variable}.sh" - f" {source_value}"], - tty=False, - envs=container_exec_env) + ["sh", "-c", + f"sh /scripts/import-{pd.destination_variable}.sh" + f" {source_value}"], + tty=False, + envs=container_exec_env) waiting_for_data = False if ctx.debug: print(f"destination output: {destination_output}") diff --git a/app/deploy_types.py b/app/deploy/deploy_types.py similarity index 97% rename from app/deploy_types.py rename to app/deploy/deploy_types.py index ecc0d5a3..16b5c313 100644 --- a/app/deploy_types.py +++ b/app/deploy/deploy_types.py @@ -17,7 +17,7 @@ from typing import List from dataclasses import dataclass from pathlib import Path from app.command_types import CommandOptions -from app.deployer import Deployer +from app.deploy.deployer import Deployer @dataclass diff --git a/app/deploy_util.py b/app/deploy/deploy_util.py similarity index 97% rename from app/deploy_util.py rename to app/deploy/deploy_util.py index b492d6e1..4a1ffbfe 100644 --- a/app/deploy_util.py +++ b/app/deploy/deploy_util.py @@ -15,7 +15,7 @@ import os from typing import List -from app.deploy_types import DeployCommandContext, VolumeMapping +from app.deploy.deploy_types import DeployCommandContext, VolumeMapping from app.util import get_parsed_stack_config, get_yaml, get_compose_file_dir, get_pod_list diff --git a/app/deployer.py b/app/deploy/deployer.py similarity index 100% rename from app/deployer.py rename to app/deploy/deployer.py diff --git a/app/deployer_factory.py b/app/deploy/deployer_factory.py similarity index 90% rename from app/deployer_factory.py rename to app/deploy/deployer_factory.py index 45c54ecd..de89b72c 100644 --- a/app/deployer_factory.py +++ b/app/deploy/deployer_factory.py @@ -13,8 +13,8 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from app.deploy_k8s import K8sDeployer -from app.deploy_docker import DockerDeployer +from app.deploy.k8s.deploy_k8s import K8sDeployer +from app.deploy.compose.deploy_docker import DockerDeployer def getDeployer(type, compose_files, compose_project_name, compose_env_file): diff --git a/app/deployment.py b/app/deploy/deployment.py similarity index 95% rename from app/deployment.py rename to app/deploy/deployment.py index 36cdecac..b1b4a486 100644 --- a/app/deployment.py +++ b/app/deploy/deployment.py @@ -16,10 +16,10 @@ import click from pathlib import Path import sys -from app.deploy import up_operation, down_operation, ps_operation, port_operation -from app.deploy import exec_operation, logs_operation, create_deploy_context -from app.stack import Stack -from app.spec import Spec +from app.deploy.deploy import up_operation, down_operation, ps_operation, port_operation +from app.deploy.deploy import exec_operation, logs_operation, create_deploy_context +from app.deploy.stack import Stack +from app.deploy.spec import Spec class DeploymentContext: diff --git a/app/deployment_create.py b/app/deploy/deployment_create.py similarity index 99% rename from app/deployment_create.py rename to app/deploy/deployment_create.py index 81259795..dcaccb2b 100644 --- a/app/deployment_create.py +++ b/app/deploy/deployment_create.py @@ -23,7 +23,7 @@ from shutil import copy, copyfile, copytree import sys from app.util import (get_stack_file_path, get_parsed_deployment_spec, get_parsed_stack_config, global_options, get_yaml, get_pod_list, get_pod_file_path, pod_has_scripts, get_pod_script_paths, get_plugin_code_path) -from app.deploy_types import DeploymentContext, DeployCommandContext, LaconicStackSetupCommand +from app.deploy.deploy_types import DeploymentContext, DeployCommandContext, LaconicStackSetupCommand def _make_default_deployment_dir(): @@ -325,7 +325,7 @@ def create(ctx, spec_file, deployment_dir, network_dir, initial_peers): os.mkdir(destination_compose_dir) destination_pods_dir = os.path.join(deployment_dir, "pods") os.mkdir(destination_pods_dir) - data_dir = Path(__file__).absolute().parent.joinpath("data") + data_dir = Path(__file__).absolute().parent.parent.joinpath("data") yaml = get_yaml() for pod in pods: pod_file_path = get_pod_file_path(parsed_stack, pod) diff --git a/app/deploy/k8s/__init__.py b/app/deploy/k8s/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/deploy_k8s.py b/app/deploy/k8s/deploy_k8s.py similarity index 97% rename from app/deploy_k8s.py rename to app/deploy/k8s/deploy_k8s.py index c6a3e03e..7cf0261d 100644 --- a/app/deploy_k8s.py +++ b/app/deploy/k8s/deploy_k8s.py @@ -14,7 +14,7 @@ # along with this program. If not, see . from kubernetes import client, config -from app.deployer import Deployer +from app.deploy.deployer import Deployer class K8sDeployer(Deployer): diff --git a/app/spec.py b/app/deploy/spec.py similarity index 100% rename from app/spec.py rename to app/deploy/spec.py diff --git a/app/stack.py b/app/deploy/stack.py similarity index 100% rename from app/stack.py rename to app/deploy/stack.py diff --git a/app/stack_state.py b/app/deploy/stack_state.py similarity index 100% rename from app/stack_state.py rename to app/deploy/stack_state.py diff --git a/app/repos/__init__.py b/app/repos/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/setup_repositories.py b/app/repos/setup_repositories.py similarity index 98% rename from app/setup_repositories.py rename to app/repos/setup_repositories.py index c14dccb4..0ce11670 100644 --- a/app/setup_repositories.py +++ b/app/repos/setup_repositories.py @@ -240,7 +240,7 @@ def command(ctx, include, exclude, git_ssh, check_only, pull, branches, branches if stack: # In order to be compatible with Python 3.8 we need to use this hack to get the path: # See: https://stackoverflow.com/questions/25389095/python-get-path-of-root-project-structure - stack_file_path = Path(__file__).absolute().parent.joinpath("data", "stacks", stack, "stack.yml") + stack_file_path = Path(__file__).absolute().parent.parent.joinpath("data", "stacks", stack, "stack.yml") with stack_file_path: stack_config = yaml.safe_load(open(stack_file_path, "r")) # TODO: syntax check the input here diff --git a/cli.py b/cli.py index 63823715..5dea43ca 100644 --- a/cli.py +++ b/cli.py @@ -16,12 +16,12 @@ import click from app.command_types import CommandOptions -from app import setup_repositories -from app import build_containers -from app import build_npms -from app import deploy +from app.repos import setup_repositories +from app.build import build_containers +from app.build import build_npms +from app.deploy import deploy from app import version -from app import deployment +from app.deploy import deployment from app import update CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])