From 1392edb64e3b773eca48aee1685a2afb93170af9 Mon Sep 17 00:00:00 2001 From: nghuyenthevinh2000 Date: Thu, 30 Mar 2023 09:33:31 +0700 Subject: [PATCH 1/4] setting up Dockerfile.ubuntu --- .../terra-operator/{Dockerfile.core => Dockerfile.ubuntu} | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename contrib/terra-operator/{Dockerfile.core => Dockerfile.ubuntu} (94%) diff --git a/contrib/terra-operator/Dockerfile.core b/contrib/terra-operator/Dockerfile.ubuntu similarity index 94% rename from contrib/terra-operator/Dockerfile.core rename to contrib/terra-operator/Dockerfile.ubuntu index f284a6819..5cca79d58 100644 --- a/contrib/terra-operator/Dockerfile.core +++ b/contrib/terra-operator/Dockerfile.ubuntu @@ -1,7 +1,7 @@ # 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 @@ -14,6 +14,7 @@ RUN apk add git cmake RUN git clone https://github.com/classic-terra/core.git && mv core /code WORKDIR /code +RUN git checkout $version # Install mimalloc RUN git clone --depth 1 https://github.com/microsoft/mimalloc; cd mimalloc; mkdir build; cd build; cmake ..; make -j$(nproc); make install @@ -33,7 +34,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 ; \ From bf9a7a88abb4dd497abe42ac51bb72d69c802dcc Mon Sep 17 00:00:00 2001 From: nghuyenthevinh2000 Date: Fri, 31 Mar 2023 00:55:09 +0700 Subject: [PATCH 2/4] code for building image v1.1.0-ubuntu22.05 --- Dockerfile | 5 ++-- Makefile | 5 +++- contrib/terra-operator/Dockerfile.ubuntu | 8 +++--- .../terra-operator/docker-compose.build.yml | 26 ++++++++++++++----- .../terra-operator/docker-compose.node.yml | 2 +- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index ac8ca8c4b..11f6f4b44 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,8 @@ ARG source=. # 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; +RUN set -eux; apk add --no-cache ca-certificates build-base cmake; -RUN apk add git cmake # NOTE: add these to run with LEDGER_ENABLED=true # RUN apk add libusb-dev linux-headers @@ -16,7 +15,7 @@ WORKDIR /code COPY ${source} /code/ # 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 diff --git a/Makefile b/Makefile index de4de2030..e622a400f 100755 --- a/Makefile +++ b/Makefile @@ -16,6 +16,9 @@ TESTNET_NVAL := $(if $(TESTNET_NVAL),$(TESTNET_NVAL),4) TESTNET_CHAINID := $(if $(TESTNET_CHAINID),$(TESTNET_CHAINID),localnet-1) TESTNET_VOTING_PERIOD := $(if $(TESTNET_VOTING_PERIOD),$(TESTNET_VOTING_PERIOD),86400s) +#OPERATOR ARGS +NODE_VERSION := $(if $(NODE_VERSION),$(NODE_VERSION),alpine3.17) + ifneq ($(OS),Windows_NT) UNAME_S = $(shell uname -s) endif @@ -293,7 +296,7 @@ build-operator-img-core: docker-compose -f contrib/terra-operator/docker-compose.build.yml build core --no-cache build-operator-img-node: - @if ! docker image inspect public.ecr.aws/p5q2r9h7/core:alpine3.17 &>/dev/null ; then make build-operator-img-core ; fi + @if ! docker image inspect public.ecr.aws/classic-terra/core:${NODE_VERSION} &>/dev/null ; then make build-operator-img-core ; fi docker-compose -f contrib/terra-operator/docker-compose.build.yml build node --no-cache .PHONY: build-operator-img-all build-operator-img-core build-operator-img-node \ No newline at end of file diff --git a/contrib/terra-operator/Dockerfile.ubuntu b/contrib/terra-operator/Dockerfile.ubuntu index 5cca79d58..3d55432c0 100644 --- a/contrib/terra-operator/Dockerfile.ubuntu +++ b/contrib/terra-operator/Dockerfile.ubuntu @@ -6,18 +6,16 @@ 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 checkout $version +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 diff --git a/contrib/terra-operator/docker-compose.build.yml b/contrib/terra-operator/docker-compose.build.yml index d2581df80..ef2afa201 100644 --- a/contrib/terra-operator/docker-compose.build.yml +++ b/contrib/terra-operator/docker-compose.build.yml @@ -1,22 +1,34 @@ version: '3.8' services: - core: - image: public.ecr.aws/p5q2r9h7/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/p5q2r9h7/node:alpine3.17 - build: + + ubuntu-core: + image: public.ecr.aws/classic-terra/core:v1.1.0-ubuntu22.04 + build: + context: . + dockerfile: Dockerfile.ubuntu + args: + version: v1.1.0 + platforms: + - "linux/amd64" + labels: + - "description=Contains the terrad binary in ubuntu" + node: + image: public.ecr.aws/classic-terra/node:alpine3.17 + build: context: . dockerfile: Dockerfile args: - base_image: public.ecr.aws/p5q2r9h7/core + base_image: public.ecr.aws/classic-terra/core version: alpine3.17 platforms: - "linux/amd64" diff --git a/contrib/terra-operator/docker-compose.node.yml b/contrib/terra-operator/docker-compose.node.yml index c8d44db7d..cc5d61729 100644 --- a/contrib/terra-operator/docker-compose.node.yml +++ b/contrib/terra-operator/docker-compose.node.yml @@ -3,7 +3,7 @@ version: '3.8' services: node: container_name: node - image: public.ecr.aws/p5q2r9h7/node:alpine3.17 + image: public.ecr.aws/classic-terra/node:alpine3.17 platform: linux/amd64 environment: - CHAINID=test From 005cff466dad3c4b4923f26ac7458cdbffdd3cf9 Mon Sep 17 00:00:00 2001 From: nghuyenthevinh2000 Date: Tue, 4 Apr 2023 11:11:41 +0700 Subject: [PATCH 3/4] add docker for mainnet run --- contrib/terra-operator/core/Dockerfile.arch | 57 +++++++++++++++++++ .../{ => core}/Dockerfile.ubuntu | 0 .../terra-operator/docker-compose.build.yml | 15 ++++- .../mainnet-validator/.gitignore | 1 + .../mainnet-validator/Dockerfile.validator | 24 ++++++++ .../mainnet-validator/README.md | 45 +++++++++++++++ .../mainnet-validator/data/README.md | 1 + .../mainnet-validator/docker-compose.yml | 15 +++++ .../mainnet-validator/entrypoint.sh | 30 ++++++++++ scripts/run-node.sh | 9 +-- 10 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 contrib/terra-operator/core/Dockerfile.arch rename contrib/terra-operator/{ => core}/Dockerfile.ubuntu (100%) create mode 100644 contrib/terra-operator/mainnet-validator/.gitignore create mode 100644 contrib/terra-operator/mainnet-validator/Dockerfile.validator create mode 100644 contrib/terra-operator/mainnet-validator/README.md create mode 100644 contrib/terra-operator/mainnet-validator/data/README.md create mode 100644 contrib/terra-operator/mainnet-validator/docker-compose.yml create mode 100755 contrib/terra-operator/mainnet-validator/entrypoint.sh diff --git a/contrib/terra-operator/core/Dockerfile.arch b/contrib/terra-operator/core/Dockerfile.arch new file mode 100644 index 000000000..7d295ff53 --- /dev/null +++ b/contrib/terra-operator/core/Dockerfile.arch @@ -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"] \ No newline at end of file diff --git a/contrib/terra-operator/Dockerfile.ubuntu b/contrib/terra-operator/core/Dockerfile.ubuntu similarity index 100% rename from contrib/terra-operator/Dockerfile.ubuntu rename to contrib/terra-operator/core/Dockerfile.ubuntu diff --git a/contrib/terra-operator/docker-compose.build.yml b/contrib/terra-operator/docker-compose.build.yml index ef2afa201..91c27d4df 100644 --- a/contrib/terra-operator/docker-compose.build.yml +++ b/contrib/terra-operator/docker-compose.build.yml @@ -15,13 +15,26 @@ services: image: public.ecr.aws/classic-terra/core:v1.1.0-ubuntu22.04 build: context: . - dockerfile: Dockerfile.ubuntu + 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: diff --git a/contrib/terra-operator/mainnet-validator/.gitignore b/contrib/terra-operator/mainnet-validator/.gitignore new file mode 100644 index 000000000..5092b2eaf --- /dev/null +++ b/contrib/terra-operator/mainnet-validator/.gitignore @@ -0,0 +1 @@ +data/*.tar.lz4 \ No newline at end of file diff --git a/contrib/terra-operator/mainnet-validator/Dockerfile.validator b/contrib/terra-operator/mainnet-validator/Dockerfile.validator new file mode 100644 index 000000000..edc9d8263 --- /dev/null +++ b/contrib/terra-operator/mainnet-validator/Dockerfile.validator @@ -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 + +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"] \ No newline at end of file diff --git a/contrib/terra-operator/mainnet-validator/README.md b/contrib/terra-operator/mainnet-validator/README.md new file mode 100644 index 000000000..fa982ff0d --- /dev/null +++ b/contrib/terra-operator/mainnet-validator/README.md @@ -0,0 +1,45 @@ +# 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 newline at end of file diff --git a/contrib/terra-operator/mainnet-validator/data/README.md b/contrib/terra-operator/mainnet-validator/data/README.md new file mode 100644 index 000000000..754d4f853 --- /dev/null +++ b/contrib/terra-operator/mainnet-validator/data/README.md @@ -0,0 +1 @@ +This folder will contain mainnet snapshot from quicksync.io \ No newline at end of file diff --git a/contrib/terra-operator/mainnet-validator/docker-compose.yml b/contrib/terra-operator/mainnet-validator/docker-compose.yml new file mode 100644 index 000000000..37ddef3e0 --- /dev/null +++ b/contrib/terra-operator/mainnet-validator/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/contrib/terra-operator/mainnet-validator/entrypoint.sh b/contrib/terra-operator/mainnet-validator/entrypoint.sh new file mode 100755 index 000000000..c10675f8b --- /dev/null +++ b/contrib/terra-operator/mainnet-validator/entrypoint.sh @@ -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 \ No newline at end of file diff --git a/scripts/run-node.sh b/scripts/run-node.sh index e9ad27dc0..c8e412b01 100755 --- a/scripts/run-node.sh +++ b/scripts/run-node.sh @@ -7,6 +7,11 @@ BINARY=$1 # 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 + SED_BINARY=sed # check if this is OS X if [[ "$OSTYPE" == "darwin"* ]]; then @@ -56,10 +61,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}" --keyring-backend $KEYRING --chain-id $CHAIN_ID --home $HOME_DIR From 591a598cac6ce7154556d8e7ea5384cee18a7190 Mon Sep 17 00:00:00 2001 From: nghuyenthevinh2000 Date: Tue, 4 Apr 2023 11:15:43 +0700 Subject: [PATCH 4/4] add guide to run --- contrib/terra-operator/mainnet-validator/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contrib/terra-operator/mainnet-validator/README.md b/contrib/terra-operator/mainnet-validator/README.md index fa982ff0d..8c08551a3 100644 --- a/contrib/terra-operator/mainnet-validator/README.md +++ b/contrib/terra-operator/mainnet-validator/README.md @@ -42,4 +42,11 @@ environment: - CONTINUE=true ``` -Setting CONTINUE=false will start node again \ No newline at end of file +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 +``` \ No newline at end of file