Skip to content

Commit

Permalink
Merge pull request #141 from GoogleCloudPlatform/fix-sb-vars
Browse files Browse the repository at this point in the history
fix bug in set vars and deploy
  • Loading branch information
jonchenn authored Oct 25, 2023
2 parents f3fadb9 + e04f0d4 commit c527021
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "Apache"
Expand Down
29 changes: 24 additions & 5 deletions solutions_builder/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()] = ".",
Expand All @@ -141,7 +142,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,
Expand All @@ -165,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:
Expand All @@ -187,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):
Expand All @@ -197,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)
Expand Down
8 changes: 4 additions & 4 deletions solutions_builder/cli/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit c527021

Please sign in to comment.