diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 3bbb043e5..22bdee847 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -50,24 +50,43 @@ jobs: with: go-version: 1.17 - # There is an issue with the latest starport, especially 0.18 version - - name: Download and install starport - run: wget -qO- https://github.com/tendermint/starport/releases/download/v0.18.6/starport_0.18.6_linux_amd64.tar.gz | tar xvz -C /tmp/ && sudo cp /tmp/starport /usr/bin + - name: Get go protoc compiler plugins + env: + GOLANG_PROTOBUF_VERSION: 1.3.5 + GOGO_PROTOBUF_VERSION: 1.3.2 + GRPC_GATEWAY_VERSION: 1.14.7 + run: | + # Taken from: tendermintdev/sdk-proto-gen:v0.2 + go get \ + github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogo@v${GOGO_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogofast@v${GOGO_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogofaster@v${GOGO_PROTOBUF_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} \ + github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest + + - name: Install buf + env: + PREFIX: "/usr/local" + VERSION: "1.0.0-rc8" + run: | + curl -sSL "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m).tar.gz" | \ + sudo tar -xvzf - -C "${PREFIX}" --strip-components 1 - uses: actions/checkout@v2 with: - fetch-depth: 0 # FIXME: Starport requires full repository + fetch-depth: 0 # Required to fetch version - name: Build run: | - starport chain build --release - tar xzvf release/cheqd-node_linux_amd64.tar.gz + make proto-gen build - name: Store artifact uses: actions/upload-artifact@v2 with: name: cheqd-noded - path: cheqd-noded + path: build/cheqd-noded build-deb-package: name: Build deb package diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 98f1a3af2..ce8d7188e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -39,24 +39,43 @@ jobs: with: go-version: 1.17 - # There is an issue with the latest starport, especially 0.18 version - - name: Download and install starport - run: wget -qO- https://github.com/tendermint/starport/releases/download/v0.18.6/starport_0.18.6_linux_amd64.tar.gz | tar xvz -C /tmp/ && sudo cp /tmp/starport /usr/bin + - name: Get go protoc compiler plugins + env: + GOLANG_PROTOBUF_VERSION: 1.3.5 + GOGO_PROTOBUF_VERSION: 1.3.2 + GRPC_GATEWAY_VERSION: 1.14.7 + run: | + # Taken from: tendermintdev/sdk-proto-gen:v0.2 + go get \ + github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogo@v${GOGO_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogofast@v${GOGO_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogofaster@v${GOGO_PROTOBUF_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} \ + github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest + + - name: Install buf + env: + PREFIX: "/usr/local" + VERSION: "1.0.0-rc8" + run: | + curl -sSL "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m).tar.gz" | \ + sudo tar -xvzf - -C "${PREFIX}" --strip-components 1 - uses: actions/checkout@v2 with: - fetch-depth: 0 # FIXME: Starport requires full repository + fetch-depth: 0 # Required to fetch version - name: Build run: | - starport chain build --release - tar xzvf release/cheqd-node_linux_amd64.tar.gz + make proto-gen build - name: Store artifact uses: actions/upload-artifact@v2 with: name: cheqd-noded - path: cheqd-noded + path: build/cheqd-noded build-deb-package: name: Build deb package diff --git a/.gitignore b/.gitignore index c325ec45a..e9ced95d6 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ secret.yml # Python .pytest_cache **/__pycache__ +.vscode-upload.json diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d67398b27 --- /dev/null +++ b/Makefile @@ -0,0 +1,119 @@ +export VERSION := $(shell echo $(shell git describe --always --match "v*") | sed 's/^v//') +export TMVERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') +export COMMIT := $(shell git log -1 --format='%H') + +NAME ?= cheqd-node +APPNAME ?= $(NAME)d +LEDGER_ENABLED ?= true + +BINDIR ?= $(GOPATH)/bin +BUILDDIR ?= $(CURDIR)/build + +export GO111MODULE = on + + +### Process build tags +build_tags = netgo +ifeq ($(LEDGER_ENABLED),true) + ifeq ($(OS),Windows_NT) + $(error Windows OS is not supported currently, exiting) + 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 (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS))) + build_tags += gcc +endif + +whitespace := +whitespace += $(whitespace) +comma := , +build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags)) + + +### Process linker flags +ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(NAME)\ + -X github.com/cosmos/cosmos-sdk/version.AppName=$(APPNAME) \ + -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) + + +# DB backend selection +ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS))) + ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb +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)) + + +### Resulting build flags +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 + + +############################################################################### +### Build ### +############################################################################### + + +all: install + +build: go.sum $(BUILDDIR) + go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR)/cheqd-noded ./cmd/cheqd-noded + +install: go.sum + go install -mod=readonly $(BUILD_FLAGS) ./cmd/cheqd-noded + +$(BUILDDIR): + mkdir -p $(BUILDDIR) + +clean: + rm -rf \ + $(BUILDDIR)/ \ + artifacts/ \ + tmp-swagger-gen/ + +.PHONY: all clean build install + +go.sum: go.mod + echo "Ensure dependencies have not been modified ..." >&2 + go mod verify + go mod tidy + + +############################################################################### +### Protobuf ### +############################################################################### + +proto-gen: + bash scripts/protocgen.sh diff --git a/docker/cheqd_node/Dockerfile b/docker/cheqd_node/Dockerfile index 1bd3bba03..ee99c500e 100644 --- a/docker/cheqd_node/Dockerfile +++ b/docker/cheqd_node/Dockerfile @@ -4,33 +4,48 @@ FROM golang:buster as builder RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ && apt-get -y install --no-install-recommends \ - # Common curl \ - # Protoc - protobuf-compiler \ libprotobuf-dev \ wget -# Starport -# RUN curl https://get.starport.network/starport! | bash -# There is an issue with the latest starport, especially 0.18 version -RUN wget -qO- https://github.com/tendermint/starport/releases/download/v0.18.6/starport_0.18.6_linux_amd64.tar.gz | tar xvz -C /tmp/ && cp /tmp/starport /usr/bin + +# Get go protoc compiler plugins. Taken from: tendermintdev/sdk-proto-gen:v0.2 +ENV GOLANG_PROTOBUF_VERSION=1.3.5 \ + GOGO_PROTOBUF_VERSION=1.3.2 \ + GRPC_GATEWAY_VERSION=1.14.7 + +RUN go get \ + github.com/golang/protobuf/protoc-gen-go@v${GOLANG_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogo@v${GOGO_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogofast@v${GOGO_PROTOBUF_VERSION} \ + github.com/gogo/protobuf/protoc-gen-gogofaster@v${GOGO_PROTOBUF_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v${GRPC_GATEWAY_VERSION} \ + github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v${GRPC_GATEWAY_VERSION} \ + github.com/regen-network/cosmos-proto/protoc-gen-gocosmos@latest + + +# Install buf +RUN PREFIX="/usr/local" && \ + VERSION="1.0.0-rc8" && \ + curl -sSL "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m).tar.gz" | \ + tar -xvzf - -C "${PREFIX}" --strip-components 1 + # App WORKDIR /app COPY app ./app COPY cmd ./cmd +COPY scripts ./scripts COPY proto ./proto -COPY vue ./vue COPY x ./x COPY go.mod . COPY go.sum . -# Required by starport +COPY Makefile . +# Required to fetch version COPY .git . -RUN starport chain build --release -RUN tar xzvf release/cheqd-node_linux_amd64.tar.gz +RUN make proto-gen build ##### Run container ##### @@ -38,7 +53,7 @@ RUN tar xzvf release/cheqd-node_linux_amd64.tar.gz FROM ubuntu:focal # Node binary -COPY --from=builder /app/cheqd-noded /bin +COPY --from=builder /app/build/cheqd-noded /bin # Runner script COPY docker/cheqd_node/node-runner.sh /bin/node-runner diff --git a/go.mod b/go.mod index 9985f3ae4..4e2d872c5 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce - github.com/cosmos/cosmos-sdk v0.44.4 + github.com/cosmos/cosmos-sdk v0.44.5 github.com/cosmos/ibc-go v1.2.3 github.com/gogo/protobuf v1.3.3 github.com/golang/protobuf v1.5.2 diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh new file mode 100644 index 000000000..cadf77b2f --- /dev/null +++ b/scripts/protocgen.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +set -euox pipefail + +# Get protoc executions +go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null + +# Get cosmos sdk from github +go get github.com/cosmos/cosmos-sdk 2>/dev/null + +# Get the path of the cosmos-sdk repo from go/pkg/mod +cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk) + +proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq) + +for dir in $proto_dirs; do + # Generate protobuf bind + buf protoc \ + -I "proto" \ + -I "$cosmos_sdk_dir/third_party/proto" \ + -I "$cosmos_sdk_dir/proto" \ + --gocosmos_out=plugins=interfacetype+grpc,\ +Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \ + $(find "${dir}" -name '*.proto') + + # Generate grpc gateway + buf protoc \ + -I "proto" \ + -I "$cosmos_sdk_dir/third_party/proto" \ + -I "$cosmos_sdk_dir/proto" \ + --grpc-gateway_out=logtostderr=true:. \ + $(find "${dir}" -maxdepth 1 -name '*.proto') +done + +cp -r ./github.com/cheqd/cheqd-node/* ./ +rm -rf ./github.com