Skip to content

Commit

Permalink
fix: issue certificate after write private key
Browse files Browse the repository at this point in the history
Signed-off-by: OjusWiZard <[email protected]>
  • Loading branch information
OjusWiZard committed Oct 28, 2024
1 parent 5c76a26 commit 8794339
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 25 deletions.
7 changes: 4 additions & 3 deletions autonomy/cli/helpers/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from autonomy.deploy.image import build_image


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

mkdirs = [(new_dir_name,) for new_dir_name in mkdir]
Expand Down Expand Up @@ -257,7 +257,7 @@ def build_deployment( # pylint: disable=too-many-arguments, too-many-locals
resources: Optional[Resources] = None,
service_hash_id: Optional[str] = None,
service_offset: int = 0,
mkdir: Optional[str] = None,
mkdir: Optional[List[str]] = None,
) -> None:
"""Build deployment."""

Expand All @@ -271,7 +271,8 @@ def build_deployment( # pylint: disable=too-many-arguments, too-many-locals

click.echo(f"Building deployment @ {build_dir}")
build_dir.mkdir()
_build_dirs(build_dir, mkdir)
if mkdir is not None:
_build_dirs(build_dir, mkdir)

if service_hash_id is None:
service_hash_id = build_hash_id()
Expand Down
2 changes: 2 additions & 0 deletions autonomy/deploy/generators/localhost/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
)
from autonomy.deploy.generators.localhost.utils import (
check_tendermint_version,
run_aea_cmd,
setup_agent,
)

Expand Down Expand Up @@ -114,6 +115,7 @@ def _populate_keys(self) -> None:
ledger = kp.get(LEDGER, DEFAULT_LEDGER)
keys_file = self.build_dir / PRIVATE_KEY_PATH_SCHEMA.format(ledger)
keys_file.write_text(key, encoding=DEFAULT_ENCODING)
run_aea_cmd(["issue-certificates"], cwd=self.build_dir)

def _populate_keys_multiledger(self) -> None:
"""Populate the keys directory with multiple set of keys"""
Expand Down
12 changes: 5 additions & 7 deletions autonomy/deploy/generators/localhost/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import subprocess # nosec
import sys
from pathlib import Path
from typing import Any, List, Optional
from typing import Any, Dict, List, Optional

from aea.configurations.constants import DEFAULT_AEA_CONFIG_FILE, VENDOR

Expand Down Expand Up @@ -69,12 +69,12 @@ def check_tendermint_version() -> Path:
return tendermint_executable


def _run_aea_cmd(
def run_aea_cmd(
args: List[str],
cwd: Optional[Path] = None,
stdout: int = subprocess.PIPE,
stderr: int = subprocess.PIPE,
ignore_error: str | None = None,
ignore_error: Optional[str] = None,
**kwargs: Any,
) -> None:
"""Run an aea command in a subprocess."""
Expand Down Expand Up @@ -121,7 +121,7 @@ def _prepare_agent_env(working_dir: Path) -> None:
)


def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None:
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)
Expand All @@ -134,10 +134,8 @@ def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None:
for ledger_name, path in agent_config.get("private_key_paths", {}).items():
if Path(path).exists():
shutil.copy(path, working_dir)
_run_aea_cmd(
run_aea_cmd(
["add-key", ledger_name],
cwd=working_dir,
ignore_error="already present",
)

_run_aea_cmd(["issue-certificates"], cwd=working_dir)
17 changes: 7 additions & 10 deletions docs/api/cli/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ Deploy an agent service.
@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 @@ -164,6 +164,7 @@ def build_deployment_command(
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 @@ -179,8 +180,7 @@ def build_deployment_command(
agent_cpu_limit: Optional[float] = None,
agent_memory_limit: Optional[int] = None,
agent_cpu_request: Optional[float] = None,
agent_memory_request: Optional[int] = None,
mkdir: Optional[str] = None) -> None
agent_memory_request: Optional[int] = None) -> None
```

Build deployment setup for n agents.
Expand Down Expand Up @@ -227,11 +227,8 @@ Build deployment setup for n agents.
help="Use docker as a backend. (default)",
default=True,
)
def run(build_dir: Path,
no_recreate: bool,
remove_orphans: bool,
detach: bool = False,
deployment_type: str = "localhost") -> None
def run(build_dir: Path, no_recreate: bool, remove_orphans: bool, detach: bool,
deployment_type: str) -> None
```

Run deployment.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/cli/helpers/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def build_deployment(keys_file: Path,
resources: Optional[Resources] = None,
service_hash_id: Optional[str] = None,
service_offset: int = 0,
mkdir: Optional[str] = None) -> None
mkdir: Optional[List[str]] = None) -> None
```

Build deployment.
Expand Down
17 changes: 16 additions & 1 deletion docs/api/deploy/generators/localhost/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,27 @@ def check_tendermint_version() -> Path

Check tendermint version.

<a id="autonomy.deploy.generators.localhost.utils.run_aea_cmd"></a>

#### run`_`aea`_`cmd

```python
def run_aea_cmd(args: List[str],
cwd: Optional[Path] = None,
stdout: int = subprocess.PIPE,
stderr: int = subprocess.PIPE,
ignore_error: Optional[str] = None,
**kwargs: Any) -> None
```

Run an aea command in a subprocess.

<a id="autonomy.deploy.generators.localhost.utils.setup_agent"></a>

#### setup`_`agent

```python
def setup_agent(working_dir: Path, agent_config: dict[str, Any]) -> None
def setup_agent(working_dir: Path, agent_config: Dict[str, Any]) -> None
```

Setup locally deployed agent.
Expand Down
4 changes: 3 additions & 1 deletion tests/test_autonomy/test_chain/test_addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
from autonomy.chain.constants import CHAIN_PROFILES


ADDRESS_FILE_URL = "https://raw.githubusercontent.com/valory-xyz/autonolas-registries/main/docs/configuration.json"
# this file is fetched from an old commit, because the latest file version has removed some chains
# TODO: use the latest file
ADDRESS_FILE_URL = "https://github.com/valory-xyz/autonolas-registries/raw/a6a35cf7bbdbac64eeab9375c0b32848b266a166/docs/configuration.json"


class TestAddresses:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
TM_STATE_DIR,
)
from autonomy.deploy.generators.docker_compose.base import DockerComposeGenerator
from autonomy.deploy.generators.localhost.utils import _run_aea_cmd
from autonomy.deploy.generators.localhost.utils import run_aea_cmd
from autonomy.replay.agent import ETHEREUM_PRIVATE_KEY_FILE

from tests.conftest import ROOT_DIR, skip_docker_tests
Expand Down Expand Up @@ -269,7 +269,7 @@ def setup(self) -> None:
# add all the components
for component_type in (CONNECTION, CONTRACT, SKILL, PROTOCOL):
for component_name in agent_config[component_type + "s"]:
_run_aea_cmd(
run_aea_cmd(
[
"--skip-consistency-check",
"add",
Expand Down

0 comments on commit 8794339

Please sign in to comment.