Skip to content

Commit

Permalink
fix: add build setup for validator script
Browse files Browse the repository at this point in the history
  • Loading branch information
JeancarloBarrios committed Oct 16, 2023
1 parent 3ad4c05 commit 520a447
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@ checksum:
algorithm: sha256

changelog:
skip: false
skip: false


dockers:
- image_templates:
- ghcr.io/sedaprotocol/seda-chain:{{.Version}}
- dockerfile: "gorelease.Dockerfile"
- skip_push: false
9 changes: 7 additions & 2 deletions Dockerfile → Dockerfile.old
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM --platform=$BUILDPLATFORM golang:1.21 AS build-env
#FROM golang:1.21 AS build-env
# Install minimum necessary dependencies
RUN apt-get update && apt-get install -y gcc-aarch64-linux-gnu
RUN echo 'deb [trusted=yes] https://repo.goreleaser.com/apt/ /' | sudo tee /etc/apt/sources.list.d/goreleaser.list

RUN apt-get update && apt-get install -y gcc-aarch64-linux-gnu goreleaser



Expand All @@ -19,7 +21,10 @@ COPY . .
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide
ARG TARGETOS TARGETARCH

RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build
#RUN GOOS=$TARGETOS GOARCH=$TARGETARCH make build
RUN goreleaser build --snapshot --clean --skip-validate
RUN pwd
# Use alpine:3 as a base image
FROM alpine:3

RUN apk add --no-cache curl make bash jq sed
Expand Down
Empty file added Dockerfile.old2
Empty file.
150 changes: 143 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,159 @@ all: tools build lint test
###############################################################################
### Build ###
###############################################################################
BUILD_TARGETS := build install
#BUILD_TARGETS := build install
#
#build: BUILD_ARGS=-o $(BUILDDIR)/
#
#build-linux-amd64:
# GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build
#
#build-linux-arm64:
# GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build
#
#$(BUILD_TARGETS): go.sum $(BUILDDIR)/
# go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...
#
#$(BUILDDIR)/:
# mkdir -p $(BUILDDIR)/
#
#.PHONY: build build-linux-amd64 build-linux-arm64
###############################################################################
## Build ##
###############################################################################

build: BUILD_ARGS=-o $(BUILDDIR)/
build_tags = netgo

# experimental feature
ifeq ($(EXPERIMENTAL),true)
build_tags += experimental
endif

ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif

ifeq (secp,$(findstring secp,$(COSMOS_BUILD_OPTIONS)))
build_tags += libsecp256k1_sdk
endif

whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))

ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=umee \
-X github.com/cosmos/cosmos-sdk/version.AppName=umeed \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TMVERSION)

ifeq ($(ENABLE_ROCKSDB),true)
BUILD_TAGS += rocksdb
test_tags += rocksdb
endif

# DB backend selection
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
build_tags += gcc
endif
ifeq (badgerdb,$(findstring badgerdb,$(COSMOS_BUILD_OPTIONS)))
BUILD_TAGS += badgerdb
endif
# handle rocksdb
ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS)))
ifneq ($(ENABLE_ROCKSDB),true)
$(error Cannot use RocksDB backend unless ENABLE_ROCKSDB=true)
endif
CGO_ENABLED=1
endif

ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif

ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif

all: tools build lint test

build-linux-amd64:
GOOS=linux GOARCH=amd64 LEDGER_ENABLED=false $(MAKE) build
echo-build-tags:
echo ${BUILD_TAGS}

build-linux-arm64:
GOOS=linux GOARCH=arm64 LEDGER_ENABLED=false $(MAKE) build
BUILD_TARGETS := build install

build: BUILD_ARGS=-o $(BUILDDIR)/
build-linux:
@if [ "${ENABLE_ROCKSDB}" != "true" ]; then \
echo "RocksDB support is disabled; to build and test with RocksDB support, set ENABLE_ROCKSDB=true"; fi
GOOS=linux GOARCH=$(if $(findstring aarch64,$(shell uname -m)) || $(findstring arm64,$(shell uname -m)),arm64,amd64) LEDGER_ENABLED=false $(MAKE) build

$(BUILD_TARGETS): go.sum $(BUILDDIR)/
@if [ "${ENABLE_ROCKSDB}" != "true" ]; then \
echo "RocksDB support is disabled; to build and test with RocksDB support, set ENABLE_ROCKSDB=true"; fi
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./...

$(BUILDDIR)/:
mkdir -p $(BUILDDIR)/

.PHONY: build build-linux-amd64 build-linux-arm64
build-experimental: go.sum
@echo "--> Building Experimental version..."
EXPERIMENTAL=true $(MAKE) build

build-no_cgo:
@echo "--> Building static binary with no CGO nor GLIBC dynamic linking..."
ifneq ($(ENABLE_ROCKSDB),true)
$(error RocksDB requires CGO)
endif
CGO_ENABLED=0 CGO_LDFLAGS="-static" $(MAKE) build


go-mod-tidy:
@contrib/scripts/go-mod-tidy-all.sh

clean:
@echo "--> Cleaning..."
@rm -rf $(BUILD_DIR)/** $(DIST_DIR)/**

.PHONY: build build-linux build-experimental build-no_cgo clean go-mod-tidy


###############################################################################
### Tools & Dependencies ###
Expand Down
5 changes: 5 additions & 0 deletions goreleaser.Dockefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
ENTRYPOINT ["/sedad"]
COPY sedad /


58 changes: 58 additions & 0 deletions scripts/validator_setup/validator_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
set -e

# Basic Setup Configurations
BIN=$(git rev-parse --show-toplevel)/build/seda-chaind # chain binary executable on your machine
KEYRING="${KEYRING:-file}"
KEYPASSWD="${KEYPASSWD:-somepassword}"

$BIN config keyring-backend file # use file backend

KeyName="${KEY_NAME:-default_key}"

# Adds a key to the keyring with the given MNEMONIC and KEYPASSWD (if provided) and KeyName
# or generates a new key if MNEMONIC is not provided.
if [[ -z "${MNEMONIC}" ]]; then
# $BIN
echo $KeyName
(echo $KEYPASSWD; echo $KEYPASSWD) | $BIN keys add $KeyName
else
(echo $KEYPASSWD; echo $KEYPASSWD; echo $MNEMONIC) | $BIN keys add $KeyName
fi


$BIN init new $MONIKER

cp /Users/jc/Downloads/genesis.json /Users/jc/.seda-chain/config/genesis.json

# VALIDATOR ENVS
STAKE_AMOUNT="${STAKE_AMOUNT:-100000000000000000seda}"
MONIKER="${MONIKER:-node0}"
COMMISSION_RATE="${COMMISSION_RATE:-0.10}"
COMMISSION_MAX_RATE="${COMMISSION_MAX_RATE:-0.20}"
COMMISSION_MAX_CHANGE_RATE="${COMMISSION_MAX_CHANGE_RATE:-0.01}"
MINIMAL_SELF_DELETAGION="${MINIMAL_SELF_DELETAGION:-10000000000000000seda}"


# Query for a validator if it does not exist exist create it
VALIDATOR=$($BIN query staking validators --output json | jq -r '.validators[] | select(.description.moniker=="'"${MONIKER}"'")')

if [[ -z "${VALIDATOR}" ]]; then
$BIN tx staking create-validator \
--amount "${STAKE_AMOUNT}seda" \
--moniker "${MONIKER}" \
--pubkey $($BIN tendermint show-validator) \
--commission-rate "${COMMISSION_RATE}" \
--commission-max-rate "$COMMISSION_MAX_RATE" \
--commission-max-change-rate "${COMMISSION_MAX_CHANGE_RATE}" \
--min-self-delegation "${MINIMAL_SELF_DELETAGION}"\
--from "${KEY_NAME}" \
--keyring-backend "${KEYRING}"
else
echo "Validator already exists"
exit 1
fi



#$BIN start

0 comments on commit 520a447

Please sign in to comment.