From f3ba53616dde91c26dc94f84d7f7a9e675cf7254 Mon Sep 17 00:00:00 2001 From: starsquidnodes Date: Sun, 22 Oct 2023 23:01:39 +0200 Subject: [PATCH] Add api port, extend build script --- .gitignore | 1 + build.sh | 36 ++++++++++++++++++++++++----------- prepare/prepare.py | 6 +++++- prepare/templates/app.toml.j2 | 2 +- prepare/templates/start.sh.j2 | 7 ++++--- 5 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/build.sh b/build.sh index b80bf28..f9f95ab 100755 --- a/build.sh +++ b/build.sh @@ -1,16 +1,30 @@ #!/bin/bash +cmd="" action=build -if [ $# -eq 1 ] && [ "$1" == "manifest" ]; then - action=manifest +namespace="teamkujira" +if [ $# -gt 0 ]; then + if [ "$1" == "manifest" ]; then + action=manifest + fi + + if [ "$1" == "docker" ] || [ "$1" == "podman" ]; then + cmd="$1" + fi + + if [ $# -eq 2 ]; then + namespace=$2 + fi fi -if [ -n "$(which docker)" ]; then - cmd=docker -elif [ -n "$(which podman)" ]; then - cmd=podman -else - exit 1 +if [ -z "$cmd" ]; then + if [ -n "$(which docker)" ]; then + cmd=docker + elif [ -n "$(which podman)" ]; then + cmd=podman + else + exit 1 + fi fi arch=$(arch) @@ -18,7 +32,7 @@ arch=$(arch) # kujirad go_version=1.20.2 kujira_version=v0.9.0 -tag=teamkujira/kujirad:${kujira_version} +tag=${namespace}/kujirad:${kujira_version} if [ "$action" == "build" ]; then $cmd build \ @@ -38,7 +52,7 @@ fi # feeder go_version=1.20.2 feeder_version=next -tag=teamkujira/feeder:${feeder_version} +tag=${namespace}/feeder:${feeder_version} if [ "$action" == "build" ]; then $cmd build \ @@ -58,7 +72,7 @@ fi # prepare prepare_version=latest -tag=teamkujira/prepare:${prepare_version} +tag=${namespace}/prepare:${prepare_version} if [ "$action" == "build" ]; then $cmd build \ diff --git a/prepare/prepare.py b/prepare/prepare.py index 9c662d0..d690aa1 100644 --- a/prepare/prepare.py +++ b/prepare/prepare.py @@ -18,6 +18,7 @@ class Chain: port_prefix = 1 podman = False rpc_port = "" + api_port = "" def __init__(self, name, chain_id, denom, num_validators, port_prefix, podman): self.name = name @@ -39,6 +40,7 @@ def __init__(self, name, chain_id, denom, num_validators, port_prefix, podman): info, gentx = self.prepare_gentxs(chain_id, home) info["rpc_port"] = f"{self.port_prefix}{i:02}57" + info["api_port"] = f"{self.port_prefix}{i:02}17" self.validators.append(info) gentxs.append(gentx) @@ -259,11 +261,13 @@ def main(): for validator in chain.validators: validator["rpc_url"] = f"http://localhost:{validator['rpc_port']}" + validator["api_url"] = f"http://localhost:{validator['api_port']}" validator.pop("rpc_port") + validator.pop("api_port") validator.pop("amount") chain_info["validators"].append(validator) - + info["chains"][chain.chain_id] = chain_info json.dump(info, open(f"{WORKDIR}/info.json", "w")) diff --git a/prepare/templates/app.toml.j2 b/prepare/templates/app.toml.j2 index db2ef98..c42bb09 100644 --- a/prepare/templates/app.toml.j2 +++ b/prepare/templates/app.toml.j2 @@ -121,7 +121,7 @@ enable = true swagger = false # Address defines the API server to listen on. -address = "tcp://127.0.0.1:{{ api_port }}" +address = "tcp://0.0.0.0:{{ api_port }}" # MaxOpenConnections defines the number of maximum open connections. max-open-connections = 1000 diff --git a/prepare/templates/start.sh.j2 b/prepare/templates/start.sh.j2 index 8707062..e378f9d 100644 --- a/prepare/templates/start.sh.j2 +++ b/prepare/templates/start.sh.j2 @@ -4,20 +4,21 @@ cd $(dirname $0) {% if podman -%} podman pod rm --force pond -podman pod create --name pond{% for chain in chains %}{% for validator in chain.validators %} -p {{ validator.rpc_port }}:{{ validator.rpc_port }}{% endfor %}{% endfor %} +podman pod create --name pond{% for chain in chains %}{% for validator in chain.validators %} -p {{ validator.rpc_port }}:{{ validator.rpc_port }} -p {{ validator.api_port }}:{{ validator.api_port }}{% endfor %}{% endfor %} {% else -%} docker network rm pond docker network create pond {% endif -%} {% for chain in chains -%} {% for validator in chain.validators -%} -{% set port = validator.rpc_port %} +{% set rpc_port = validator.rpc_port %} +{% set api_port = validator.api_port %} {% set name = validator.moniker | lower -%} {% if podman %} podman run --name {{ name }} -d --pod pond -v ./{{ name }}:/kujira teamkujira/kujirad:v0.9.0 kujirad --home /kujira start {% else %} docker rm {{ name }} -docker run -e USER=$UID -dp 127.0.0.1:{{ port }}:{{ port }} --network pond --name {{ name }} --network-alias {{ name }} -v ./{{ name }}:/kujira teamkujira/kujirad:v0.9.0 kujirad --home /kujira start +docker run -e USER=$UID -dp 127.0.0.1:{{ rpc_port }}:{{ rpc_port }} -p 127.0.0.1:{{ api_port }}:{{ api_port }} --network pond --name {{ name }} --network-alias {{ name }} -v ./{{ name }}:/kujira teamkujira/kujirad:v0.9.0 kujirad --home /kujira start {% endif %} {% endfor -%} {% endfor %}