From 4c9a12b5de7bdde78ef6b92dedf7397c1b11de8c Mon Sep 17 00:00:00 2001 From: Jon Chen Date: Wed, 25 Oct 2023 23:07:33 +0900 Subject: [PATCH 1/3] fix bug in set vars and deploy --- pyproject.toml | 2 +- solutions_builder/cli/cli.py | 8 +++++++- solutions_builder/cli/set.py | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 97ad00c..19baf3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "solutions-builder" -version = "1.17.16" +version = "1.17.17" description = "A solution framework to generate a project with built-in structure and modules" authors = ["Jon Chen "] license = "Apache" diff --git a/solutions_builder/cli/cli.py b/solutions_builder/cli/cli.py index c6ca449..395de47 100644 --- a/solutions_builder/cli/cli.py +++ b/solutions_builder/cli/cli.py @@ -141,7 +141,13 @@ def deploy( validate_solution_folder(solution_path) sb_yaml = read_yaml(f"{solution_path}/sb.yaml") - project_id = sb_yaml["project_id"] + global_variables = sb_yaml.get("global_variables", {}) + + # Get project_id from sb.yaml. + project_id = global_variables.get("project_id", None) + assert project_id, "project_id is not set in 'global_variables' in sb.yaml." + + # Get terraform_gke component settings. terraform_gke = sb_yaml["components"].get("terraform_gke") env_vars = { "PROJECT_ID": project_id, diff --git a/solutions_builder/cli/set.py b/solutions_builder/cli/set.py index 1ffdecd..ddabd7e 100644 --- a/solutions_builder/cli/set.py +++ b/solutions_builder/cli/set.py @@ -38,8 +38,8 @@ def project_id( yes: Optional[bool] = False, ): validate_solution_folder(solution_path) - root_st_yaml = read_yaml(f"{solution_path}/sb.yaml") - global_variables = root_st_yaml.get("global_variables", {}) + sb_yaml = read_yaml(f"{solution_path}/sb.yaml") + global_variables = sb_yaml.get("global_variables", {}) old_project_id = global_variables.get("project_id") old_project_number = global_variables.get("project_number") @@ -56,8 +56,8 @@ def project_id( global_variables["project_id"] = new_project_id global_variables["project_number"] = new_project_number - root_st_yaml["global_variables"] = global_variables - write_yaml(f"{solution_path}/sb.yaml", root_st_yaml) + sb_yaml["global_variables"] = global_variables + write_yaml(f"{solution_path}/sb.yaml", sb_yaml) # Update copier answers copier_yaml = read_yaml(f"{solution_path}/.copier-answers.yml") From 86af1e3f52c1cad8770cf7264810f6794decd97e Mon Sep 17 00:00:00 2001 From: Jon Chen Date: Wed, 25 Oct 2023 23:11:20 +0900 Subject: [PATCH 2/3] added skaffold namespace to sb deploy --- solutions_builder/cli/cli.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/solutions_builder/cli/cli.py b/solutions_builder/cli/cli.py index 395de47..9e37c5f 100644 --- a/solutions_builder/cli/cli.py +++ b/solutions_builder/cli/cli.py @@ -130,6 +130,7 @@ def update(solution_path: Annotated[Optional[str], def deploy( profile: Annotated[str, typer.Option("--profile", "-p")] = DEFAULT_DEPLOY_PROFILE, component: Annotated[str, typer.Option("--component", "-c", "-m")] = None, + namespace: Annotated[str, typer.Option("--namespace", "-n")] = None, dev: Optional[bool] = False, solution_path: Annotated[Optional[str], typer.Argument()] = ".", @@ -171,8 +172,12 @@ def deploy( f"gcloud container clusters get-credentials {cluster_name} --region {region} --project {project_id}" ) + # Set Skaffold namespace + namespace_flag = f"-n {namespace}" if namespace else "" + + # Add skaffold command. commands.append( - f"{skaffold_command} -p {profile} {component_flag} --default-repo=\"gcr.io/{project_id}\" {skaffold_args}" + f"{skaffold_command} -p {profile} {component_flag} {namespace_flag} --default-repo=\"gcr.io/{project_id}\" {skaffold_args}" ) print("This will build and deploy all services using the command below:") for command in commands: From e04f0d44ee2b97705393cb58952e9f3e257a4a70 Mon Sep 17 00:00:00 2001 From: Jon Chen Date: Wed, 25 Oct 2023 23:17:58 +0900 Subject: [PATCH 3/3] updated project_id var in sb delete --- solutions_builder/cli/cli.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/solutions_builder/cli/cli.py b/solutions_builder/cli/cli.py index 9e37c5f..ea96a38 100644 --- a/solutions_builder/cli/cli.py +++ b/solutions_builder/cli/cli.py @@ -198,7 +198,8 @@ def deploy( # Destory deployment. @app.command() def delete(profile: str = DEFAULT_DEPLOY_PROFILE, - component: str = None, + component: Annotated[str, typer.Option("--component", "-c", "-m")] = None, + namespace: Annotated[str, typer.Option("--namespace", "-n")] = None, solution_path: Annotated[Optional[str], typer.Argument()] = ".", yes: Optional[bool] = False): @@ -208,14 +209,21 @@ def delete(profile: str = DEFAULT_DEPLOY_PROFILE, validate_solution_folder(solution_path) sb_yaml = read_yaml(f"{solution_path}/sb.yaml") - project_id = sb_yaml["project_id"] + global_variables = sb_yaml.get("global_variables", {}) + + # Get project_id from sb.yaml. + project_id = global_variables.get("project_id", None) + assert project_id, "project_id is not set in 'global_variables' in sb.yaml." if component: component_flag = f" -m {component} " else: component_flag = "" - command = f"skaffold delete -p {profile} {component_flag} --default-repo=\"gcr.io/{project_id}\"" + # Set Skaffold namespace + namespace_flag = f"-n {namespace}" if namespace else "" + + command = f"skaffold delete -p {profile} {component_flag} {namespace_flag} --default-repo=\"gcr.io/{project_id}\"" print("This will DELETE deployed services using the command below:") print_highlight(command) confirm("\nThis may take a few minutes. Continue?", default=False, skip=yes)