Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: docker support for mainnet validator #197

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# syntax=docker/dockerfile:1

# This comes rust-lang/docker-rust-nightly with some changes to support our toolchain, etc
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine/Dockerfile
RUN set -eux; apk add --no-cache ca-certificates build-base cmake;

# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers
ARG source=./
ARG GO_VERSION="1.18"
ARG ALPINE_VERSION="3.17"
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ TESTNET_CHAINID := $(if $(TESTNET_CHAINID),$(TESTNET_CHAINID),localterra)
#OPERATOR ARGS
NODE_VERSION := $(if $(NODE_VERSION),$(NODE_VERSION),alpine3.17)

#OPERATOR ARGS
NODE_VERSION := $(if $(NODE_VERSION),$(NODE_VERSION),alpine3.17)

ifneq ($(OS),Windows_NT)
UNAME_S = $(shell uname -s)
endif
Expand Down
57 changes: 57 additions & 0 deletions contrib/terra-operator/core/Dockerfile.arch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.18-alpine3.17 AS go-builder
ARG version=v1.1.0

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
RUN set -eux; apk add --no-cache ca-certificates build-base git cmake;

# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers

WORKDIR /code
RUN git clone -b $version https://github.com/classic-terra/core.git ./

# Install mimalloc
RUN git clone -b v2.0.0 --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4

# Cosmwasm - download correct libwasmvm version and verify checksum
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt \
&& sha256sum /lib/libwasmvm_muslc.a | grep $(cat /tmp/checksums.txt | grep $(uname -m) | cut -d ' ' -f 1)

# force it to use static lib (from above) not standard libgo_cosmwasm.so file
RUN LEDGER_ENABLED=false BUILD_TAGS=muslc LDFLAGS="-linkmode=external -extldflags \"-L/code/mimalloc/build -lmimalloc -Wl,-z,muldefs -static\"" make build

FROM archlinux:base

RUN pacman -Syu ; \
pacman -S --noconfirm wget lz4 aria2 curl jq net-tools; \
pacman -Scc ;

RUN mkdir /terra ; \
groupadd terra ; \
useradd -g terra --home-dir=/terra terra ; \
chown -R terra:terra /terra

USER terra

WORKDIR /terra

COPY --from=go-builder /code/build/terrad /usr/local/bin/terrad

# rest server
EXPOSE 1317
# grpc
EXPOSE 9090
# tendermint p2p
EXPOSE 26656
# tendermint rpc
EXPOSE 26657

CMD ["/usr/local/bin/terrad", "version"]
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# docker build . -t cosmwasm/wasmd:latest
# docker run --rm -it cosmwasm/wasmd:latest /bin/sh
FROM golang:1.18-alpine3.17 AS go-builder
ARG source=.
ARG version=v1.1.0

# this comes from standard alpine nightly file
# https://github.com/rust-lang/docker-rust-nightly/blob/master/alpine3.12/Dockerfile
# with some changes to support our toolchain, etc
RUN set -eux; apk add --no-cache ca-certificates build-base git;
RUN set -eux; apk add --no-cache ca-certificates build-base git cmake;

RUN apk add git cmake
# NOTE: add these to run with LEDGER_ENABLED=true
# RUN apk add libusb-dev linux-headers

RUN git clone https://github.com/classic-terra/core.git && mv core /code
WORKDIR /code
RUN git clone -b $version https://github.com/classic-terra/core.git ./

# Install mimalloc
RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
RUN git clone -b v2.0.0 --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install
ENV MIMALLOC_RESERVE_HUGE_OS_PAGES=4

# Cosmwasm - download correct libwasmvm version and verify checksum
Expand All @@ -33,7 +32,7 @@ FROM ubuntu:22.04

RUN DEBIAN_FRONTEND=noninteractive ; \
apt-get update ; \
apt-get install -y wget lz4 aria2 curl jq ip nmap; \
apt-get install -y wget lz4 aria2 curl jq ip net-tools; \
apt-get clean ; \
mkdir /terra ; \
groupadd -r terra ; \
Expand Down
37 changes: 31 additions & 6 deletions contrib/terra-operator/docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
version: '3.8'

services:
core:
image: public.ecr.aws/classic-terra/core:alpine3.17
build:
core:
image: public.ecr.aws/classic-terra/core:alpine3.17
build:
context: ../..
dockerfile: Dockerfile
platforms:
- "linux/amd64"
labels:
- "description=Contains the terrad binary"
node:
image: public.ecr.aws/classic-terra/node:alpine3.17
build:

ubuntu-core:
image: public.ecr.aws/classic-terra/core:v1.1.0-ubuntu22.04
build:
context: .
dockerfile: core/Dockerfile.ubuntu
args:
version: v1.1.0
platforms:
- "linux/amd64"
labels:
- "description=Contains the terrad binary in ubuntu"

arch-core:
image: public.ecr.aws/classic-terra/core:v1.1.0-arch-base
build:
context: .
dockerfile: core/Dockerfile.arch
args:
version: v1.1.0
platforms:
- "linux/amd64"
labels:
- "description=Contains the terrad binary in archlinux base"

node:
image: public.ecr.aws/classic-terra/node:alpine3.17
build:
context: .
dockerfile: Dockerfile
args:
Expand Down
1 change: 1 addition & 0 deletions contrib/terra-operator/mainnet-validator/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data/*.tar.lz4
24 changes: 24 additions & 0 deletions contrib/terra-operator/mainnet-validator/Dockerfile.validator
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ARG base_image=public.ecr.aws/classic-terra/core
ARG version=v1.1.0-arch-base

FROM ${base_image}:${version}

ENV TERRAD_P2P_LADDR=tcp://0.0.0.0:26656
ENV TERRAD_RPC_LADDR=tcp://0.0.0.0:26657
ENV TERRAD_GRPC_ENABLE=false
ENV TERRAD_GRPC_WEB_ENABLE=false
ENV TERRAD_P2P_MAX_NUM_INBOUND_PEERS=200
ENV TERRAD_P2P_MAX_NUM_OUTBOUND_PEERS=50
ENV TERRAD_TX_INDEX_INDEXER=null

inon-man marked this conversation as resolved.
Show resolved Hide resolved
RUN mkdir /terra/data && mkdir /terra/.terra

# Download genesis for columbus-5, put it in here for caching
RUN wget https://columbus-genesis.s3.ap-northeast-1.amazonaws.com/columbus-5-genesis.json

# Addrbook json, put it in here for caching
RUN wget https://www.dropbox.com/s/bina9qfqkbsko6f/addrbook.json

COPY --chown=terra:terra ./entrypoint.sh /entrypoint.sh

CMD ["/entrypoint.sh"]
52 changes: 52 additions & 0 deletions contrib/terra-operator/mainnet-validator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Mainnet validator image

This image bases on the following assumption:
* validator already has a config folder on their machine (so that Dockerfile will not init another config folder)

Based on that asumption, the image will do the following:
* setup validator production env
* contain mainnet genesis.json
* contain addrbook.json

The container will do the following:
* Download newest snapshot from quicksync.io to /terra/data volume if not already have
* Copy addrbook.json to /terra/.terra volume
* Copy genesis.json to /terra/.terra volume
* Remove old data and copy snapshot data to /terra/.terra

## What you can do as an user?
1. To force download snapshot again, delete snapshot file in [data folder](data/README.md)
2. To configure tendermint and cosmos, define ENV in docker-compose.yaml. This is a feature provided by https://github.com/spf13/viper

```
TERRAD_P2P_LADDR=tcp://0.0.0.0:26656
```

the ENV above will configure --p2p.laddr

If you want to enable API in app.toml, add this to docker-compose.yml

```
environment:
- TERRAD_API_ENABLE=true
```

some common env:
* TERRAD_RPC_LADDR: change address of rpc
* will supply more if people ask

3. To continue running node after setting up something, change this line in docker-compose.yml

```
environment:
- CONTINUE=true
```

Setting CONTINUE=false will start node again

## No brainer guide

```bash
terrad init moniker --chain-id columbus-5
cd contrib/terra-operator/mainnet-validator && docker compose up -d
```
1 change: 1 addition & 0 deletions contrib/terra-operator/mainnet-validator/data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This folder will contain mainnet snapshot from quicksync.io
15 changes: 15 additions & 0 deletions contrib/terra-operator/mainnet-validator/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
mainnet:
image: public.ecr.aws/classic-terra/mainnet:v1.1.0-arch-base
container_name: columbus-5
restart: always
environment:
- CONTINUE=false
ports:
- 26657:26657
- 26656:26656
volumes:
- ./data:/terra/data
- ~/.terra:/terra/.terra
30 changes: 30 additions & 0 deletions contrib/terra-operator/mainnet-validator/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

CONTINUE=${CONTINUE:-false}

if [ "$CONTINUE" = "true" ]; then
echo "Continuing from previous run"
terrad start --home ~/.terra
exit 0
fi

# Copy genesis.json and addrbook.json to config
cp /terra/columbus-5-genesis.json /terra/.terra/config/genesis.json
cp /terra/addrbook.json /terra/.terra/config/addrbook.json

# Download snapshot from quicksync.io
URL=$(curl -L https://quicksync.io/terra.json|jq -r '.[] |select(.file=="columbus-5-pruned")|select (.mirror=="Netherlands")|.url')

# TODO: need a better way to check for columbus-5-pruned* else it will always download newest snapshot
if [ ! -f /terra/data/columbus-5-pruned* ]; then
echo "Downloading snapshot from $URL"
aria2c -x5 $URL -d /terra/data
echo "Download complete"
fi
DATA_FILE=$(find /terra/data -type f -name 'columbus-5-pruned*' | grep '\.tar\.lz4$')
rm -rf /terra/.terra/data
echo "Extracting snapshot from $DATA_FILE"
lz4 -dc $DATA_FILE | tar -xf - -C /terra/.terra
echo "Extraction complete"

terrad start --home ~/.terra
9 changes: 5 additions & 4 deletions scripts/run-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ pkill terrad
# check DENOM is set. If not, set to uluna
DENOM=${2:-uluna}

export TERRAD_P2P_LADDR=tcp://0.0.0.0:2000
export TERRAD_RPC_LADDR=tcp://0.0.0.0:1000
export TERRAD_API_ENABLE=true
export TERRAD_API_SWAGGER=true
inon-man marked this conversation as resolved.
Show resolved Hide resolved

COMMISSION_RATE=0.01
COMMISSION_MAX_RATE=0.02

Expand Down Expand Up @@ -66,10 +71,6 @@ update_test_genesis '.app_state["gov"]["deposit_params"]["min_deposit"]=[{"denom
update_test_genesis '.app_state["crisis"]["constant_fee"]={"denom":"'$DENOM'","amount":"1000"}'
update_test_genesis '.app_state["staking"]["params"]["bond_denom"]="'$DENOM'"'

# enable rest server and swagger
$SED_BINARY -i '0,/enable = false/s//enable = true/' $HOME_DIR/config/app.toml
$SED_BINARY -i 's/swagger = false/swagger = true/' $HOME_DIR/config/app.toml

# Sign genesis transaction
$BINARY gentx $KEY "1000000${DENOM}" --commission-rate=$COMMISSION_RATE --commission-max-rate=$COMMISSION_MAX_RATE --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME_DIR

Expand Down