Skip to content

Commit

Permalink
Merge branch 'stream-218.deploy_fix' into 'master'
Browse files Browse the repository at this point in the history
[STREAM-218] Use profiles in deploy

See merge request getindata/streaming-labs/streaming-cli!24
  • Loading branch information
Marcin Kacperek committed Oct 22, 2021
2 parents 0ae75a6 + 1bd75b8 commit 77658ba
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 56 deletions.
50 changes: 25 additions & 25 deletions streamingcli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,38 @@ def project_init(project_name: str):
click.echo(f"Project: {project_name} initialized")

@project.command()
@click.option('--docker-image-tag', 'docker_image_tag',
help='Docker image tag to deploy')
@click.option('--profile',
help='Profile name to use')
help='Profile name to use')
@click.option('--vvp-url', 'ververica_url',
help='URL for Ververica cluster, i.e: "https://vvp.streaming-platform.example.com"')
help='URL for Ververica cluster, i.e: "https://vvp.streaming-platform.example.com"')
@click.option('--vvp-namespace', 'ververica_namespace',
help='Ververica namespace')
help='Ververica namespace')
@click.option('--vvp-deployment-target', 'ververica_deployment_target_name',
help='Ververica deployment target name')
help='Ververica deployment target name')
@click.option('--token', 'ververica_webtoken_secret',
help='Ververica WebToken secret to make API calls')
help='Ververica WebToken secret to make API calls')
@click.option('--docker-registry-url', 'docker_registry_url',
help='URL for Docker registry, i.e: "https://hub.docker.com/"')
@click.option('--docker-image-tag', 'docker_image_tag',
help='Docker image tag to deploy')
help='URL for Docker registry, i.e: "https://hub.docker.com/"')
@click.option('--overrides_from_yaml',
help='Path to additional deployment YAML file to merge with Ververica one')
def project_deploy(profile: str = None,
ververica_url: str = None,
ververica_namespace: str = None,
ververica_deployment_target_name: str = None,
ververica_webtoken_secret: str = None,
docker_registry_url: str = None,
docker_image_tag: str = None,
overrides_from_yaml: str = None):
ProjectDeployer.deploy_project(profile=profile,
ververica_url=ververica_url,
ververica_namespace=ververica_namespace,
ververica_deployment_target_name=ververica_deployment_target_name,
ververica_webtoken_secret=ververica_webtoken_secret,
docker_registry_url=docker_registry_url,
docker_image_tag=docker_image_tag,
overrides_from_yaml=overrides_from_yaml)
help='Path to additional deployment YAML file to merge with Ververica one')
def project_deploy(docker_image_tag: str,
profile: str = None,
ververica_url: str = None,
ververica_namespace: str = None,
ververica_deployment_target_name: str = None,
ververica_webtoken_secret: str = None,
docker_registry_url: str = None,
overrides_from_yaml: str = None):
ProjectDeployer.deploy_project(docker_image_tag=docker_image_tag,
profile=profile,
ververica_url=ververica_url,
ververica_namespace=ververica_namespace,
ververica_deployment_target_name=ververica_deployment_target_name,
ververica_webtoken_secret=ververica_webtoken_secret,
docker_registry_url=docker_registry_url,
overrides_from_yaml=overrides_from_yaml)


@project.command()
Expand Down
70 changes: 39 additions & 31 deletions streamingcli/project/deploy_command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import os
from dataclasses import replace
from typing import Optional

import click
from jinja2 import Environment
from streamingcli.Config import PROFILE_ENV_VARIABLE_NAME
from streamingcli.platform.ververica.deployment_adapter import \
DeploymentAdapter
from streamingcli.profile.profile_command import ProfileCommand, ScliProfile
from streamingcli.project.local_project_config import LocalProjectConfigIO
from streamingcli.project.template_loader import TemplateLoader
from streamingcli.project.yaml_merger import YamlMerger
Expand All @@ -20,60 +22,66 @@ def get_profile_name(profile_name: Optional[str]) -> Optional[str]:
return os.getenv(PROFILE_ENV_VARIABLE_NAME)

@staticmethod
def deploy_project(profile: Optional[str] = None,
def deploy_project(docker_image_tag: str,
profile: Optional[str] = None,
ververica_url: Optional[str] = None,
ververica_namespace: Optional[str] = None,
ververica_deployment_target_name: Optional[str] = None,
ververica_webtoken_secret: Optional[str] = None,
docker_registry_url: Optional[str] = None,
docker_image_tag: Optional[str] = None,
overrides_from_yaml: Optional[str] = None):
profile_name = ProjectDeployer.get_profile_name(profile_name=profile)

# TODO Use ScliProfile dataclass instead
profile_data = {}

# TODO Load profile data for {profile_name}
# Load platform ConfigMap
# Load local project config
local_project_config = LocalProjectConfigIO.load_project_config()

profile_name = ProjectDeployer.get_profile_name(profile_name=profile)
profile_data = ScliProfile(profile_name=profile_name)

# Explicitly defined parameters will override profile ones
if ververica_url is not None:
profile_data["ververica_url"] = ververica_url
if ververica_namespace is not None:
profile_data["ververica_namespace"] = ververica_namespace
if ververica_deployment_target_name is not None:
profile_data["ververica_deployment_target_name"] = ververica_deployment_target_name
if ververica_webtoken_secret is not None:
profile_data["ververica_webtoken_secret"] = ververica_webtoken_secret
if docker_registry_url is not None:
profile_data["docker_registry_url"] = docker_registry_url
if docker_image_tag is not None:
profile_data["docker_image_tag"] = docker_image_tag
if(profile_name is not None):
profile_data = ProfileCommand.get_profile(profile_name=profile_name)

# Load local project config
local_project_config = LocalProjectConfigIO.load_project_config()
profile_data = ProjectDeployer.update_profile_data(profile_data, ververica_url, ververica_namespace,
ververica_deployment_target_name, ververica_webtoken_secret, docker_registry_url)

# Generate deployment YAML
deployment_yml = ProjectDeployer.generate_project_template(
project_name=local_project_config.project_name,
docker_registry_url=profile_data["docker_registry_url"],
docker_image_tag=profile_data["docker_image_tag"],
deployment_target_name=profile_data["ververica_deployment_target_name"]
docker_registry_url=profile_data.docker_registry_url,
docker_image_tag=docker_image_tag,
deployment_target_name=profile_data.ververica_deployment_target
)
if overrides_from_yaml:
deployment_yml = YamlMerger.merge_two_yaml(deployment_yml, overrides_from_yaml)
click.echo(f"Deploying streaming project: {local_project_config.project_name} ...")

deployment_name = DeploymentAdapter.deploy(
deployment_yml=deployment_yml,
ververica_url=profile_data["ververica_url"],
ververica_namespace=profile_data["ververica_namespace"],
auth_token=profile_data["ververica_webtoken_secret"]
ververica_url=profile_data.ververica_url,
ververica_namespace=profile_data.ververica_namespace,
auth_token=profile_data.ververica_api_token
)
click.echo(f"Created deployment: "
f"{profile_data['ververica_url']}/app/#/namespaces/"
f"{profile_data['ververica_namespace']}/deployments/{deployment_name}")
f"{profile_data.ververica_url}/app/#/namespaces/"
f"{profile_data.ververica_namespace}/deployments/{deployment_name}")

@staticmethod
def update_profile_data(profile_data, ververica_url, ververica_namespace, ververica_deployment_target_name,
ververica_webtoken_secret, docker_registry_url):
deployment_params = {
'ververica_url' : ververica_url,
'ververica_namespace' : ververica_namespace,
'ververica_deployment_target_name' : ververica_deployment_target_name,
'ververica_api_token' : ververica_webtoken_secret,
'docker_registry_url' : docker_registry_url
}

non_empty_deployment_params = {
key : value for (key,value) in deployment_params.items() if value is not None
}

profile_data = replace(profile_data, **non_empty_deployment_params)
click.echo(profile_data)
return profile_data

@staticmethod
def generate_project_template(
Expand Down

0 comments on commit 77658ba

Please sign in to comment.