Skip to content

Commit 2a6715b

Browse files
authored
dx: Dockerfile rework (#90)
1 parent 02e1f4f commit 2a6715b

File tree

9 files changed

+250
-26
lines changed

9 files changed

+250
-26
lines changed

Dockerfile

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,62 @@ RUN --mount=type=cache,target=/root/.cache go build -o /app/build/sourcehubd ./c
1313
# Deployment entrypoint
1414
FROM debian:bookworm-slim
1515

16+
COPY docker/entrypoint.sh /usr/local/bin/entrypoint.sh
17+
COPY docker/config.toml /etc/sourcehub/config.toml
18+
COPY docker/app.toml /etc/sourcehub/app.toml
19+
COPY docker/faucet-key.json /etc/sourcehub/faucet-key.json
1620
COPY --from=builder /app/build/sourcehubd /usr/local/bin/sourcehubd
1721

1822
RUN useradd --create-home --home-dir /home/node node && mkdir /sourcehub && chown node:node /sourcehub && ln -s /sourcehub /home/node/.sourcehub && chown node:node -R /home/node
1923

24+
# MONIKER sets the node moniker
25+
ENV MONIKER="node"
26+
# CHAIN_ID sets the id for the chain which will be initialized
27+
ENV CHAIN_ID="sourcehub-dev"
28+
29+
# GENESIS_PATH is an optional variable which if set must point to a genesis file mounted in the container.
30+
# The file is copied to the configuration directory during the first container initialization
31+
# If empty, the entrypoint will generate a new genesis
32+
ENV GENESIS_PATH=""
33+
34+
# MNEMONIC_PATH is an optional varible which, if set, must point to a file containing a
35+
# cosmos key mnemonic. The mnemonic will be used to restore the node operator / validator key.
36+
# If empty, the entrypoint will generate a new key
37+
ENV MNEMONIC_PATH=""
38+
39+
# CONSENSUS_KEY_PATH is an optional variable which, if set, must point to a file containg
40+
# a comebft consesus key for the validator.
41+
# If empty, the entrypoint will generate a new key
42+
ENV CONSENSUS_KEY_PATH=""
43+
44+
# COMET_NODE_KEY_PATH is an optional variable which, if set, must point to a file containg
45+
# a comebft p2p node key.
46+
# If empty, the entrypoint will generate a new key
47+
ENV COMET_NODE_KEY_PATH=""
48+
49+
# COMET_CONFIG_PATH is an optional variable which, if set, will overwrite
50+
# the default cofig.toml with the provided file.
51+
ENV COMET_CONFIG_PATH=""
52+
53+
# APP_CONFIG_PATH is an optional variable which, if set, will overwrite
54+
# the default app.toml with the provided file.
55+
ENV APP_CONFIG_PATH=""
56+
57+
ENV STANDALONE=""
58+
59+
# Comet P2P Port
60+
EXPOSE 26656
61+
62+
# Comet RPC Port
63+
EXPOSE 26657
64+
65+
# SourceHub GRPC Port
66+
EXPOSE 9090
67+
68+
# SourceHub HTTP API Port
69+
EXPOSE 1317
70+
2071
USER node
2172
VOLUME ["/sourcehub"]
22-
ENTRYPOINT ["sourcehubd"]
23-
CMD ["start"]
73+
ENTRYPOINT ["entrypoint.sh"]
74+
CMD ["sourcehubd", "start"]

api/sourcehub/hub/chain_config.pulsar.go

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker-compose.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
version: '3.8'
2-
31
services:
42
sourcehub:
53
build:
6-
target: builder
7-
args:
8-
dev: 1
4+
context: .
95
ports:
10-
- 1317
6+
- 1317:1317
7+
- 26656:26656
8+
- 26657:26657
9+
- 9090:9090
10+
environment:
11+
STANDALONE: 1
1112
volumes:
12-
- .:/app
13+
- data:/sourcehub
14+
volumes:
15+
data:

docker/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# SourceHub Dockerfile
2+
3+
Dockerfile designed to make getting started with SourceHub easily.
4+
5+
Dockerfile can be used to join a pre-existing network or used for a standalone test envrionment.
6+
7+
To configure initialization set `MONIKER` for the node moniker and `CHAIN_ID` for the chain id.
8+
9+
Validator, comet p2p and comet validator keys can be recovered and loaded for previously created keys, otherwise new keys will be generated.
10+
11+
## Usage modes
12+
13+
### Validator Recovery mode
14+
Validator recovery mode configures the sourcehub node to recover a validator credentials
15+
16+
Set env var `MNEMONIC_PATH` to recover the sourcehub validator key.
17+
Set env var `CONSENSUS_KEY_PATH` to recover the CometBFT consensus key (ie. `priv_validator_key.json`).
18+
Set env var `COMET_NODE_KEY_PATH` to recover the CometBFT p2p key (ie. `node_key.json`)
19+
Set `GENESIS_PATH` to initialize the genesis file.
20+
21+
### RPC Mode
22+
RPC Mode joins an existing network as an RPC Node with a new set of keys.
23+
24+
Set `GENESIS_PATH` to specify the network genesis.
25+
Ensure `CHAIN_ID` matches the chain id in the genesis file.
26+
27+
### RPC with account recovery
28+
To spin up an RPC node with a previously generated account key, follow the steps in RPC Mode and additionally set `MNEMONIC_PATH`.
29+
30+
31+
## Standalone mode
32+
Standalone mode is ideal for local experimentation and test environments.
33+
During container startup, it generates a new network and genesis.
34+
35+
Set `STANDALONE=1` at time of container creation to force standalone mode, all recovery variables are ignored in standalone mode.
36+
37+
## Environment Variable Reference
38+
39+
40+
- `MONIKER` sets the node moniker
41+
- `CHAIN_ID` sets the id for the chain which will be initialized
42+
- `GENESIS_PATH` is an optional variable which if set must point to a genesis file mounted in the container.
43+
The file is copied to the configuration directory during the first container initialization
44+
If empty, the entrypoint will generate a new genesis
45+
46+
- `MNEMONIC_PATH` is an optional varible which, if set, must point to a file containing a
47+
cosmos key mnemonic. The mnemonic will be used to restore the node operator / validator key.
48+
If empty, the entrypoint will generate a new key
49+
50+
- `CONSENSUS_KEY_PATH` is an optional variable which, if set, must point to a file containg
51+
a comebft consesus key for the validator.
52+
If empty, the entrypoint will generate a new key
53+
54+
- `COMET_NODE_KEY_PATH` is an optional variable which, if set, must point to a file containg
55+
a comebft p2p node key.
56+
If empty, the entrypoint will generate a new key
57+
58+
- `COMET_CONFIG_PATH` is an optional variable which, if set, will overwrite
59+
the default cofig.toml with the provided file.
60+
61+
- `APP_CONFIG_PATH` is an optional variable which, if set, will overwrite
62+
the default app.toml with the provided file.
63+
64+
- `STANDALONE` if set to `1` will initialize a new SourceHub network / genesis for local usage.
65+
The network will with no fees, a single validator and a funded faucet account.

docker/entrypoint.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
DEFAULT_CHAIN_ID="sourcehub"
6+
DEFAULT_MONIKER="node"
7+
DEV_FACUET_MNEMONIC="comic very pond victory suit tube ginger antique life then core warm loyal deliver iron fashion erupt husband weekend monster sunny artist empty uphold"
8+
9+
if [ ! -d /sourcehub/.initialized ]; then
10+
echo "Initializing SourceHub"
11+
12+
if [ -z "$CHAIN_ID" ]; then
13+
echo "CHAIN_ID not set: using default"
14+
CHAIN_ID=$DEFAULT_CHAIN_ID
15+
fi
16+
17+
if [ -z "$MONIKER" ]; then
18+
echo "MONIKER not set: using default"
19+
MONIKER=$DEFAULT_MONIKER
20+
fi
21+
22+
sourcehubd init "$MONIKER" --chain-id $CHAIN_ID --default-denom="uopen" 2>/dev/null
23+
24+
# recover account mnemonic
25+
if [ -n "$MNEMONIC_PATH" ]; then
26+
echo "MNEMONIC_PATH set: recovering key"
27+
sourcehubd keys add validator --recover --source $MNEMONIC_PATH --keyring-backend test
28+
fi
29+
30+
# if consensus key is set, we recover the full
31+
# node, including p2p and consensus key
32+
if [ -n "$CONSENSUS_KEY_PATH" ]; then
33+
echo "CONSENSUS_KEY_PATH set: recovering validator"
34+
test -s $CONSENSUS_KEY_PATH || (echo "error: consensus key file is empty" && exit 1)
35+
test -s $COMET_NODE_KEY_PATH || (echo "error: comet node key file is empty" && exit 1)
36+
37+
cp $CONSENSUS_KEY_PATH /sourcehub/config/priv_validator_key.json
38+
cp $COMET_NODE_KEY_PATH /sourcehub/config/node_key.json
39+
fi
40+
41+
# initialize chain in standalone
42+
if [ "$STANDALONE" = "1" ]; then
43+
echo "Standalone mode: generating new genesis"
44+
# initialize chain / create genesis
45+
sourcehubd keys add validator --keyring-backend test
46+
echo $DEV_FACUET_MNEMONIC | sourcehubd keys add faucet --keyring-backend test --recover
47+
VALIDATOR_ADDR=$(sourcehubd keys show validator -a --keyring-backend test)
48+
FAUCET_ADDR=$(sourcehubd keys show faucet -a --keyring-backend test)
49+
sourcehubd genesis add-genesis-account $VALIDATOR_ADDR 1000000000000000uopen # 1b open
50+
sourcehubd genesis add-genesis-account $FAUCET_ADDR 100000000000000uopen # 100m open
51+
sourcehubd genesis gentx validator 1000000000000000uopen --chain-id $CHAIN_ID --keyring-backend test # 1b open
52+
sourcehubd genesis collect-gentxs
53+
sed -i 's/"allow_zero_fee_txs": false,/"allow_zero_fee_txs": true,/' /sourcehub/config/genesis.json
54+
cp /etc/sourcehub/faucet-key.json /sourcehub/config/faucet-key.json
55+
echo "initialized sourcehub genesis"
56+
else
57+
if [ -z "$GENESIS_PATH" ]; then
58+
echo "GENESIS_PATH not set and standalone is false: provide a genesis file or set env STANDALONE=1"
59+
exit 1
60+
fi
61+
cp $GENESIS_PATH /sourcehub/config/genesis.json
62+
echo "Loaded Genesis from $GENESIS_PATH"
63+
fi
64+
65+
touch /sourcehub/.initialized
66+
else
67+
echo "Skipping initialization: container previously initialized"
68+
fi
69+
70+
if [ -n "$COMET_CONFIG_PATH" ]; then
71+
echo "COMET_CONFIG_PATH set: updating comet config with $COMET_CONFIG_PATH"
72+
cp $COMET_CONFIG_PATH /sourcehub/config/config.toml
73+
fi
74+
75+
if [ -n "$APP_CONFIG_PATH" ]; then
76+
echo "APP_CONFIG_PATH set: updating app config with $APP_CONFIG_PATH"
77+
cp $APP_CONFIG_PATH /sourcehub/config/app.toml
78+
fi
79+
80+
exec $@

docker/faucet-key.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"mnemonic": "comic very pond victory suit tube ginger antique life then core warm loyal deliver iron fashion erupt husband weekend monster sunny artist empty uphold",
3+
"name": "faucet",
4+
"address": "source12d9hjf0639k995venpv675sju9ltsvf8u5c9jt"
5+
}

readme.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
Source's Trust Layer
44

5+
## Getting Started
6+
7+
To quickly spin up a standalone SourceHub network, we recommend using Docker.
8+
This repository contains a Dockerfile which if run with the environment variable `STANDALONE=1`, spins up a new single node SourceHub network.
9+
10+
To get started build the docker image with,
11+
12+
```
13+
docker image build -t sourcehub:latest .
14+
```
15+
16+
and start it with:
17+
18+
```
19+
docker run -p 9090:9090 -p 26657:26657 -p 26656:26656 -p 1317:1317 -e STANDALONE=1 sourcehub:latest
20+
```
21+
22+
The container will start a new network with no fees and a funded faucet account which can be used.
23+
The funded account is static for all new instances of the standalone deployment and can be imported by a keyring outside docker or a wallet (eg keplr) to broadcast transactions.
24+
25+
The account mnemonic is:
26+
27+
```
28+
comic very pond victory suit tube ginger antique life then core warm loyal deliver iron fashion erupt husband weekend monster sunny artist empty uphold
29+
```
30+
31+
For a complete list of params regarding the Dockerfile, see [docker readme](./docker/README.md)
32+
533
## Development
634

735
### Prerequisites

scripts/dev-entrypoint.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

x/hub/types/chain_config.pb.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)