-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update implementation steps for e2e test
- Loading branch information
Showing
12 changed files
with
347 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.venv/ | ||
.venv/ | ||
|
||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
FROM ubuntu:latest | ||
LABEL authors="Cedric" | ||
|
||
ENTRYPOINT ["top", "-b"] | ||
# Use the official python image as the base image | ||
FROM python:3.12-alpine | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy the requirements and the rest | ||
COPY . . | ||
RUN pip install -r requirements.txt | ||
|
||
# Set the entrypoint to the built binary | ||
ENTRYPOINT ["python3", "./testbed.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 WüSpace e. V. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
MIT License | ||
Copyright (c) 2024 WüSpace e. V. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Telestion Python Backend | ||
|
||
This repository contains everything to build a working Telestion backend in Python. | ||
Additional examples help in setting everything up. | ||
|
||
The Python backend is mainly added to allow for easier interfacing with many scientific libraries, such as numpy, | ||
scipy, tensorflow or pytorch. | ||
# Telestion Python Backend | ||
|
||
This repository contains everything to build a working Telestion backend in Python. | ||
Additional examples help in setting everything up. | ||
|
||
The Python backend is mainly added to allow for easier interfacing with many scientific libraries, such as numpy, | ||
scipy, tensorflow or pytorch. | ||
Creating static graphs with Matplotlib that can be rendered in the frontend could also be created. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
nats-py~=2.7.2 # TODO: decide if we want to specify versions | ||
pydantic~=2.6.4 | ||
nats-py>=2.9.0,<3 | ||
pydantic>=2.10.4,<3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import lib | ||
import config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,110 @@ | ||
import argparse | ||
import json | ||
import os | ||
from pathlib import Path | ||
from typing import Any, TypeVar | ||
|
||
from pydantic import BaseModel, Field, ConfigDict | ||
|
||
|
||
class TelestionConfig(BaseModel): | ||
dev: bool = False | ||
nats_url: str = Field(alias="NATS_URL") | ||
nats_user: str | None = Field(alias="NATS_USER", default=None) | ||
nats_password: str | None = Field(alias="NATS_PASSWORD", default=None) | ||
config_file: Path | None = Field(alias="CONFIG_FILE", default=None) | ||
config_key: str | None = Field(alias="CONFIG_KEY", default=None) | ||
service_name: str = Field(alias="SERVICE_NAME") | ||
data_dir: Path = Field(alias="DATA_DIR") | ||
|
||
unparsed_cli: list[str] = Field(alias="_telestion_validator_unparsed_cli") | ||
|
||
# To include all envs and config parts -> it is recommended to add a custom subtype | ||
model_config = ConfigDict( | ||
extra='allow' | ||
) | ||
|
||
|
||
# With this we allow users to extend TelestionConfig for finer control over custom config fields | ||
_TelestionConfigT = TypeVar("_TelestionConfigT", bound=TelestionConfig) | ||
|
||
|
||
def build_config(clazz: type[_TelestionConfigT] = None) -> _TelestionConfigT: | ||
if clazz is None: | ||
clazz = TelestionConfig | ||
|
||
cli_args, additional_args = _parse_cli() | ||
|
||
def _from_env_or_cli(key: str): | ||
return cli_args.get(key, os.environ.get(key, None)) | ||
|
||
config_p = _from_env_or_cli('CONFIG_FILE') | ||
config_key = _from_env_or_cli('CONFIG_KEY') | ||
|
||
config_assembly: dict[str, Any] = dict() | ||
if 'dev' in cli_args and cli_args['dev']: | ||
# 1. Add default config | ||
config_assembly.update(defaults()) | ||
|
||
if config_p is not None: | ||
config_p = Path(config_p) | ||
# 2. Insert config file | ||
config_assembly.update(_parse_config_file(config_p, config_key)) | ||
|
||
# 3. Add Environment Variables | ||
config_assembly.update(os.environ) | ||
|
||
# 4. Add CLI args | ||
config_assembly.update(cli_args) | ||
|
||
# 5. Add args that cannot be parsed by the pipeline, i.e. service specific config | ||
config_assembly['_telestion_validator_unparsed_cli'] = additional_args | ||
|
||
return clazz(**config_assembly) | ||
|
||
|
||
def defaults() -> dict[str, Any]: | ||
return { | ||
'NATS_URL': "nats://localhost:4222", | ||
'SERVICE_NAME': f"dev-{os.getpid()}", | ||
'DATA_DIR': Path("./data") | ||
} | ||
|
||
|
||
def _parse_cli() -> tuple[dict[str, Any], list[str]]: | ||
description = "CLI Interface for the Telestion Services. This is one way to setup your Telestion application." | ||
epilog = "For more information please visit https://github.com/wuespace/telestion or \ | ||
https://telestion.wuespace.de/" | ||
parser = argparse.ArgumentParser( | ||
description=description, | ||
epilog=epilog, | ||
prog="Telestion-CLI (Python)", | ||
argument_default=argparse.SUPPRESS | ||
) | ||
|
||
parser.add_argument("--dev", action='store_true', help="If set, program will start in development mode") | ||
parser.add_argument("--version", action='version', version="%(prog)s v1.0-alpha") | ||
|
||
parser.add_argument("--NATS_URL", help="NATS url of the server the service can connect to") | ||
parser.add_argument("--NATS_USER", help="NATS user name for the authentication with the server") | ||
parser.add_argument("--NATS_PASSWORD", help="NATS password for the authentication with the server \ | ||
(Note: It is recommended to set this via the environment variables or the config!)") | ||
|
||
parser.add_argument("--CONFIG_FILE", help="file path to the config of the service", type=Path) | ||
parser.add_argument("--CONFIG_KEY", help="object key of a config file") | ||
|
||
parser.add_argument("--SERVICE_NAME", help="name of the service also used in the nats service registration") | ||
parser.add_argument("--DATA_DIR", help="path where the service can store persistent data", type=Path) | ||
|
||
namespace, args = parser.parse_known_args() | ||
return vars(namespace), args | ||
|
||
|
||
def _parse_config_file(config_p: Path, key: str = None) -> dict[str, Any]: | ||
with open(config_p, 'r') as config_f: | ||
content = json.load(config_f) | ||
|
||
if key is None: | ||
return content | ||
|
||
return content[key] | ||
import argparse | ||
import json | ||
import os | ||
from pathlib import Path | ||
from typing import Any, TypeVar | ||
|
||
from pydantic import BaseModel, Field, ConfigDict | ||
|
||
|
||
class TelestionConfig(BaseModel): | ||
dev: bool = False | ||
nats_url: str = Field(alias="NATS_URL") | ||
nats_user: str | None = Field(alias="NATS_USER", default=None) | ||
nats_password: str | None = Field(alias="NATS_PASSWORD", default=None) | ||
config_file: Path | None = Field(alias="CONFIG_FILE", default=None) | ||
config_key: str | None = Field(alias="CONFIG_KEY", default=None) | ||
service_name: str = Field(alias="SERVICE_NAME") | ||
data_dir: Path = Field(alias="DATA_DIR") | ||
|
||
unparsed_cli: list[str] = Field(alias="_telestion_validator_unparsed_cli") | ||
|
||
# To include all envs and config parts -> it is recommended to add a custom subtype | ||
model_config = ConfigDict( | ||
extra='allow' | ||
) | ||
|
||
|
||
# With this we allow users to extend TelestionConfig for finer control over custom config fields | ||
_TelestionConfigT = TypeVar("_TelestionConfigT", bound=TelestionConfig) | ||
|
||
|
||
def build_config(clazz: type[_TelestionConfigT] = None) -> _TelestionConfigT: | ||
if clazz is None: | ||
clazz = TelestionConfig | ||
|
||
cli_args, additional_args = _parse_cli() | ||
|
||
def _from_env_or_cli(key: str): | ||
return cli_args.get(key, os.environ.get(key, None)) | ||
|
||
config_path = _from_env_or_cli('CONFIG_FILE') | ||
config_key = _from_env_or_cli('CONFIG_KEY') | ||
|
||
config_assembly: dict[str, Any] = dict() | ||
if 'dev' in cli_args and cli_args['dev']: | ||
# 1. Add default config | ||
config_assembly.update(defaults()) | ||
|
||
if config_path is not None: | ||
config_path = Path(config_path) | ||
# 2. Insert config file | ||
config_assembly.update(_parse_config_file(config_path, config_key)) | ||
|
||
# 3. Add Environment Variables | ||
config_assembly.update(os.environ) | ||
|
||
# 4. Add CLI args | ||
config_assembly.update(cli_args) | ||
|
||
# 5. Add args that cannot be parsed by the pipeline, i.e. service specific config | ||
config_assembly['_telestion_validator_unparsed_cli'] = additional_args | ||
|
||
return clazz(**config_assembly) | ||
|
||
|
||
def defaults() -> dict[str, Any]: | ||
return { | ||
'NATS_URL': "nats://localhost:4222", | ||
'SERVICE_NAME': f"dev-{os.getpid()}", | ||
'DATA_DIR': Path("./data") | ||
} | ||
|
||
|
||
def _parse_cli() -> tuple[dict[str, Any], list[str]]: | ||
description = "CLI Interface for the Telestion Services. This is one way to setup your Telestion application." | ||
epilog = "For more information please visit https://github.com/wuespace/telestion or \ | ||
https://telestion.wuespace.de/" | ||
parser = argparse.ArgumentParser( | ||
description=description, | ||
epilog=epilog, | ||
prog="Telestion-CLI (Python)", | ||
argument_default=argparse.SUPPRESS | ||
) | ||
|
||
parser.add_argument("--dev", action='store_true', help="If set, program will start in development mode") | ||
parser.add_argument("--version", action='version', version="%(prog)s v1.0-alpha") | ||
|
||
parser.add_argument("--NATS_URL", help="NATS url of the server the service can connect to") | ||
parser.add_argument("--NATS_USER", help="NATS user name for the authentication with the server") | ||
parser.add_argument("--NATS_PASSWORD", help="NATS password for the authentication with the server \ | ||
(Note: It is recommended to set this via the environment variables or the config!)") | ||
|
||
parser.add_argument("--CONFIG_FILE", help="file path to the config of the service", type=Path) | ||
parser.add_argument("--CONFIG_KEY", help="object key of a config file") | ||
|
||
parser.add_argument("--SERVICE_NAME", help="name of the service also used in the nats service registration") | ||
parser.add_argument("--DATA_DIR", help="path where the service can store persistent data", type=Path) | ||
|
||
namespace, args = parser.parse_known_args() | ||
return vars(namespace), args | ||
|
||
|
||
def _parse_config_file(config_p: Path, key: str = None) -> dict[str, Any]: | ||
with open(config_p, 'r') as config_f: | ||
content = json.load(config_f) | ||
|
||
if key is None: | ||
return content | ||
|
||
return content[key] |
Oops, something went wrong.