Skip to content

Commit

Permalink
Merge pull request #210 from cheqd/docker-improvements
Browse files Browse the repository at this point in the history
Docker improvements
  • Loading branch information
Toktar authored Nov 12, 2021
2 parents 7006972 + ed44a88 commit 00f537e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 22 deletions.
30 changes: 22 additions & 8 deletions docker/cheqd_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can find prebuilt package here:

To pull it use:

```text
```bash
docker pull ghcr.io/cheqd/cheqd-node:latest
```

Expand All @@ -23,6 +23,8 @@ To build the image:
* Go to the repository root;
* Run `docker build -f docker/cheqd_node/Dockerfile -t cheqd-node .`.

Default home directory for `cheqd` user is `/cheqd`. It can be overridden via `CHEQD_HOME_DIR` build argument. Example: `--build-arg CHEQD_HOME_DIR=/home/cheqd`.

Note: If you are using M1 Macbook you should modify the FROM statement in the Dockerfile, should be like this "FROM --platform=linux/amd64 golang:buster as builder "

## Usage
Expand All @@ -33,25 +35,37 @@ Note: If you are using M1 Macbook you should modify the FROM statement in the Do

Usage:

```text
```bash
docker run -it --rm cheqd-node <command> <args>
```

### node-runner

Used to initialize configuration files and run a node in one command.

Parameters:
Parameters that can be passed via environment variables:

* `NODE_MONIKER` - node moniker;
* `GENESIS` - base64 encoded content of `genesis.json`;
* `NODE_KEY` - base64 encoded content of `node_key.json`;
* `PRIV_VALIDATOR_KEY` - base64 encoded content of `priv_validator_key.json`;
* `NODE_ARGS` \(optional\) - argument string passed to the `cheqd-noded start` command.

Additional parameters that will be applied via `cheqd-noded configure`:

* `CREATE_EMPTY_BLOCKS`
* `FASTSYNC_VERSION`
* `MIN_GAS_PRICES`
* `RPC_LADDR`
* `P2P_EXTERNAL_ADDRESS`
* `P2P_LADDR`
* `P2P_MAX_PACKET_MSG_PAYLOAD_SIZE`
* `P2P_PERSISTENT_PEERS`
* `P2P_RECV_RATE`
* `P2P_SEED_MODE`
* `P2P_SEEDS`
* `P2P_SEND_RATE`

Usage:

```text
docker run -it --rm --entrypoint node-runner -e NODE_MONIKER=<moniker> -e GENESIS="<content>" -e NODE_KEY="<content>" -e PRIV_VALIDATOR_KEY="<content>" cheqd-node
```bash
docker run -it -v data:/cheqd --rm --entrypoint node-runner -e NODE_MONIKER=<moniker> -e GENESIS="<content>" cheqd-node
```

11 changes: 6 additions & 5 deletions docker/cheqd_node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN starport chain build

##### Run container #####

FROM debian:buster
FROM ubuntu:focal

# Node binary
COPY --from=builder /go/bin/cheqd-noded /bin
Expand All @@ -42,14 +42,15 @@ COPY --from=builder /go/bin/cheqd-noded /bin
COPY docker/cheqd_node/node-runner.sh /bin/node-runner
RUN chmod +x /bin/node-runner

ARG CHEQD_HOME_DIR="/cheqd"

RUN groupadd --system --gid 1000 cheqd && \
useradd --system --create-home --home-dir /cheqd --shell /bin/bash --gid cheqd --uid 1000 cheqd
RUN chown -R cheqd /cheqd
useradd --system --create-home --home-dir ${CHEQD_HOME_DIR} --shell /bin/bash --gid cheqd --uid 1000 cheqd

WORKDIR /cheqd
WORKDIR ${CHEQD_HOME_DIR}
USER cheqd

EXPOSE 26656 26657
STOPSIGNAL SIGTERM

ENTRYPOINT [ "cheqd-noded" ]
ENTRYPOINT [ "node-runner" ]
36 changes: 27 additions & 9 deletions docker/cheqd_node/node-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@

set -euox pipefail

NODE_HOME="$HOME/.cheqdnode"

CHEQD_ROOT_DIR="$HOME/.cheqdnode"

# Init node config directory
if [ ! -d "${NODE_HOME}/config" ]
if [ ! -d "${CHEQD_ROOT_DIR}/config" ]
then
echo "Node home not found. Initializing."
cheqd-noded init $NODE_MONIKER
echo "Node config not found. Initializing."
cheqd-noded init $NODE_MONIKER --home
else
echo "Node home exists. Skipping initialization."
echo "Node config exists. Skipping initialization."
fi

# Run configure
# `! -z` is used instead of `-n` to distinguilsh null and empty values

if [[ ! -z ${CREATE_EMPTY_BLOCKS+x} ]]; then cheqd-noded configure create-empty-blocks ${CREATE_EMPTY_BLOCKS}; fi
if [[ ! -z ${FASTSYNC_VERSION+x} ]]; then cheqd-noded configure fastsync-version ${FASTSYNC_VERSION}; fi
if [[ ! -z ${MIN_GAS_PRICES+x} ]]; then cheqd-noded configure min-gas-prices ${MIN_GAS_PRICES}; fi
if [[ ! -z ${RPC_LADDR+x} ]]; then cheqd-noded configure rpc-laddr ${RPC_LADDR}; fi
if [[ ! -z ${P2P_EXTERNAL_ADDRESS+x} ]]; then cheqd-noded configure p2p external-address ${P2P_EXTERNAL_ADDRESS}; fi
if [[ ! -z ${P2P_LADDR+x} ]]; then cheqd-noded configure p2p laddr ${P2P_LADDR}; fi
if [[ ! -z ${P2P_MAX_PACKET_MSG_PAYLOAD_SIZE+x} ]]; then cheqd-noded configure p2p max-packet-msg-payload-size ${P2P_MAX_PACKET_MSG_PAYLOAD_SIZE}; fi
if [[ ! -z ${P2P_PERSISTENT_PEERS+x} ]]; then cheqd-noded configure p2p persistent-peers ${P2P_PERSISTENT_PEERS}; fi
if [[ ! -z ${P2P_RECV_RATE+x} ]]; then cheqd-noded configure p2p recv-rate ${P2P_RECV_RATE}; fi
if [[ ! -z ${P2P_SEED_MODE+x} ]]; then cheqd-noded configure p2p seed-mode ${P2P_SEED_MODE}; fi
if [[ ! -z ${P2P_SEEDS+x} ]]; then cheqd-noded configure p2p seeds ${P2P_SEEDS}; fi
if [[ ! -z ${P2P_SEND_RATE+x} ]]; then cheqd-noded configure p2p send-rate ${P2P_SEND_RATE}; fi


# Update configs
echo "$GENESIS" | base64 --decode > $NODE_HOME/config/genesis.json
echo "$NODE_KEY" | base64 --decode > $NODE_HOME/config/node_key.json
echo "$PRIV_VALIDATOR_KEY" | base64 --decode > $NODE_HOME/config/priv_validator_key.json
set - # Disable ditailed command logging

echo "Updating genesis"
echo "$GENESIS" | base64 --decode > $CHEQD_ROOT_DIR/config/genesis.json

set -x # Re-enable ditailed command logging

# Run node
NODE_ARGS=${NODE_ARGS:-} # Allo node args to be empty
Expand Down

0 comments on commit 00f537e

Please sign in to comment.