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 expansion feature #37

Merged
merged 10 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: test
on:
pull_request:
push:
branches:
- main
tags:
- "*"

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: install dependencies
run: python3 -m pip install --user --upgrade poetry
- name: install
run: poetry install
- name: Run tests
run: make test
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test:
@(cd pystarport/tests && poetry run pytest)
177 changes: 176 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ supervisor = "^4.2.1"
docker = "^4.3.1"
bech32 = "^1.1.0"
multitail2 = "^1.5.2"
python-dotenv = "^0.19.2"

[tool.poetry.dev-dependencies]
pytest = "^6.2.5"
deepdiff = "^5.6.0"

[tool.poetry.scripts]
pystarport = "pystarport.cli:main"
Expand Down
15 changes: 10 additions & 5 deletions pystarport/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ def init(
data,
config,
base_port,
dotenv,
*args,
**kwargs,
):
interact(
f"rm -r {data}; mkdir {data}",
ignore_error=True,
)
return init_cluster(data, config, base_port, *args, **kwargs)
return init_cluster(data, config, base_port, dotenv, *args, **kwargs)


def start(data, quiet):
Expand All @@ -42,8 +43,8 @@ def start(data, quiet):
tailer.join()


def serve(data, config, base_port, cmd, quiet):
init(data, config, base_port, cmd=cmd)
def serve(data, config, base_port, dotenv, cmd, quiet):
init(data, config, base_port, dotenv, cmd=cmd)
start(data, quiet)


Expand All @@ -59,6 +60,7 @@ def init(
data: str = "./data",
config: str = "./config.yaml",
base_port: int = 26650,
dotenv: str = None,
image: str = IMAGE,
gen_compose_file: bool = False,
cmd: str = CHAIN,
Expand All @@ -70,11 +72,12 @@ def init(
:param config: path to the configuration file
:param base_port: the base port to use, the service ports of different nodes
are calculated based on this
:param dotenv: path to .env file
:param image: the image used in the generated docker-compose.yml
:param gen_compose_file: generate a docker-compose.yml
:param cmd: path to chain binary
"""
init(Path(data), config, base_port, image, self.cmd, gen_compose_file)
init(Path(data), config, base_port, dotenv, image, self.cmd, gen_compose_file)

def start(self, data: str = "./data", quiet: bool = False):
"""
Expand All @@ -99,6 +102,7 @@ def serve(
data: str = "./data",
config: str = "./config.yaml",
base_port: int = 26650,
dotenv: str = None,
quiet: bool = False,
):
"""
Expand All @@ -108,10 +112,11 @@ def serve(
:param config: path to the configuration file
:param base_port: the base port to use, the service ports of different nodes
are calculated based on this
:param dotenv: path to .env file
:param cmd: path to chain binary
:param quiet: don't print logs of subprocesses
"""
serve(Path(data), config, base_port, self.cmd, quiet)
serve(Path(data), config, base_port, dotenv, self.cmd, quiet)

def supervisorctl(self, *args, data: str = "./data"):
from supervisor.supervisorctl import main
Expand Down
5 changes: 3 additions & 2 deletions pystarport/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from . import ports
from .app import CHAIN, IMAGE, SUPERVISOR_CONFIG_FILE
from .cosmoscli import ChainCommand, CosmosCLI, ModuleAccount, module_address
from .expansion import expand_yaml
from .ledger import ZEMU_BUTTON_PORT, ZEMU_HOST
from .utils import format_doc_string, interact, write_ini

Expand Down Expand Up @@ -902,9 +903,9 @@ def relayer_chain_config(data_dir, chain, relayer_chains_config):


def init_cluster(
data_dir, config_path, base_port, image=IMAGE, cmd=None, gen_compose_file=False
data_dir, config_path, base_port, dotenv=None, image=IMAGE, cmd=None, gen_compose_file=False
):
config = yaml.safe_load(open(config_path))
config = expand_yaml(config_path, dotenv)

relayer_config = config.pop("relayer", {})
for chain_id, cfg in config.items():
Expand Down
Loading