Skip to content

Commit

Permalink
Docker + Chain Specs (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
deblanco authored Sep 11, 2023
1 parent 2cc7bbd commit 20bd6e1
Show file tree
Hide file tree
Showing 7 changed files with 8,347 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: ./docker/alphanet/Dockerfile
file: ./docker/client/Dockerfile
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ rls*.log
*.bin
*.iml
.secrets
.env
.env
data
8,307 changes: 8,307 additions & 0 deletions chain-specs/alphanet.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Optionally, You can build and run the stability node within Docker directly. it
To build the Docker container, run the following command in the root of the project

```
$ docker build -f ./docker/alphanet/Dockerfile -t stability .
$ docker build -f ./docker/client/Dockerfile -t stability .
```

### Run Alphanet
Expand All @@ -32,14 +32,17 @@ docker run -d -p 30333:30333 -p 9933:9933 -p 9944:9944 -p 9615:9615 stability
Optional environment variables:

- SEED: This environment variable allows the node to authenticate with a specific account.
- BOOTNODE: This environment variable allows specifying the bootnode to which the node will connect.
- CHAIN and CHAIN_NAME: If you want to use a pre-defined chain spec, you can use the CHAIN_NAME environment variable to specify the name of the chain spec to use. If you want to use a custom chain spec, you can use the CHAIN environment variable to specify the path to the chain spec file to use. If both are specified, CHAIN will be used. By default, the node will use the `dev` chain spec.
- NODE_KEY: This environment variable allows specifying the node key to use. If not specified, the node will generate a random node key. This applies to the P2P key, not the account key.
- BOOTNODES: This environment variable allows specifying the bootnodes to use, separated by commas. If not specified, the node will use the default bootnodes for the chain spec.
- DEFAULT_BOOTNODE: This environment variable allows specifying the default bootnode to use. If not specified, the node will use the default bootnode of Stability network.

To set an environment variable in the docker run, use the flag -e NAME=VALUE

### Example

```
docker run -d -p 30333:30333 -p 9933:9933 -p 9944:9944 -p 9615:9615 -e SEED=account -e BOOTNODE=/ip4/... stability
docker run -d -p 30333:30333 -p 9933:9933 -p 9944:9944 -p 9615:9615 -e SEED=account -e BOOTNODES=/ip4/... stability
```

## Test
Expand Down
4 changes: 1 addition & 3 deletions docker/alphanet/Dockerfile → docker/client/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ COPY stability-rpc ./stability-rpc
COPY test-utils ./test-utils
COPY Cargo.lock Cargo.toml rust-toolchain.toml ./



# Download rust dependencies and build the rust binary
RUN cargo build "--$PROFILE"

Expand All @@ -35,7 +33,7 @@ EXPOSE 30333 9933 9944 9615

# Copy entrypoint

COPY ./docker/alphanet/entrypoint.sh /usr/local/bin/
COPY ./docker/client/entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
24 changes: 18 additions & 6 deletions docker/alphanet/entrypoint.sh → docker/client/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
#!/bin/bash

CHAIN_TARGET=${CHAIN:-"dev"}
if [ ! -z "$CHAIN_NAME" ]; then
CHAIN_TARGET="$CHAIN_NAME"
fi

if [[ "$CHAIN_TARGET" == "dev" ]]; then
echo "Starting dev chain"
./target/release/stability --base-path /tmp/node --dev --unsafe-rpc-external --rpc-cors all --unsafe-ws-external --pruning archive --prometheus-external
exit 0
fi

if [ -n "$SEED" ]; then
./target/release/stability key insert --base-path /tmp/node \
--keystore-path /tmp/node/chains/alphanet/keystore \
./target/release/stability key insert \
--base-path /tmp/node \
--chain $CHAIN_TARGET \
--scheme ecdsa \
--suri "$SEED" \
--key-type aura

./target/release/stability key insert \
--keystore-path /tmp/node/chains/alphanet/keystore \
--base-path /tmp/node \
--chain $CHAIN_TARGET \
--scheme Ed25519 \
--suri "$SEED" \
--key-type gran

./target/release/stability key insert \
--keystore-path /tmp/node/chains/alphanet/keystore \
--base-path /tmp/node \
--chain $CHAIN_TARGET \
--scheme ecdsa \
--suri "$SEED" \
--key-type imon

fi

START_COMMAND="./target/release/stability --base-path /tmp/node --validator --unsafe-rpc-external --rpc-cors all --unsafe-ws-external --chain alphanet --pruning archive --prometheus-external"
START_COMMAND="./target/release/stability --base-path /tmp/node --validator --unsafe-rpc-external --rpc-cors all --unsafe-ws-external --pruning archive --prometheus-external --chain=$CHAIN_TARGET"

if [ -n "$NODE_KEY" ]; then
START_COMMAND="$START_COMMAND --node-key $NODE_KEY"
Expand All @@ -35,5 +46,6 @@ elif [ -n "$BOOTNODES" ]; then
START_COMMAND="$START_COMMAND --bootnodes $BOOTNODES"
fi

echo "Starting $CHAIN_TARGET chain"
eval $START_COMMAND

12 changes: 12 additions & 0 deletions docs/GETTING-STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,15 @@ Additionally, you can configure the following flags:
- `--unsafe-rpc-external --rpc-cors all --unsafe-ws-external`: Use if your node will be accessed from a system external to your localhost.
- `--bootnodes`: A list of p2p nodes for Stability to join the network. What is known as bootnodes
- `--base-path`: Specifies a custom base path for the data folder

## Generating the a build spec file or Genesis file

This file contains the initial genesis state that all nodes in the network agree on. The genesis state must be established when the blockchain is first started and it cannot be changed thereafter without starting an entirely new blockchain.

To generate the genesis file, execute the following command:

```sh
./target/release/stability build-spec --chain alphanet --disable-default-bootnode --raw > specs/alphanet.json
```

More info: https://docs.substrate.io/build/chain-spec/

0 comments on commit 20bd6e1

Please sign in to comment.