Skip to content

Commit

Permalink
Merge pull request #50 from getindata/release-2.0.0
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
niladrem authored Jul 19, 2023
2 parents 9bc9fec + 40dfc36 commit 2dbc70e
Show file tree
Hide file tree
Showing 42 changed files with 414 additions and 1,052 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## [Unreleased]

## [2.0.0] - 2023-05-30

## [1.11.1] - 2023-05-19

## [1.11.0] - 2023-05-19
Expand Down Expand Up @@ -134,7 +136,9 @@

# [Unreleased]&#x3A; <https://github.com/getindata/streaming-cli/compare/1.8.0...HEAD>

[Unreleased]: https://github.com/getindata/streaming-cli/compare/1.11.1...HEAD
[Unreleased]: https://github.com/getindata/streaming-cli/compare/2.0.0...HEAD

[2.0.0]: https://github.com/getindata/streaming-cli/compare/1.11.1...2.0.0

[1.11.1]: https://github.com/getindata/streaming-cli/compare/1.11.0...1.11.1

Expand Down
115 changes: 30 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,102 +10,47 @@

### Platform operations

Commands below will help you set up and work with Ververica Platform.

#### Generating API token

```shell
scli platform api-token create \
--vvp-url "https://vvp.example.com" \
--vvp-namespace "default" \
--name "cicd" \
--role "editor" \
--save-to-kubernetes-secret "vvp/secret"
```

Sample response:

```json
{
"namespace": "default",
"name": "cicd",
"role": "editor",
"secret": "x§11d091jd1jd9jasd0j"
}
```

#### Removing API token

```shell
scli platform api-token remove \
--vvp-url "https://vvp.example.com" \
--vvp-namespace "default" \
--name "cicd"
```

#### Profiles

You can set up your own profile, which will help you to connect to Ververica. Instead of providing common parameters to
each command, you can just pass the profile name with `--profile`
or export environmental variable as `SCLI_PROFILE`.

##### Creating a profile

The command below will walk you through an interactive way of setting up a profile:

```shell
scli profile add sandbox
#### Environments

You can set up your own environment, which will allow you to connect to Ververica/K8S operator. You need to fill
properties within `config/<env_name>` directory. `config/flink_deployment.yml` is default deployment descriptor file
for each environment (you can overwrite it using `--file-descriptor-path` flag). You can use jinja for templating
(look at the tests for an example). `base` environment is the default environment. Others environment override
parameters from `base`. You need to have in `base` or your own environment `profile.yml`
file with given schema:
```yaml
deployment_mode: <VVP|K8S_OPERATOR>
docker_registry_url: <docker_registry_url>
```

You can also set up a profile in a non-interactive way by providing all required parameters as arguments:

```shell
scli profile add sandbox \
--vvp-url "https://vvp.streaming-platform.getindata.dev" \
--vvp-namespace "default" \
--vvp-deployment-target "vvp-team1" \
--vvp-api-token "x§11d091jd1jd9jasd0j" \
--docker-registry-url "registry.gitlab.com/flink-jobs"
You need also extra file(s) with Ververica/Kubernetes configuration
and optionally other configuration used for templating.
Example `vvp.yml`:
```yaml
vvp:
url: <ververica_url>
namespace: <ververica_namespace>
deployment_target: <some_deployment_target>
```

Example `k8s.yml`:
```yaml
k8s:
namespace: test_ns
```

#### Creating Deployment target

```shell
scli platform deployment-target create \
--vvp-url "https://vvp.example.com" \
--vvp-namespace "default" \
--vvp-api-token "x§11d091jd1jd9jasd0j" \
--name "vvp-team1" \
--kubernetes-namespace "vvp" \
--profile "sandbox"
```

> Parameters `--vvp-url`, `--vvp-namespace`, `--vvp-api-token`, `--vvp-deployment-target` are optional if they can be read from profile.
Sample response:

```json
{
"name": "vvp-team1"
}
```
For most of the command, you can pass the environment name with `--env`
or export environmental variable as `SCLI_ENV`.

#### Deploying job

```shell
scli project deploy \
--vvp-url "https://vvp.example.com" \
--vvp-namespace "default" \
--vvp-api-token "x§11d091jd1jd9jasd0j" \
--vvp-deployment-target "vvp-team1" \
--docker-image-registry "${CI_REGISTRY_IMAGE}" \
--docker-image-tag "${CI_COMMIT_TAG}" \
--docker-image-repository tmp_project \
--profile "sandbox"
--profile "dev"
```

> Parameters `--vvp-url`, `--vvp-namespace`, `--vvp-api-token`, `--vvp-deployment-target` are optional if they can be read from profile.
#### Building job Docker image

```shell
Expand All @@ -119,7 +64,7 @@ scli project build \
scli docker login \
--username "user" \
--password "password" \
--docker-registry-url registry.gitlab.com/getindata/
--profile "dev"
```

> Parameters`--docker-image-tag` is optional and has default value `latest`.
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.11.1
current_version = 2.0.0

[flake8]
exclude = .git,__pycache__,build,dist,*.yml
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from setuptools import find_packages, setup
from setuptools.command.install import install

__version__ = "1.11.1"
__version__ = "2.0.0"

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down
12 changes: 6 additions & 6 deletions streamingcli/config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from pathlib import Path

PROJECT_LOCAL_CONFIG_FILE_NAME = ".streaming_config.yml"
PROJECT_LOCAL_CONFIG_FILE_NAME = "config/general.yml"
PROJECT_DEPLOYMENT_TEMPLATE = "config/flink_deployment.yml"
PROJECT_K8S_CONFIGMAP_KEY = "project_configmap.json"
PLATFORM_K8S_CONFIGMAP_NAME = "streaming-platform-config"
PLATFORM_K8S_CONFIGMAP_KEY = "platform_config.json"
PLATFORM_K8S_SECRET_NAME = "streaming-platform-secret"
PLATFORM_DEFAULT_DEPLOYMENT_TARGET_NAME = "default"
PROFILE_ENV_VARIABLE_NAME = "SCLI_PROFILE"
PROFILE_ENV_VARIABLE_NAME = "SCLI_ENV"
SCLI_CONFIG_DIR_NAME = ".scli"
DEFAULT_PROFILE_DIR = f"{str(Path.home())}/{SCLI_CONFIG_DIR_NAME}"
DEFAULT_PROFILE_PATH = f"{DEFAULT_PROFILE_DIR}/profiles.yml"
DEFAULT_PROFILE_PATH = "config"
DEFAULT_PROFILE = "base"
PROFILE_CONFIG_FILE = "profile.yml"
PYTHON_TEMPLATE_PROJECT = "PYTHON_TEMPLATE_PROJECT"
JUPYTER_TEMPLATE_PROJECT = "JUPYTER_TEMPLATE_PROJECT"
DEFAULT_FLINK_APP_NAME = "flink_app.py"
Expand Down
24 changes: 19 additions & 5 deletions streamingcli/docker/login_command.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
import base64
import json
from typing import Any, Dict
from typing import Any, Dict, Optional

import click
import docker
from docker import auth
from docker.utils import config

from streamingcli.profile.profile_adapter import ProfileAdapter
from streamingcli.project.deploy_command import ProjectDeployer


class LoginCommand:
@staticmethod
def docker_login(username: str, password: str, docker_registry_url: str) -> None:
def docker_login(
username: str, password: str, profile: Optional[str] = None
) -> None:
profile_name = ProjectDeployer.get_profile_name(profile_name=profile)
profile_data = ProfileAdapter.get_profile(profile_name=profile_name)
if not profile_data.docker_registry_url:
raise click.ClickException("Missing docker_registry_url")

client = docker.from_env()
client.login(username, password, registry=docker_registry_url, reauth=True)
click.echo(f"Successfully logged in to {docker_registry_url}")
client.login(
username, password, registry=profile_data.docker_registry_url, reauth=True
)
click.echo(f"Successfully logged in to {profile_data.docker_registry_url}")
# it's a bit of a hack, docker-py login method does not update auth credentials in Docker config file
LoginCommand.update_docker_auths_config(username, password, docker_registry_url)
LoginCommand.update_docker_auths_config(
username, password, profile_data.docker_registry_url
)

@staticmethod
def update_docker_auths_config(
Expand Down
Loading

0 comments on commit 2dbc70e

Please sign in to comment.