From a4cc0ef961591abd77d1dacd322a0a603537bac7 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 6 Sep 2023 17:47:43 +0200 Subject: [PATCH 1/2] feat: baedeker helper scripts --- .baedeker/.gitignore | 4 + .baedeker/down.sh | 6 ++ .baedeker/rewrites.example.jsonnet | 17 ++++ .baedeker/up.sh | 6 ++ .envrc | 45 +++++++++ launch-config-full.json | 125 ----------------------- launch-config.json | 154 ----------------------------- launch-testnet-full.sh | 6 -- launch-testnet.sh | 6 -- launch-zombienet.toml | 40 -------- 10 files changed, 78 insertions(+), 331 deletions(-) create mode 100644 .baedeker/.gitignore create mode 100755 .baedeker/down.sh create mode 100644 .baedeker/rewrites.example.jsonnet create mode 100755 .baedeker/up.sh create mode 100644 .envrc delete mode 100644 launch-config-full.json delete mode 100644 launch-config.json delete mode 100755 launch-testnet-full.sh delete mode 100755 launch-testnet.sh delete mode 100644 launch-zombienet.toml diff --git a/.baedeker/.gitignore b/.baedeker/.gitignore new file mode 100644 index 0000000000..fb2b1c2276 --- /dev/null +++ b/.baedeker/.gitignore @@ -0,0 +1,4 @@ +/.bdk-env +/rewrites.jsonnet +/vendor +/baedeker-library diff --git a/.baedeker/down.sh b/.baedeker/down.sh new file mode 100755 index 0000000000..c60bd5a1ac --- /dev/null +++ b/.baedeker/down.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -e +BDK_DIR=$(dirname $(readlink -f "$0")) +cd $BDK_DIR/.bdk-env +docker compose down -v --remove-orphans +rm -rf discover.env secret specs diff --git a/.baedeker/rewrites.example.jsonnet b/.baedeker/rewrites.example.jsonnet new file mode 100644 index 0000000000..322cbc30dd --- /dev/null +++ b/.baedeker/rewrites.example.jsonnet @@ -0,0 +1,17 @@ +local dotenv = { + [std.splitLimit(line, "=", 2)[0]]: std.splitLimit(line, "=", 2)[1] + for line in std.split(importstr "../.env", "\n") + if line != "" + if std.member(line, "=") +}; + +function(prev, repoDir) +(import 'baedeker-library/ops/rewrites.libsonnet').rewriteNodePaths({ + 'bin/unique':'%s/target/release/unique-collator' % repoDir, + 'bin/polkadot':{dockerImage:'uniquenetwork/builder-polkadot:%s' % dotenv.POLKADOT_MAINNET_BRANCH}, + 'bin/acala':{dockerImage:'uniquenetwork/builder-acala:%s' % dotenv.ACALA_BUILD_BRANCH}, + 'bin/moonbeam':{dockerImage:'uniquenetwork/builder-moonbeam:%s' % dotenv.MOONBEAM_BUILD_BRANCH}, + 'bin/cumulus':{dockerImage:'uniquenetwork/builder-cumulus:%s' % dotenv.STATEMINE_BUILD_BRANCH}, + 'bin/astar':{dockerImage:'uniquenetwork/builder-astar:%s' % dotenv.ASTAR_BUILD_BRANCH}, + 'bin/polkadex':{dockerImage:'uniquenetwork/builder-polkadex:%s' % dotenv.POLKADEX_BUILD_BRANCH}, +})(prev) diff --git a/.baedeker/up.sh b/.baedeker/up.sh new file mode 100755 index 0000000000..7c1404b1c2 --- /dev/null +++ b/.baedeker/up.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -e +BDK_DIR=$(dirname $(readlink -f "$0")) +RUST_LOG=info baedeker --spec=docker -J$BDK_DIR --generator=docker_compose=$BDK_DIR/.bdk-env --generator=docker_compose_discover=$BDK_DIR/.bdk-env/discover.env --secret=file=$BDK_DIR/.bdk-env/secret --tla-str=relay_spec=rococo-local --input-modules='lib:baedeker-library/ops/nginx.libsonnet' --input-modules='lib:baedeker-library/ops/devtools.libsonnet' $@ $BDK_DIR/rewrites.jsonnet +cd $BDK_DIR/.bdk-env +docker compose up -d --wait --remove-orphans diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..2c3c1cf7dc --- /dev/null +++ b/.envrc @@ -0,0 +1,45 @@ +#!/bin/sh + +# Load .envrc from parent directories +source_up_if_exists +# Common variables from .env +dotenv + +RED='\033[0;31m' +GREEN='\033[0;32m' +RESET='\033[0m' + +dep_not_found=false +function check_bdk { + if ! has $1; then + echo -e "${RED}$1 not found (wanted for beadeker discovery)${RESET}" + dep_not_found=true + fi +} + +watch_file .baedeker/.bdk-env/discover.env +if test -f .baedeker/.bdk-env/discover.env; then + check_bdk baedeker + check_bdk docker + check_bdk jq + if $dep_not_found; then + echo -e "${RED}Not performing bdk discovery${RESET}" + exit 0 + fi + + echo -e "${GREEN}Baedeker env updated${RESET}" + nginx_id=$(docker compose -f $PWD/.bdk-env/docker-compose.yml ps --format=json | jq -r '.[] | select(.Service == "nginx") | .ID' -e) + if ! [ $? -eq 0 ]; then + echo -e "${RED}Nginx container not found${RESET}" + exit 0 + fi + nginx_ip=$(docker inspect $nginx_id | jq -r -e '.[0].NetworkSettings.Networks[].IPAddress') + if ! [ $? -eq 0 ]; then + echo -e "${RED}Nginx container network misconfigured?${RESET}" + exit 0 + fi + tmpenv=$(mktemp) + cat .baedeker/.bdk-env/discover.env | sed "s|BALANCER_URL|$nginx_ip|g" > $tmpenv + dotenv $tmpenv + echo -e "${GREEN}Enjoy your baedeker networks at $(echo $BDK_BALANCER || sed "s|BALANCER_URL|$nginx_ip|g")${RESET}" +fi diff --git a/launch-config-full.json b/launch-config-full.json deleted file mode 100644 index 0a4df36611..0000000000 --- a/launch-config-full.json +++ /dev/null @@ -1,125 +0,0 @@ -{ - "relaychain": { - "bin": "../polkadot/target/release/polkadot", - "chain": "westend-local", - "nodes": [ - { - "name": "alice", - "rpcPort": 9844, - "port": 30444, - "flags": [ - "-lparachain::candidate_validation=debug", - "-lxcm=trace" - ] - }, - { - "name": "bob", - "rpcPort": 9855, - "port": 30555, - "flags": [ - "-lparachain::candidate_validation=debug", - "-lxcm=trace" - ] - }, - { - "name": "charlie", - "rpcPort": 9866, - "port": 30666, - "flags": [ - "-lparachain::candidate_validation=debug" - ] - }, - { - "name": "dave", - "rpcPort": 9877, - "port": 30777, - "flags": [ - "-lparachain::candidate_validation=debug" - ] - }, - { - "name": "eve", - "rpcPort": 9888, - "port": 30888, - "flags": [ - "-lparachain::candidate_validation=debug" - ] - } - ], - "genesis": { - "runtime": { - "runtime_genesis_config": { - "parachainsConfiguration": { - "config": { - "validation_upgrade_frequency": 1, - "validation_upgrade_delay": 1 - } - } - } - } - } - }, - "parachains": [ - { - "bin": "../unique-chain/target/release/unique-collator", - "id": "1000", - "balance": "1000000000000000000000000", - "nodes": [ - { - "port": 31200, - "rpcPort": 9944, - "name": "alice", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - }, - { - "port": 31201, - "rpcPort": 9945, - "name": "bob", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - } - ] - }, - { - "bin": "../Acala/target/release/acala", - "id": "2000", - "chain": "karura-dev", - "balance": "1000000000000000000000", - "nodes": [ - { - "rpcPort": 9946, - "port": 31202, - "name": "alice", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - } - ] - } - ], - "simpleParachains": [], - "hrmpChannels": [ - { - "sender": 2000, - "recipient": 1000, - "maxCapacity": 8, - "maxMessageSize": 512 - }, - { - "sender": 1000, - "recipient": 2000, - "maxCapacity": 8, - "maxMessageSize": 512 - } - ], - "finalization": false -} diff --git a/launch-config.json b/launch-config.json deleted file mode 100644 index 2cd5d5ac32..0000000000 --- a/launch-config.json +++ /dev/null @@ -1,154 +0,0 @@ -{ - "relaychain": { - "bin": "../polkadot/target/release/polkadot", - "chain": "rococo-local", - "nodes": [ - { - "name": "alice", - "rpcPort": 9844, - "port": 30444, - "flags": [ - "-lxcm=trace", - "-ltrace", - "-lnetlink_proto=info", - "-lnetlink_sys=info", - "-lwasmtime_cranelift=info", - "-ltrie-cache=info", - "-lwasm-heap=info", - "-lmultistream_select=warn", - "-llibp2p_swarm=warn", - "-llibp2p_ping=warn", - "-llibp2p_noise=warn", - "-lwasm_overrides=warn", - "-lsc_allocator=warn", - "-ljsonrpsee_core=warn", - "-lsoketto=warn", - "-lrpc_metrics=warn", - "-lsubstrate=warn", - "-ltrie=debug", - "--rpc-cors=all", - "--unsafe-rpc-external" - ] - }, - { - "name": "bob", - "rpcPort": 9855, - "port": 30555, - "flags": [ - "-lparachain::candidate_validation=debug", - "-lxcm=trace", - "--rpc-cors=all", - "--unsafe-rpc-external" - ] - }, - { - "name": "charlie", - "rpcPort": 9866, - "port": 30666, - "flags": [ - "-lparachain::candidate_validation=debug", - "-lxcm=trace", - "--rpc-cors=all", - "--unsafe-rpc-external" - ] - }, - { - "name": "dave", - "rpcPort": 9877, - "port": 30777, - "flags": [ - "-lparachain::candidate_validation=debug", - "-lxcm=trace", - "--rpc-cors=all", - "--unsafe-rpc-external" - ] - }, - { - "name": "eve", - "rpcPort": 9888, - "port": 30888, - "flags": [ - "-lparachain::candidate_validation=debug", - "-lxcm=trace", - "--rpc-cors=all", - "--unsafe-rpc-external" - ] - } - ], - "genesis": { - "runtime": { - "runtime_genesis_config": { - "parachainsConfiguration": { - "config": { - "validation_upgrade_frequency": 1, - "validation_upgrade_delay": 1 - } - } - } - } - } - }, - "parachains": [ - { - "bin": "../unique-chain/target/release/unique-collator", - "id": 1000, - "balance": "1000000000000000000000000", - "nodes": [ - { - "port": 31200, - "rpcPort": 9944, - "name": "alice", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace", - "-lruntime=debug" - ] - }, - { - "port": 31201, - "rpcPort": 9945, - "name": "bob", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - }, - { - "port": 31202, - "rpcPort": 9946, - "name": "charlie", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - }, - { - "port": 31203, - "rpcPort": 9947, - "name": "dave", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - }, - { - "port": 31204, - "rpcPort": 9948, - "name": "eve", - "flags": [ - "--rpc-cors=all", - "--unsafe-rpc-external", - "-lxcm=trace" - ] - } - ] - } - ], - "simpleParachains": [], - "hrmpChannels": [], - "finalization": false -} \ No newline at end of file diff --git a/launch-testnet-full.sh b/launch-testnet-full.sh deleted file mode 100755 index 092e216f11..0000000000 --- a/launch-testnet-full.sh +++ /dev/null @@ -1,6 +0,0 @@ -cp launch-config-full.json ../polkadot-launch/launch-config-full.json - -cd ../polkadot-launch -yarn install -yarn build -yarn start launch-config-full.json diff --git a/launch-testnet.sh b/launch-testnet.sh deleted file mode 100755 index 94b20e0529..0000000000 --- a/launch-testnet.sh +++ /dev/null @@ -1,6 +0,0 @@ -cp launch-config.json ../polkadot-launch/launch-config.json - -cd ../polkadot-launch -yarn install -yarn build -yarn start launch-config.json diff --git a/launch-zombienet.toml b/launch-zombienet.toml deleted file mode 100644 index a5d79854a0..0000000000 --- a/launch-zombienet.toml +++ /dev/null @@ -1,40 +0,0 @@ -# To launch this zombienet out-of-the-box, run `yarn frankenstein` in the `tests` folder. - -[settings] -provider = "native" - -[relaychain] -# RELAY_DIR is an environment variable. If you're launching ZN from the repository's root, you should likely specify it as ../polkadot/ -default_command = "{{RELAY_DIR}}target/release/polkadot" -default_args = [ "-lparachain::candidate_validation=debug", "-lxcm=trace", ] -chain = "rococo-local" - - [[relaychain.nodes]] - name = "relay-alice" - rpc_port = 9844 - p2p_port = 30444 - # Zombienet does not grant the default balance to nodes created with [[nodes]]. - balance = 2000000000000 - - [[relaychain.node_groups]] - name = "relay" - count = 4 - -[[parachains]] -id = 1000 - - [[parachains.collators]] - name = "alice" - # PARA_DIR is an environment variable. If you're launching ZN from the repository's root, you should likely specify it as ./ - command = "{{PARA_DIR}}target/release/unique-collator" - rpc_port = 9944 - p2p_port = 31200 - args = [ "-lxcm=trace", ] - - [[parachains.collators]] - name = "bob" - # PARA_DIR is an environment variable. If you're launching ZN from the repository's root, you should likely specify it as ./ - command = "{{PARA_DIR}}target/release/unique-collator" - rpc_port = 9945 - p2p_port = 31201 - args = [ "-lxcm=trace", ] From 3567b2a05d8283bcd1bde73629358879073c735e Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 6 Sep 2023 23:07:51 +0200 Subject: [PATCH 2/2] ci: set repoDir tla-str by default --- .baedeker/up.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.baedeker/up.sh b/.baedeker/up.sh index 7c1404b1c2..8a1c6121cf 100755 --- a/.baedeker/up.sh +++ b/.baedeker/up.sh @@ -1,6 +1,6 @@ #!/bin/sh set -e BDK_DIR=$(dirname $(readlink -f "$0")) -RUST_LOG=info baedeker --spec=docker -J$BDK_DIR --generator=docker_compose=$BDK_DIR/.bdk-env --generator=docker_compose_discover=$BDK_DIR/.bdk-env/discover.env --secret=file=$BDK_DIR/.bdk-env/secret --tla-str=relay_spec=rococo-local --input-modules='lib:baedeker-library/ops/nginx.libsonnet' --input-modules='lib:baedeker-library/ops/devtools.libsonnet' $@ $BDK_DIR/rewrites.jsonnet +RUST_LOG=info baedeker --spec=docker -J$BDK_DIR --generator=docker_compose=$BDK_DIR/.bdk-env --generator=docker_compose_discover=$BDK_DIR/.bdk-env/discover.env --secret=file=$BDK_DIR/.bdk-env/secret --tla-str=relay_spec=rococo-local --input-modules='lib:baedeker-library/ops/nginx.libsonnet' --input-modules='lib:baedeker-library/ops/devtools.libsonnet' --tla-str=repoDir=$(realpath $BDK_DIR/..) $@ $BDK_DIR/rewrites.jsonnet cd $BDK_DIR/.bdk-env docker compose up -d --wait --remove-orphans