Skip to content

Commit

Permalink
WIP (deploy): Add local agent env patches
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <[email protected]>
  • Loading branch information
OjusWiZard committed Oct 25, 2024
1 parent ce41225 commit 5c76a26
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
11 changes: 6 additions & 5 deletions autonomy/cli/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,9 @@ def deploy_group(
@click.option(
"--mkdir",
type=str,
help="Comma-separated list of directory names to create in the build directory.",
default=None,
help="Directory names to create in the build directory.",
default=[],
multiple=True,
)
@registry_flag()
@password_option(confirmation_prompt=True)
Expand All @@ -240,6 +241,7 @@ def build_deployment_command( # pylint: disable=too-many-arguments, too-many-lo
output_dir: Optional[Path],
dev_mode: bool,
registry: str,
mkdir: list[str],
number_of_agents: Optional[int] = None,
number_of_services: int = 1,
password: Optional[str] = None,
Expand All @@ -256,7 +258,6 @@ def build_deployment_command( # pylint: disable=too-many-arguments, too-many-lo
agent_memory_limit: Optional[int] = None,
agent_cpu_request: Optional[float] = None,
agent_memory_request: Optional[int] = None,
mkdir: Optional[str] = None,
) -> None:
"""Build deployment setup for n agents."""
if password is not None: # pragma: nocover
Expand Down Expand Up @@ -362,8 +363,8 @@ def run(
build_dir: Path,
no_recreate: bool,
remove_orphans: bool,
detach: bool = False,
deployment_type: str = "localhost",
detach: bool,
deployment_type: str,
) -> None:
"""Run deployment."""
build_dir = Path(build_dir or Path.cwd()).absolute()
Expand Down
4 changes: 2 additions & 2 deletions autonomy/cli/helpers/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@
from autonomy.deploy.image import build_image


def _build_dirs(build_dir: Path, mkdir: Optional[str] = None) -> None:
def _build_dirs(build_dir: Path, mkdir: list[str] = []) -> None:
"""Build necessary directories."""

mkdirs = [(new_dir_name,) for new_dir_name in mkdir.split(",")] if mkdir else []
mkdirs = [(new_dir_name,) for new_dir_name in mkdir]

for dir_path in [
(PERSISTENT_DATA_DIR,),
Expand Down
38 changes: 37 additions & 1 deletion autonomy/deploy/generators/localhost/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# ------------------------------------------------------------------------------

"""Localhost Deployment utilities."""
import json
import os
import platform
import shutil
Expand All @@ -28,7 +29,11 @@

from aea.configurations.constants import DEFAULT_AEA_CONFIG_FILE, VENDOR

from autonomy.deploy.constants import TENDERMINT_BIN_UNIX, TENDERMINT_BIN_WINDOWS
from autonomy.deploy.constants import (
BENCHMARKS_DIR,
TENDERMINT_BIN_UNIX,
TENDERMINT_BIN_WINDOWS,
)


LOCAL_TENDERMINT_VERSION = "0.34.19"
Expand Down Expand Up @@ -86,8 +91,39 @@ def _run_aea_cmd(
raise RuntimeError(f"Error running: {args} @ {cwd}\n{result_error}")


def _prepare_agent_env(working_dir: Path) -> None:
"""Prepare agent env, add keys, run aea commands."""
env = json.loads((working_dir / "agent.json").read_text(encoding="utf-8"))

# TODO: Dynamic port allocation, backport to service builder
env["CONNECTION_ABCI_CONFIG_HOST"] = "localhost"
env["CONNECTION_ABCI_CONFIG_PORT"] = "26658"

for var in env:
# Fix tendermint connection params
if var.endswith("MODELS_PARAMS_ARGS_TENDERMINT_COM_URL"):
env[var] = "http://localhost:8080"

if var.endswith("MODELS_PARAMS_ARGS_TENDERMINT_URL"):
env[var] = "http://localhost:26657"

if var.endswith("MODELS_PARAMS_ARGS_TENDERMINT_P2P_URL"):
env[var] = "localhost:26656"

if var.endswith("MODELS_BENCHMARK_TOOL_ARGS_LOG_DIR"):
benchmarks_dir = working_dir / BENCHMARKS_DIR
benchmarks_dir.mkdir(exist_ok=True, parents=True)
env[var] = str(benchmarks_dir.resolve())

(working_dir / "agent.json").write_text(
json.dumps(env, indent=2),
encoding="utf-8",
)


def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None:
"""Setup locally deployed agent."""
_prepare_agent_env(working_dir)
shutil.copy(DEFAULT_AEA_CONFIG_FILE, working_dir)

# add dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def load_and_check_localhost_build(self, path: Path) -> None:
"CONNECTION_LEDGER_CONFIG_LEDGER_APIS_ETHEREUM_CHAIN_ID": "31337",
"CONNECTION_LEDGER_CONFIG_LEDGER_APIS_ETHEREUM_POA_CHAIN": "False",
"CONNECTION_LEDGER_CONFIG_LEDGER_APIS_ETHEREUM_DEFAULT_GAS_PRICE_STRATEGY": "eip1559",
"CONNECTION_ABCI_CONFIG_HOST": "127.0.0.1",
"CONNECTION_ABCI_CONFIG_HOST": "localhost",
"CONNECTION_ABCI_CONFIG_PORT": "26658",
}

Expand Down

0 comments on commit 5c76a26

Please sign in to comment.