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

Add environment to chainlet DeploymentContext #1214

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions truss-chains/truss_chains/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,13 @@ class ServiceDescriptor(SafeModel):
options: RPCOptions


class Environment(SafeModel):
"""The environment in which the chainlet is deployed."""

name: str
# can add more fields here as we add them to dynamic_config configmap


class DeploymentContext(SafeModelNonSerializable, Generic[UserConfigT]):
"""Bundles config values and resources needed to instantiate Chainlets.

Expand Down Expand Up @@ -417,6 +424,7 @@ class DeploymentContext(SafeModelNonSerializable, Generic[UserConfigT]):
chainlet_to_service: Mapping[str, ServiceDescriptor]
secrets: MappingNoIter[str, str]
user_env: Mapping[str, str]
environment: Optional[Environment] = None

def get_service_descriptor(self, chainlet_name: str) -> ServiceDescriptor:
if chainlet_name not in self.chainlet_to_service:
Expand Down
12 changes: 10 additions & 2 deletions truss-chains/truss_chains/model_skeleton.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pathlib
from typing import Optional

import pydantic
from truss.templates.shared import secrets_resolver
Expand All @@ -15,7 +16,11 @@ class TrussChainletModel:
_chainlet: definitions.ABCChainlet

def __init__(
self, config: dict, data_dir: pathlib.Path, secrets: secrets_resolver.Secrets
self,
config: dict,
data_dir: pathlib.Path,
secrets: secrets_resolver.Secrets,
environment: Optional[dict] = None,
spal1 marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
truss_metadata: definitions.TrussMetadata[UserConfigT] = (
definitions.TrussMetadata[
Expand All @@ -24,7 +29,9 @@ def __init__(
config["model_metadata"][definitions.TRUSS_CONFIG_CHAINS_KEY]
)
)

deployment_environment: Optional[definitions.Environment] = (
definitions.Environment.model_validate(environment) if environment else None
)
override_chainlet_to_service_metadata(truss_metadata.chainlet_to_service)

self._context = definitions.DeploymentContext[UserConfigT](
Expand All @@ -33,6 +40,7 @@ def __init__(
secrets=secrets,
data_dir=data_dir,
user_env=truss_metadata.user_env,
environment=deployment_environment,
)

# Below illustrated code will be added by code generation.
Expand Down
Loading