diff --git a/testground/README.md b/testground/README.md index 8d03f11b76..80c3a325f2 100644 --- a/testground/README.md +++ b/testground/README.md @@ -75,14 +75,22 @@ mounts: To simplify cluster setup, we are introducing a stateless mode. -## Generate Data Files Locally +## Generate data files locally -You need to have a `cronosd` in `PATH`. +You need to have the `cronosd` in `PATH`. ```bash $ nix run github:crypto-org-chain/cronos#stateless-testcase gen /tmp/data/out 3 7 ``` +## Embed the data directory + +Patch the image to embed the data directory, it produce a local image: + +```bash +$ nix run github:crypto-org-chain/cronos#stateless-testcase patchimage cronos-testground:latest /tmp/data/out +``` + ## Run In Local Docker ```bash diff --git a/testground/benchmark/benchmark/stateless.py b/testground/benchmark/benchmark/stateless.py index 6a93fa95d8..7e935cf812 100644 --- a/testground/benchmark/benchmark/stateless.py +++ b/testground/benchmark/benchmark/stateless.py @@ -1,7 +1,9 @@ import json import os +import shutil import socket import subprocess +import tempfile from pathlib import Path from typing import List @@ -26,11 +28,17 @@ DEFAULT_CHAIN_ID = "cronos_777-1" DEFAULT_DENOM = "basecro" # the container must be deployed with the prefixed name -CONTAINER_PREFIX = "testplan-" +HOSTNAME_TEMPLATE = "testplan-{index}" class CLI: - def gen(self, outdir: str, validators: int, fullnodes: int): + def gen( + self, + outdir: str, + validators: int, + fullnodes: int, + hostname_template=HOSTNAME_TEMPLATE, + ): outdir = Path(outdir) cli = ChainCommand(LOCAL_CRONOSD_PATH) (outdir / VALIDATOR_GROUP).mkdir(parents=True, exist_ok=True) @@ -39,12 +47,12 @@ def gen(self, outdir: str, validators: int, fullnodes: int): peers = [] for i in range(validators): print("init validator", i) - peers.append(init_node_local(cli, outdir, VALIDATOR_GROUP, i, i)) + ip = hostname_template.format(index=i) + peers.append(init_node_local(cli, outdir, VALIDATOR_GROUP, i, ip)) for i in range(fullnodes): print("init fullnode", i) - peers.append( - init_node_local(cli, outdir, FULLNODE_GROUP, i, i + validators) - ) + ip = hostname_template.format(index=i + validators) + peers.append(init_node_local(cli, outdir, FULLNODE_GROUP, i, ip)) print("prepare genesis") # use a full node directory to prepare the genesis file @@ -59,6 +67,26 @@ def gen(self, outdir: str, validators: int, fullnodes: int): peers, genesis, outdir, FULLNODE_GROUP, i, i + validators ) + def patchimage( + self, + toimage, + src, + dst="/data", + fromimage="ghcr.io/crypto-org-chain/cronos-testground:latest", + ): + """ + combine data directory with an exiting image to produce a new image + """ + with tempfile.TemporaryDirectory() as tmpdir: + tmpdir = Path(tmpdir) + shutil.copytree(src, tmpdir / "out") + content = f"""FROM {fromimage} +ADD ./out {dst} +""" + print(content) + (tmpdir / "Dockerfile").write_text(content) + subprocess.run(["docker", "build", "-t", toimage, tmpdir]) + def run( self, outdir: str, @@ -100,12 +128,12 @@ def run( def init_node_local( - cli: ChainCommand, outdir: Path, group: str, group_seq: int, global_seq: int + cli: ChainCommand, outdir: Path, group: str, group_seq: int, ip: str ) -> PeerPacket: return init_node( cli, outdir / group / str(group_seq), - CONTAINER_PREFIX + str(global_seq), + ip, DEFAULT_CHAIN_ID, group, group_seq, diff --git a/testground/benchmark/compositions/docker-compose.jsonnet b/testground/benchmark/compositions/docker-compose.jsonnet index e3879941d8..c9e83c9d85 100644 --- a/testground/benchmark/compositions/docker-compose.jsonnet +++ b/testground/benchmark/compositions/docker-compose.jsonnet @@ -1,12 +1,9 @@ std.manifestYamlDoc({ services: { ['testplan-' + i]: { - image: 'ghcr.io/crypto-org-chain/cronos-testground:latest', + image: 'cronos-testground:latest', command: 'stateless-testcase run /data 3 --num_accounts=10 --num_txs=1000', container_name: 'testplan-' + i, - volumes: [ - @'${DATADIR:-/tmp/data/out}:/data', - ], environment: { JOB_COMPLETION_INDEX: i, },