Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug in set vars and deploy #141

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading