From ee2e25591349f5bb7ad17c57fc33feb1727ea73f Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Mon, 3 Dec 2018 17:41:00 +0100 Subject: [PATCH 1/9] Configure docker for boot node deployment. Introduce startup script for connecting to KILT test net. Improve documentation. --- Dockerfile | 10 +++++++++- README.md | 15 +++++++++++++++ build.sh | 5 +---- connect.sh | 25 +++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) create mode 100755 connect.sh diff --git a/Dockerfile b/Dockerfile index 66790a326..9c443608b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,4 +58,12 @@ EXPOSE 30333 9933 9944 RUN ls -la . -CMD ["cargo", "run", "--", "dev"] \ No newline at end of file +# boot node for Alice: +# ./target/debug/node --chain local --key Alice --name "ALICE" --node-key 0000000000000000000000000000000000000000000000000000000000000001 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 +# Alice's address: /ip4/0.0.0.0/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN + +# boot node for Bob: +# ./target/debug/node --chain local --key Bob --name "BOB" --node-key 0000000000000000000000000000000000000000000000000000000000000002 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 +# Bobs address: /ip4/0.0.0.0/tcp/30333/p2p/QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK + +CMD ["./target/debug/node", "--chain", "local", "--key", "Alice", "--name", "\"ALICE\"", "--node-key", "0000000000000000000000000000000000000000000000000000000000000001", "--validator"] \ No newline at end of file diff --git a/README.md b/README.md index cb97047d3..c6d7d7203 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,18 @@ A new SRML-based Substrate node, ready for hacking docker build -t substrate-poc . docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 --publish-all=true -it substrate-poc ``` + +## Running a local node that connects to the KILT prototype test net + +There are 2 boot nodes running in the KILT test net: + +* bootnode-alice +* bootnode-bob + +To connect to the Alice node you can use the shell script `connect.sh`: + +``` +connect.sh --key Charly --name "CHARLY" +``` + +You can use any of the accounts declared in the chain spec to connect. diff --git a/build.sh b/build.sh index 55b53039a..f19200850 100755 --- a/build.sh +++ b/build.sh @@ -8,16 +8,13 @@ PROJECT_ROOT=`pwd` export CARGO_INCREMENTAL=0 -bold=$(tput bold) -normal=$(tput sgr0) - # Save current directory. pushd . >/dev/null for SRC in runtime/wasm do echo "$PROJECT_ROOT/$SRC" - echo "${bold}Building webassembly binary in $SRC...${normal}" + echo "Building webassembly binary in $SRC..." cd "$PROJECT_ROOT/$SRC" chmod a+x build.sh diff --git a/connect.sh b/connect.sh new file mode 100755 index 000000000..b348404ba --- /dev/null +++ b/connect.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +ALICE_BOOT_NODE_DOMAIN=bootnode-alice.kilt-prototype.tk +ALICE_BOOT_NODE_IP=`dig $ALICE_BOOT_NODE_DOMAIN A +short` +ALICE_BOOT_NODE_KEY=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY + +BOB_BOOT_NODE_DOMAIN=bootnode-bob.kilt-prototype.tk +BOB_BOOT_NODE_IP=`dig $BOB_BOOT_NODE_DOMAIN A +short` +BOB_BOOT_NODE_KEY=QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK +BOB_BOOT_NODE_IPFS=/ip4/$BOB_BOOT_NODE_IP/tcp/30333/p2p/$BOB_BOOT_NODE_KEY + +echo "ALICE_BOOT_NODE_DOMAIN: $ALICE_BOOT_NODE_DOMAIN" +echo "ALICE_BOOT_NODE_IP: $ALICE_BOOT_NODE_IP" +echo "BOB_BOOT_NODE_DOMAIN: $BOB_BOOT_NODE_DOMAIN" +echo "BOB_BOOT_NODE_IP: $BOB_BOOT_NODE_IP" + +# Connect to Alice +echo "Connecting to $ALICE_BOOT_NODE_IPFS..." +./target/debug/node --chain local --bootnodes $ALICE_BOOT_NODE_IPFS --port 30334 --validator "$@" + +# Connect to Bob +# echo "Connecting to $BOB_BOOT_NODE_IPFS..." +# ./target/debug/node --chain local --bootnodes $BOB_BOOT_NODE_IPFS --port 30334 --validator "$@" + From dfc616c3c129991715159ef4cd774cfbebc29394 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Mon, 3 Dec 2018 17:47:46 +0100 Subject: [PATCH 2/9] Configure AWS CodePipeline to use prototype registry and redeploy both boot nodes --- buildspec.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildspec.yml b/buildspec.yml index 3eb09d556..30e67d171 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -6,7 +6,7 @@ phases: - echo Logging in to Amazon ECR... - aws --version - $(aws ecr get-login --region eu-central-1 --no-include-email) - - REPOSITORY_URI=348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/substrate-poc + - REPOSITORY_URI=348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain - 'IMAGE_TAG=$(sed -n ''s/version = "\(.*\)"$/\1/p'' Cargo.toml)' - docker pull $REPOSITORY_URI:latest || true build: @@ -22,6 +22,6 @@ phases: - docker push $REPOSITORY_URI:latest - docker push $REPOSITORY_URI:$IMAGE_TAG - echo Writing image definitions file... - - printf '[{"name":"substrate-poc","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json + - printf '[{"name":"prototype-bootnode-alice","imageUri":"%s"}, {"name":"prototype-bootnode-bob","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json artifacts: files: imagedefinitions.json From f2294b0a85e69bec7fe7d76ae34e3c49b132f7e4 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Mon, 3 Dec 2018 17:56:05 +0100 Subject: [PATCH 3/9] Fix documentation --- README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c6d7d7203..7e709e53f 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,8 @@ -# substrate-poc -A new SRML-based Substrate node, ready for hacking +# prototype-chain -## Run inside docker container +Substrate node implementation for the KILT prototype -``` -docker build -t substrate-poc . -docker run -p 9933:9933 -p 9944:9944 -p 30333:30333 --publish-all=true -it substrate-poc -``` - -## Running a local node that connects to the KILT prototype test net +## Running a local node that connects to the KILT prototype test environment in AWS There are 2 boot nodes running in the KILT test net: @@ -21,4 +15,4 @@ To connect to the Alice node you can use the shell script `connect.sh`: connect.sh --key Charly --name "CHARLY" ``` -You can use any of the accounts declared in the chain spec to connect. +You can use any of the accounts declared in the chain spec to connect (Alice, Bob, Charly, Dave, Eve, Ferdie). From e83f9868d17b755ddfe15a902c613f75b37646a5 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Mon, 3 Dec 2018 21:19:32 +0100 Subject: [PATCH 4/9] Restructure ECS services for independent boot node deployment --- buildspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildspec.yml b/buildspec.yml index 30e67d171..9e52eba21 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -22,6 +22,6 @@ phases: - docker push $REPOSITORY_URI:latest - docker push $REPOSITORY_URI:$IMAGE_TAG - echo Writing image definitions file... - - printf '[{"name":"prototype-bootnode-alice","imageUri":"%s"}, {"name":"prototype-bootnode-bob","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json + - printf '[{"name":"prototype-bootnode","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json artifacts: files: imagedefinitions.json From 7d806d9d183d7f8adfaca84e57dee296f8fffd5e Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Tue, 4 Dec 2018 14:38:34 +0100 Subject: [PATCH 5/9] KP-86: Reduce footprint of final image, add shell scripts for convenience use, rename "local-testnet" to "kilt-testnet" --- Dockerfile | 37 +++++++++++++++------- README.md | 38 +++++++++++++++++++---- connect.sh | 25 --------------- scripts/kilt-master-bootnode-testnet.sh | 12 +++++++ scripts/kilt-node-testnet.sh | 27 ++++++++++++++++ scripts/lookup-master-bootnode-testnet.sh | 18 +++++++++++ src/chain_spec.rs | 10 +++--- 7 files changed, 119 insertions(+), 48 deletions(-) delete mode 100755 connect.sh create mode 100755 scripts/kilt-master-bootnode-testnet.sh create mode 100755 scripts/kilt-node-testnet.sh create mode 100755 scripts/lookup-master-bootnode-testnet.sh diff --git a/Dockerfile b/Dockerfile index 9c443608b..c49e914b2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM ubuntu:xenial +FROM ubuntu:xenial as builder -WORKDIR /substrate +WORKDIR /build # install tools and dependencies RUN apt -y update && \ @@ -48,22 +48,35 @@ ENV CXX g++ ENV LC_ALL=C.UTF-8 ENV LANG=C.UTF-8 -COPY . /substrate +COPY . /build RUN /bin/bash build.sh RUN cargo build && cargo test -EXPOSE 30333 9933 9944 -RUN ls -la . +FROM ubuntu:xenial -# boot node for Alice: -# ./target/debug/node --chain local --key Alice --name "ALICE" --node-key 0000000000000000000000000000000000000000000000000000000000000001 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 -# Alice's address: /ip4/0.0.0.0/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +WORKDIR /runtime +RUN mkdir -p /runtime/target/debug/ +COPY --from=builder /build/target/debug/node ./target/debug/node +COPY --from=builder /build/scripts/kilt-node-testnet.sh ./kilt-node-testnet.sh +COPY --from=builder /build/scripts/lookup-master-bootnode-testnet.sh ./lookup-master-bootnode-testnet.sh +COPY --from=builder /build/scripts/kilt-master-bootnode-testnet.sh ./kilt-master-bootnode-testnet.sh -# boot node for Bob: -# ./target/debug/node --chain local --key Bob --name "BOB" --node-key 0000000000000000000000000000000000000000000000000000000000000002 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 -# Bobs address: /ip4/0.0.0.0/tcp/30333/p2p/QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK +RUN chmod a+x *.sh +RUN ls -la . + +# expose node ports +EXPOSE 30333 9933 9944 -CMD ["./target/debug/node", "--chain", "local", "--key", "Alice", "--name", "\"ALICE\"", "--node-key", "0000000000000000000000000000000000000000000000000000000000000001", "--validator"] \ No newline at end of file +# +# Pass the node start command to the docker run command +# +# To start a master boot node (no initial connection to other nodes): +# ./kilt-master-bootnode-testnet.sh --key Alice --name "ALICE" --node-key 0000000000000000000000000000000000000000000000000000000000000001 +# +# To start a node that connects to the master bootnode: +# ./kilt-node-testnet.sh --key Charly --name "CHARLY" +# +CMD ["echo","\"Please provide a startup command.\""] diff --git a/README.md b/README.md index 7e709e53f..d9cf1a352 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,43 @@ Substrate node implementation for the KILT prototype -## Running a local node that connects to the KILT prototype test environment in AWS +## Running a local node that connects to the KILT prototype testnet in AWS -There are 2 boot nodes running in the KILT test net: +There is a master boot node running in the KILT testnet: -* bootnode-alice -* bootnode-bob +* bootnode-alice (bootnode-alice.kilt-prototype.tk) -To connect to the Alice node you can use the shell script `connect.sh`: +To connect to the Alice node you can use the shell script `kilt-node-testnet.sh`: ``` -connect.sh --key Charly --name "CHARLY" +cd scripts/ +kilt-node-testnet.sh --key Charly --name "CHARLY" ``` You can use any of the accounts declared in the chain spec to connect (Alice, Bob, Charly, Dave, Eve, Ferdie). + + +### Running a node inside a docker container + +Make sure to have the `awscli` installed. Otherwise Install it via `brew install awscli` (Mac). +You also need to have your docker daemon system running (on mac, just download the docker application). + +Login to Amazon ECR + +``` + $(aws ecr get-login --no-include-email --region eu-central-1) +``` + +Pull the latest image from Amazon ECR + +``` +docker pull 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain:latest +``` + +Run the image and pass the command to start a node + +``` +docker run 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain ./kilt-node-testnet.sh --key Charly --name "CHARLY" +``` + +The node should be connected to the KILT testnet. \ No newline at end of file diff --git a/connect.sh b/connect.sh deleted file mode 100755 index b348404ba..000000000 --- a/connect.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -ALICE_BOOT_NODE_DOMAIN=bootnode-alice.kilt-prototype.tk -ALICE_BOOT_NODE_IP=`dig $ALICE_BOOT_NODE_DOMAIN A +short` -ALICE_BOOT_NODE_KEY=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN -ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY - -BOB_BOOT_NODE_DOMAIN=bootnode-bob.kilt-prototype.tk -BOB_BOOT_NODE_IP=`dig $BOB_BOOT_NODE_DOMAIN A +short` -BOB_BOOT_NODE_KEY=QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK -BOB_BOOT_NODE_IPFS=/ip4/$BOB_BOOT_NODE_IP/tcp/30333/p2p/$BOB_BOOT_NODE_KEY - -echo "ALICE_BOOT_NODE_DOMAIN: $ALICE_BOOT_NODE_DOMAIN" -echo "ALICE_BOOT_NODE_IP: $ALICE_BOOT_NODE_IP" -echo "BOB_BOOT_NODE_DOMAIN: $BOB_BOOT_NODE_DOMAIN" -echo "BOB_BOOT_NODE_IP: $BOB_BOOT_NODE_IP" - -# Connect to Alice -echo "Connecting to $ALICE_BOOT_NODE_IPFS..." -./target/debug/node --chain local --bootnodes $ALICE_BOOT_NODE_IPFS --port 30334 --validator "$@" - -# Connect to Bob -# echo "Connecting to $BOB_BOOT_NODE_IPFS..." -# ./target/debug/node --chain local --bootnodes $BOB_BOOT_NODE_IPFS --port 30334 --validator "$@" - diff --git a/scripts/kilt-master-bootnode-testnet.sh b/scripts/kilt-master-bootnode-testnet.sh new file mode 100755 index 000000000..cae71a285 --- /dev/null +++ b/scripts/kilt-master-bootnode-testnet.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# +# This script starts a kilt master boot node with provided account, name and node-key +# +# Run: +# ./kilt-master-bootnode-testnet.sh --key Alice --name "ALICE" --node-key 0000000000000000000000000000000000000000000000000000000000000001 +# + +echo "Starting KILT master boot node..." +./../target/debug/node --chain kilt-testnet --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" + diff --git a/scripts/kilt-node-testnet.sh b/scripts/kilt-node-testnet.sh new file mode 100755 index 000000000..696b3eaa8 --- /dev/null +++ b/scripts/kilt-node-testnet.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# +# This script starts a kilt node and connects to the master boot node of the KILT testnet. +# +# Run: +# ./kilt-node-testnet.sh --key Charly --name "CHARLY" +# + +ALICE_BOOT_NODE_DOMAIN=bootnode-alice.kilt-prototype.tk +ALICE_BOOT_NODE_IP=`dig $ALICE_BOOT_NODE_DOMAIN A +short` +ALICE_BOOT_NODE_KEY=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY + + +#BOB_BOOT_NODE_DOMAIN=bootnode-bob.kilt-prototype.tk +#BOB_BOOT_NODE_IP=`dig $BOB_BOOT_NODE_DOMAIN A +short` +#BOB_BOOT_NODE_KEY=QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK +#BOB_BOOT_NODE_IPFS=/ip4/$BOB_BOOT_NODE_IP/tcp/30333/p2p/$BOB_BOOT_NODE_KEY + +MASTER_BOOT_NODE_IPFS=`./lookup-master-bootnode-testnet.sh` + + +# Connect to master boot node +echo "Master boot node: $MASTER_BOOT_NODE_IPFS..." +./../target/debug/node --chain kilt-testnet --bootnodes $MASTER_BOOT_NODE_IPFS --port 30333 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" + diff --git a/scripts/lookup-master-bootnode-testnet.sh b/scripts/lookup-master-bootnode-testnet.sh new file mode 100755 index 000000000..ec49b0b84 --- /dev/null +++ b/scripts/lookup-master-bootnode-testnet.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# +# This script performs a lookup for the master boot node and prints out its ipfs address. +# +# Run: +# ./lookup-master-bootnode-testnet.sh +# Prints out the IPFS of the master boot node: +# e.g.: +# /ip4/3.120.148.48/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +# + +ALICE_BOOT_NODE_DOMAIN=bootnode-alice.kilt-prototype.tk +ALICE_BOOT_NODE_IP=`dig $ALICE_BOOT_NODE_DOMAIN A +short` +ALICE_BOOT_NODE_KEY=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY + +echo $ALICE_BOOT_NODE_IPFS \ No newline at end of file diff --git a/src/chain_spec.rs b/src/chain_spec.rs index 2e6815c0b..fe6c7bf3a 100644 --- a/src/chain_spec.rs +++ b/src/chain_spec.rs @@ -16,7 +16,7 @@ pub enum Alternative { /// Whatever the current runtime is, with just Alice as an auth. Development, /// Whatever the current runtime is, with simple Alice/Bob auths. - LocalTestnet, + KiltTestnet, } impl Alternative { @@ -39,9 +39,9 @@ impl Alternative { None, None ), - Alternative::LocalTestnet => ChainSpec::from_genesis( - "Local Testnet", - "local_testnet", + Alternative::KiltTestnet => ChainSpec::from_genesis( + "KILT Testnet", + "kilt_testnet", || testnet_genesis(vec![ ed25519::Pair::from_seed(b"Alice ").public().into(), ed25519::Pair::from_seed(b"Bob ").public().into(), @@ -67,7 +67,7 @@ impl Alternative { pub(crate) fn from(s: &str) -> Option { match s { "dev" => Some(Alternative::Development), - "local" => Some(Alternative::LocalTestnet), + "kilt-testnet" => Some(Alternative::KiltTestnet), _ => None, } } From 8a37bbc1dd792e66eb365f9431fccc352ba534b8 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Tue, 4 Dec 2018 16:10:48 +0100 Subject: [PATCH 6/9] KP-86: Reduce footprint of final image, add shell scripts for convenience use, rename "local-testnet" to "kilt-testnet" --- Dockerfile | 13 ++++++++++--- ...de-testnet.sh => kilt-master-bootnode-testnet.sh | 2 +- .../kilt-node-testnet.sh => kilt-node-testnet.sh | 2 +- ...-testnet.sh => lookup-master-bootnode-testnet.sh | 0 4 files changed, 12 insertions(+), 5 deletions(-) rename scripts/kilt-master-bootnode-testnet.sh => kilt-master-bootnode-testnet.sh (70%) rename scripts/kilt-node-testnet.sh => kilt-node-testnet.sh (82%) rename scripts/lookup-master-bootnode-testnet.sh => lookup-master-bootnode-testnet.sh (100%) diff --git a/Dockerfile b/Dockerfile index c49e914b2..ac9e08ced 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,11 +58,18 @@ RUN cargo build && cargo test FROM ubuntu:xenial WORKDIR /runtime + +RUN apt -y update && \ + apt install -y --no-install-recommends \ + software-properties-common curl file binutils binutils-dev snapcraft \ + ca-certificates zip dpkg-dev python rhash rpm openssl gettext\ + build-essential pkg-config libssl-dev libudev-dev ruby-dev time + RUN mkdir -p /runtime/target/debug/ COPY --from=builder /build/target/debug/node ./target/debug/node -COPY --from=builder /build/scripts/kilt-node-testnet.sh ./kilt-node-testnet.sh -COPY --from=builder /build/scripts/lookup-master-bootnode-testnet.sh ./lookup-master-bootnode-testnet.sh -COPY --from=builder /build/scripts/kilt-master-bootnode-testnet.sh ./kilt-master-bootnode-testnet.sh +COPY --from=builder /build/kilt-node-testnet.sh ./kilt-node-testnet.sh +COPY --from=builder /build/lookup-master-bootnode-testnet.sh ./lookup-master-bootnode-testnet.sh +COPY --from=builder /build/kilt-master-bootnode-testnet.sh ./kilt-master-bootnode-testnet.sh RUN chmod a+x *.sh RUN ls -la . diff --git a/scripts/kilt-master-bootnode-testnet.sh b/kilt-master-bootnode-testnet.sh similarity index 70% rename from scripts/kilt-master-bootnode-testnet.sh rename to kilt-master-bootnode-testnet.sh index cae71a285..df9010d94 100755 --- a/scripts/kilt-master-bootnode-testnet.sh +++ b/kilt-master-bootnode-testnet.sh @@ -8,5 +8,5 @@ # echo "Starting KILT master boot node..." -./../target/debug/node --chain kilt-testnet --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" +./target/debug/node --chain kilt-testnet --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" diff --git a/scripts/kilt-node-testnet.sh b/kilt-node-testnet.sh similarity index 82% rename from scripts/kilt-node-testnet.sh rename to kilt-node-testnet.sh index 696b3eaa8..90b6a42d3 100755 --- a/scripts/kilt-node-testnet.sh +++ b/kilt-node-testnet.sh @@ -23,5 +23,5 @@ MASTER_BOOT_NODE_IPFS=`./lookup-master-bootnode-testnet.sh` # Connect to master boot node echo "Master boot node: $MASTER_BOOT_NODE_IPFS..." -./../target/debug/node --chain kilt-testnet --bootnodes $MASTER_BOOT_NODE_IPFS --port 30333 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" +./target/debug/node --chain kilt-testnet --bootnodes $MASTER_BOOT_NODE_IPFS --port 30333 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" diff --git a/scripts/lookup-master-bootnode-testnet.sh b/lookup-master-bootnode-testnet.sh similarity index 100% rename from scripts/lookup-master-bootnode-testnet.sh rename to lookup-master-bootnode-testnet.sh From cc473be0a62c74b2c89e236fd11106e30a3869d0 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Tue, 4 Dec 2018 16:47:02 +0100 Subject: [PATCH 7/9] KP-86: Install dnsutils package in docker runtime (required for dig) --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ac9e08ced..2824df565 100644 --- a/Dockerfile +++ b/Dockerfile @@ -63,7 +63,7 @@ RUN apt -y update && \ apt install -y --no-install-recommends \ software-properties-common curl file binutils binutils-dev snapcraft \ ca-certificates zip dpkg-dev python rhash rpm openssl gettext\ - build-essential pkg-config libssl-dev libudev-dev ruby-dev time + build-essential pkg-config libssl-dev libudev-dev ruby-dev time dnsutils RUN mkdir -p /runtime/target/debug/ COPY --from=builder /build/target/debug/node ./target/debug/node From 057d35e29b72e8406b899027561f42fa8a867bb8 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Wed, 5 Dec 2018 11:08:59 +0100 Subject: [PATCH 8/9] KP-86: Make nodes ws and rpc ports externally accessible --- kilt-master-bootnode-testnet.sh | 2 +- kilt-node-testnet.sh | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kilt-master-bootnode-testnet.sh b/kilt-master-bootnode-testnet.sh index df9010d94..c54f5493f 100755 --- a/kilt-master-bootnode-testnet.sh +++ b/kilt-master-bootnode-testnet.sh @@ -8,5 +8,5 @@ # echo "Starting KILT master boot node..." -./target/debug/node --chain kilt-testnet --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" +./target/debug/node --chain kilt-testnet --validator --port 30333 --ws-port 9944 --ws-external --rpc-external --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" diff --git a/kilt-node-testnet.sh b/kilt-node-testnet.sh index 90b6a42d3..333b07467 100755 --- a/kilt-node-testnet.sh +++ b/kilt-node-testnet.sh @@ -20,8 +20,7 @@ ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY MASTER_BOOT_NODE_IPFS=`./lookup-master-bootnode-testnet.sh` - # Connect to master boot node echo "Master boot node: $MASTER_BOOT_NODE_IPFS..." -./target/debug/node --chain kilt-testnet --bootnodes $MASTER_BOOT_NODE_IPFS --port 30333 --validator --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" +./target/debug/node --chain kilt-testnet --bootnodes $MASTER_BOOT_NODE_IPFS --port 30333 --ws-port 9944 --validator --ws-external --rpc-external --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" From 1dc6d64d588588655ec474fcc1160b39ea560eb7 Mon Sep 17 00:00:00 2001 From: Andreas Pasch Date: Tue, 11 Dec 2018 18:11:21 +0100 Subject: [PATCH 9/9] KP-86: Introduce start script for simplified orchestration, Improve final docker image, Update documentation --- Dockerfile | 22 ++--- README.md | 17 ++-- kilt-master-bootnode-testnet.sh | 12 --- kilt-node-testnet.sh | 26 ------ lookup-master-bootnode-testnet.sh | 18 ---- start-node.sh | 141 ++++++++++++++++++++++++++++++ 6 files changed, 158 insertions(+), 78 deletions(-) delete mode 100755 kilt-master-bootnode-testnet.sh delete mode 100755 kilt-node-testnet.sh delete mode 100755 lookup-master-bootnode-testnet.sh create mode 100755 start-node.sh diff --git a/Dockerfile b/Dockerfile index 2824df565..393888f54 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,10 +9,6 @@ RUN apt -y update && \ make cmake ca-certificates g++ zip dpkg-dev python rhash rpm openssl gettext\ build-essential pkg-config libssl-dev libudev-dev ruby-dev time -#install nodejs -RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - && \ - apt-get install -y nodejs - # install rustup RUN curl https://sh.rustup.rs -sSf | sh -s -- -y @@ -61,15 +57,13 @@ WORKDIR /runtime RUN apt -y update && \ apt install -y --no-install-recommends \ - software-properties-common curl file binutils binutils-dev snapcraft \ - ca-certificates zip dpkg-dev python rhash rpm openssl gettext\ - build-essential pkg-config libssl-dev libudev-dev ruby-dev time dnsutils + openssl \ + curl \ + libssl-dev dnsutils RUN mkdir -p /runtime/target/debug/ COPY --from=builder /build/target/debug/node ./target/debug/node -COPY --from=builder /build/kilt-node-testnet.sh ./kilt-node-testnet.sh -COPY --from=builder /build/lookup-master-bootnode-testnet.sh ./lookup-master-bootnode-testnet.sh -COPY --from=builder /build/kilt-master-bootnode-testnet.sh ./kilt-master-bootnode-testnet.sh +COPY --from=builder /build/start-node.sh ./start-node.sh RUN chmod a+x *.sh RUN ls -la . @@ -80,10 +74,10 @@ EXPOSE 30333 9933 9944 # # Pass the node start command to the docker run command # -# To start a master boot node (no initial connection to other nodes): -# ./kilt-master-bootnode-testnet.sh --key Alice --name "ALICE" --node-key 0000000000000000000000000000000000000000000000000000000000000001 +# To start Alice boot node: +# ./start-node --account-name Alice --telemetry # -# To start a node that connects to the master bootnode: -# ./kilt-node-testnet.sh --key Charly --name "CHARLY" +# To start a node that connects to Alice: +# ./start-node.sh --account-name Charly --connect-to Alice -t # CMD ["echo","\"Please provide a startup command.\""] diff --git a/README.md b/README.md index d9cf1a352..47a99274a 100644 --- a/README.md +++ b/README.md @@ -2,26 +2,27 @@ Substrate node implementation for the KILT prototype -## Running a local node that connects to the KILT prototype testnet in AWS +## Running a local node that connects to KILT prototype testnet in AWS -There is a master boot node running in the KILT testnet: +There are master boot nodes running in the KILT testnet: -* bootnode-alice (bootnode-alice.kilt-prototype.tk) +* Alice (bootnode-alice.kilt-prototype.tk) +* Bob (bootnode-bob.kilt-prototype.tk) -To connect to the Alice node you can use the shell script `kilt-node-testnet.sh`: +To start a node and connect to Alice you can use the shell script `start-node.sh`: ``` -cd scripts/ -kilt-node-testnet.sh --key Charly --name "CHARLY" +./start-node.sh --account-name Charly --connect-to Alice ``` You can use any of the accounts declared in the chain spec to connect (Alice, Bob, Charly, Dave, Eve, Ferdie). +Run `./start-node.sh --help` for more information. ### Running a node inside a docker container Make sure to have the `awscli` installed. Otherwise Install it via `brew install awscli` (Mac). -You also need to have your docker daemon system running (on mac, just download the docker application). +You also need to have your docker daemon system running (on mac, just download and install the docker application). Login to Amazon ECR @@ -38,7 +39,7 @@ docker pull 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain Run the image and pass the command to start a node ``` -docker run 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain ./kilt-node-testnet.sh --key Charly --name "CHARLY" +docker run 348099934012.dkr.ecr.eu-central-1.amazonaws.com/kilt/prototype-chain ./start-node.sh --account-name Charly --connect-to Alice ``` The node should be connected to the KILT testnet. \ No newline at end of file diff --git a/kilt-master-bootnode-testnet.sh b/kilt-master-bootnode-testnet.sh deleted file mode 100755 index c54f5493f..000000000 --- a/kilt-master-bootnode-testnet.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -# -# This script starts a kilt master boot node with provided account, name and node-key -# -# Run: -# ./kilt-master-bootnode-testnet.sh --key Alice --name "ALICE" --node-key 0000000000000000000000000000000000000000000000000000000000000001 -# - -echo "Starting KILT master boot node..." -./target/debug/node --chain kilt-testnet --validator --port 30333 --ws-port 9944 --ws-external --rpc-external --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" - diff --git a/kilt-node-testnet.sh b/kilt-node-testnet.sh deleted file mode 100755 index 333b07467..000000000 --- a/kilt-node-testnet.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# -# This script starts a kilt node and connects to the master boot node of the KILT testnet. -# -# Run: -# ./kilt-node-testnet.sh --key Charly --name "CHARLY" -# - -ALICE_BOOT_NODE_DOMAIN=bootnode-alice.kilt-prototype.tk -ALICE_BOOT_NODE_IP=`dig $ALICE_BOOT_NODE_DOMAIN A +short` -ALICE_BOOT_NODE_KEY=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN -ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY - - -#BOB_BOOT_NODE_DOMAIN=bootnode-bob.kilt-prototype.tk -#BOB_BOOT_NODE_IP=`dig $BOB_BOOT_NODE_DOMAIN A +short` -#BOB_BOOT_NODE_KEY=QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK -#BOB_BOOT_NODE_IPFS=/ip4/$BOB_BOOT_NODE_IP/tcp/30333/p2p/$BOB_BOOT_NODE_KEY - -MASTER_BOOT_NODE_IPFS=`./lookup-master-bootnode-testnet.sh` - -# Connect to master boot node -echo "Master boot node: $MASTER_BOOT_NODE_IPFS..." -./target/debug/node --chain kilt-testnet --bootnodes $MASTER_BOOT_NODE_IPFS --port 30333 --ws-port 9944 --validator --ws-external --rpc-external --telemetry-url ws://telemetry-backend.kilt-prototype.tk:1024 "$@" - diff --git a/lookup-master-bootnode-testnet.sh b/lookup-master-bootnode-testnet.sh deleted file mode 100755 index ec49b0b84..000000000 --- a/lookup-master-bootnode-testnet.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# -# This script performs a lookup for the master boot node and prints out its ipfs address. -# -# Run: -# ./lookup-master-bootnode-testnet.sh -# Prints out the IPFS of the master boot node: -# e.g.: -# /ip4/3.120.148.48/tcp/30333/p2p/QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN -# - -ALICE_BOOT_NODE_DOMAIN=bootnode-alice.kilt-prototype.tk -ALICE_BOOT_NODE_IP=`dig $ALICE_BOOT_NODE_DOMAIN A +short` -ALICE_BOOT_NODE_KEY=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN -ALICE_BOOT_NODE_IPFS=/ip4/$ALICE_BOOT_NODE_IP/tcp/30333/p2p/$ALICE_BOOT_NODE_KEY - -echo $ALICE_BOOT_NODE_IPFS \ No newline at end of file diff --git a/start-node.sh b/start-node.sh new file mode 100755 index 000000000..edd509ba2 --- /dev/null +++ b/start-node.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +# start-node.sh - A script to start a node within the KILT test network + +##### Constants + +CHAIN_NAME="kilt-testnet" +ALICE_BOOT_NODE_KEY=0000000000000000000000000000000000000000000000000000000000000001 +ALICE_BOOT_NODE_KEY_HASH=QmQZ8TjTqeDj3ciwr93EJ95hxfDsb9pEYDizUAbWpigtQN +BOB_BOOT_NODE_KEY=0000000000000000000000000000000000000000000000000000000000000002 +BOB_BOOT_NODE_KEY_HASH=QmXiB3jqqn2rpiKU7k1h7NJYeBg8WNSx9DiTRKz9ti2KSK +TELEMETRY_URL=ws://telemetry-backend.kilt-prototype.tk:1024 + +##### Functions + +lookup_boot_node() { + boot_node_domain="bootnode-${bootnode}.kilt-prototype.tk" + echo "Performing lookup for boot node ${boot_node_domain}" + if [[ "$bootnode" = "Alice" ]]; then + alice_boot_node_ip=`dig ${boot_node_domain} A +short` + boot_node_ipfs=/ip4/${alice_boot_node_ip}/tcp/30333/p2p/${ALICE_BOOT_NODE_KEY_HASH} + elif [[ "$bootnode" = "Bob" ]]; then + bob_boot_node_ip=`dig ${boot_node_domain} A +short` + boot_node_ipfs=/ip4/${bob_boot_node_ip}/tcp/30333/p2p/${BOB_BOOT_NODE_KEY_HASH} + fi +} + + + +usage() +{ +cat < [...] + + If you want to start a boot node, just use "Alice" or "Bob" as account name. + + -a, --account-name ACCOUNT_NAME The name of the account to start the node with (Alice | Bob | Charly | Dave | Eve | Ferdie). + -n, --node-name NODE_NAME The arbitrary name of the node (e.g. "charly-node-1234") + -c, --connect-to BOOT_NODE_NAME The name of the boot node to connect to ("alice" | "bob") + -d, --dry-run Flag indicating to only show the resulting command instead of executing it + -t, --telemetry Flag indicating whether or not to send data to the telemetry server + + Examples: + + Start Alice (boot node): + ./start-node.sh -a Alice + + Start Bob (boot node) that connects to Alice: + ./start-node.sh -a Bob -c Alice + + Start Charly (normal node) that connects to Alice: + ./start-node.sh -a Charly -c Alice -n charly-node-123 +HELP_USAGE +} + +##### Main + + +bootnode= +node_name= +account_name= +telemetry=0 +dry_run=0 + +while [[ "$1" != "" ]]; do + case $1 in + -a | --account-name ) shift + account_name=$1 + ;; + -n | --node-name ) shift + node_name=$1 + ;; + -c | --connect-to ) shift + bootnode=$1 + ;; + -t | --telemetry ) telemetry=1 + ;; + -d | --dry-run ) dry_run=1 + ;; + -h | --help ) usage + exit + ;; + * ) usage + exit 1 + esac + shift +done + + +arg_boot_node_connect= +arg_node_key= +arg_node_name= +arg_telemetry= +arg_account_name= + +if [[ -z "$account_name" ]]; then + usage + exit 1 +fi + +if [[ "$account_name" = "Alice" ]]; then + arg_node_key=" --node-key ${ALICE_BOOT_NODE_KEY}" +elif [[ "$account_name" = "Bob" ]]; then + arg_node_key=" --node-key ${BOB_BOOT_NODE_KEY}" +fi +arg_account_name=" --key ${account_name}" + +echo "Starting KILT node with account '${account_name}'" +if [[ ! -z "$bootnode" ]]; then + echo "Trying to connect to boot node '$bootnode'..." + lookup_boot_node + if [[ -z "$boot_node_ipfs" ]]; then + echo "Boot node address lookup failed for boot node named '$bootnode'" + exit 1 + else + echo "Boot-node IPFS location: $boot_node_ipfs" + arg_boot_node_connect=" --bootnodes ${boot_node_ipfs}" + fi +fi + +if [[ ! -z "$node_name" ]]; then + random_suffix=`cat /dev/urandom | env LC_CTYPE=C tr -cd 'a-f0-9' | head -c 5` + node_name="${node_name}-${random_suffix}" + arg_node_name=" --name ${node_name}" +fi + +if [[ "$telemetry" = "1" ]]; then + arg_telemetry=" --telemetry-url ${TELEMETRY_URL}" +fi + +command="./target/debug/node --chain ${CHAIN_NAME} --validator --port 30333 --ws-port 9944 --ws-external --rpc-external${arg_account_name}${arg_node_key}${arg_boot_node_connect}${arg_node_name}${arg_telemetry}" + +if [[ "$dry_run" = "1" ]]; then + echo "Dry run." + echo "Command: $command" + exit 0 +fi + +echo "Running: $command" +`${command}` \ No newline at end of file