Skip to content

Commit

Permalink
Merge pull request #59 from anmolnetwork/aelesbao/fix/docker-compose
Browse files Browse the repository at this point in the history
Fix docker-compose setup and init scripts
  • Loading branch information
nblogist authored Oct 19, 2021
2 parents 22e1c70 + 7446c2f commit 5bd092c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 69 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ indent_style=tab
indent_size=tab
tab_width=4
max_line_length=100

[Makefile]
indent_style=tab
indent_size=tab
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
.PHONY: run run-ibtida format-code benchmarks-build benchmarks-generate test

run:
cargo run -- --dev --tmp

run-ibtida:
docker-compose -f docker-compose.ibtida.yml down
scripts/generate-keys.sh
scripts/generate-chain-spec.sh
scripts/import-keys.sh
docker-compose -f docker-compose.ibtida.yml up

format-code:
cargo fmt

Expand Down
8 changes: 4 additions & 4 deletions chains/ibtida.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
},
"palletAura": {
"authorities": [
"5CcnCFBV4RQdeq2XPMitFJk7ZsQtTakvsj4JKjBF5BzB7oPe",
"5Hipcx1M9WWPnvZLMSeS1qk3S2Bz4T19JT7AwtifgBcCH5U6"
"5EJGh5BVsTkmqX2N9qvZn7Jej1LLBKTyc6K5nMUTLTUfD2DG",
"5HguxT6Gu17jq7yaibAZTP7vtHVNvigbM1HvqPQa5j7YN9CV"
]
},
"palletGrandpa": {
"authorities": [
[
"5GgeHH27aRmzwKx72QU2cDVk9fQKgpSZiidL8NYyezeMvYia",
"5Hdr7fvjtmyo6jFjfP6i8UnaY6cvdKFdmdvsurbHbEhpBCwW",
1
],
[
"5EeRV5bd4dQ5JkZnLuxRPdujpRG7raD2SxNVFqrzQ7EJXALp",
"5CNF9gAbABtyxUKJ8HqTab8oDvjMmkgSz7h63z3AETSCuZX6",
1
]
]
Expand Down
40 changes: 20 additions & 20 deletions chains/raw/ibtida.json

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions docker-compose.ibtida.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ services:
command:
- --name=validator-1
- --chain=/ibtida.json
- --node-key-file=/node.key
- --node-key=0000000000000000000000000000000000000000000000000000000000000001
- --validator
- --rpc-cors=all
- --rpc-external
- --rpc-methods=Unsafe
- --unsafe-rpc-external
- --ws-external
- --unsafe-ws-external
- --no-prometheus
- --no-telemetry
Expand All @@ -28,7 +29,6 @@ services:
volumes:
- db-validator-1:/data
- ./chains/raw/ibtida.json:/ibtida.json:ro
- ./keys/node-1.key:/node.key:ro

deploy:
mode: global
Expand All @@ -40,26 +40,25 @@ services:
command:
- --name=validator-2
- --chain=/ibtida.json
- --node-key-file=/node.key
- --validator
- --rpc-cors=all
- --rpc-external
- --rpc-methods=Unsafe
- --unsafe-rpc-external
- --ws-external
- --unsafe-ws-external
- --no-prometheus
- --no-telemetry
- --bootnodes=/dns4/validator-1/tcp/30333/p2p/12D3KooWPPwHVGffWTNFw2MCk6m7z7drkRhyBU1nPGD1v1sqsgyB
- --bootnodes=/dns4/validator-1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp

ports:
- 9933
- 9944
- 9945:9944
- 30333

volumes:
- db-validator-2:/data
- ./chains/raw/ibtida.json:/ibtida.json:ro
- ./keys/node-2.key:/node.key:ro

depends_on:
- validator-1
Expand Down
46 changes: 29 additions & 17 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3.9"

services:
node-alice: &node
image: anmolnetwork/anmol-node:ibtida
image: anmolnetwork/anmol-node:latest
build:
context: .
args:
Expand All @@ -11,18 +11,21 @@ services:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY

command: |
--chain local
--unsafe-rpc-external
--unsafe-ws-external
--no-prometheus
--alice
--node-key 0000000000000000000000000000000000000000000000000000000000000001
command:
- --chain=local
- --rpc-cors=all
- --rpc-external
- --rpc-methods=Unsafe
- --unsafe-rpc-external
- --ws-external
- --unsafe-ws-external
- --no-prometheus
- --alice
- --node-key=0000000000000000000000000000000000000000000000000000000000000001

ports:
- 9615
- 9933
- 9944
- 9944:9944
- 30333

volumes:
Expand All @@ -35,13 +38,22 @@ services:

node-bob:
<<: *node
command: |
--chain local
--unsafe-rpc-external
--unsafe-ws-external
--no-prometheus
--bob
--bootnodes /dns4/node-alice/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp
command:
- --chain=local
- --rpc-cors=all
- --rpc-external
- --rpc-methods=Unsafe
- --unsafe-rpc-external
- --ws-external
- --unsafe-ws-external
- --no-prometheus
- --bob
- --bootnodes=/dns4/node-alice/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp

ports:
- 9933
- 9945:9944
- 30333

volumes:
- db-bob:/data
Expand Down
32 changes: 17 additions & 15 deletions scripts/generate-chain-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ else
chain_spec_path="/var/local/anmol/specs"
fi

if [[ "${1:-}" == "raw" ]]; then
echo "*** Generating raw chain spec ***"
$anmol build-spec \
--disable-default-bootnode \
--chain $chain_spec_path/ibtida.json \
--raw > chains/raw/ibtida.json
else
echo "*** Generating chain spec ***"
echo " - Replacing Aura and Grandpa keys in spec"
$anmol build-spec \
--disable-default-bootnode \
--chain ibtida | \
function replace-addresses() {
jq \
--argfile node1Aura keys/node-1-aura.json \
--argfile node2Aura keys/node-2-aura.json \
--argfile node1Gran keys/node-1-gran.json \
--argfile node2Gran keys/node-2-gran.json \
'.genesis.runtime.palletAura.authorities = [($node1Aura | .ss58Address), ($node2Aura | .ss58Address)] |
.genesis.runtime.palletGrandpa.authorities = [[($node1Gran | .ss58Address), 1], [($node2Gran | .ss58Address), 1]]' \
> chains/ibtida.json
fi
.genesis.runtime.palletGrandpa.authorities = [[($node1Gran | .ss58Address), 1], [($node2Gran | .ss58Address), 1]]' | \
sed 's/5e+27/5000000000000000000000000000/'
}

echo "*** Generating chain spec ***"
echo " - Replacing Aura and Grandpa keys in spec"
$anmol build-spec \
--disable-default-bootnode \
--chain ibtida | \
replace-addresses > chains/ibtida.json

echo " - Generating raw chain spec"
$anmol build-spec \
--disable-default-bootnode \
--chain $chain_spec_path/ibtida.json \
--raw > chains/raw/ibtida.json
7 changes: 0 additions & 7 deletions scripts/generate-keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ fi
function generate-keys() {
local node="$1"

if [[ -f keys/node-$node.key ]]; then
echo " - Found node key for node $node!"
else
echo " - Generating node key for node $node"
$anmol key generate-node-key --file $node_key_path/node-$node.key
fi

if [[ -f keys/node-$node-aura.json ]]; then
echo " - Found Aura key for node $node!"
else
Expand Down
4 changes: 4 additions & 0 deletions scripts/import-keys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ function import-node-keys() {
if [ "$method" == "file" ]; then
insert-key-file $node "aura"
insert-key-file $node "gran"
docker-compose -f docker-compose.ibtida.yml down
elif [ "$method" == "rpc" ]; then
local rpc_endpoint="http://$(docker-compose -f docker-compose.ibtida.yml port validator-$node 9933)"
insert-key-rpc $node "aura" "$rpc_endpoint"
insert-key-rpc $node "gran" "$rpc_endpoint"
else
echo "ERROR: Unknown method $method"
exit 1
fi
}

Expand Down

0 comments on commit 5bd092c

Please sign in to comment.