diff --git a/autonomy/cli/deploy.py b/autonomy/cli/deploy.py index 70460f0b0e..b24846da39 100644 --- a/autonomy/cli/deploy.py +++ b/autonomy/cli/deploy.py @@ -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) @@ -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, @@ -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 @@ -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() diff --git a/autonomy/cli/helpers/deployment.py b/autonomy/cli/helpers/deployment.py index 3ecc6364ae..c013c46c96 100644 --- a/autonomy/cli/helpers/deployment.py +++ b/autonomy/cli/helpers/deployment.py @@ -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,), diff --git a/autonomy/deploy/generators/localhost/utils.py b/autonomy/deploy/generators/localhost/utils.py index 4c6d31fe6e..a0bddc56cc 100644 --- a/autonomy/deploy/generators/localhost/utils.py +++ b/autonomy/deploy/generators/localhost/utils.py @@ -18,6 +18,7 @@ # ------------------------------------------------------------------------------ """Localhost Deployment utilities.""" +import json import os import platform import shutil @@ -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" @@ -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 diff --git a/tests/test_autonomy/test_cli/test_deploy/test_build/test_deployment.py b/tests/test_autonomy/test_cli/test_deploy/test_build/test_deployment.py index 1b21ca90a1..5a2c71c0fa 100644 --- a/tests/test_autonomy/test_cli/test_deploy/test_build/test_deployment.py +++ b/tests/test_autonomy/test_cli/test_deploy/test_build/test_deployment.py @@ -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", }