Skip to content

Commit

Permalink
Merge pull request #240 from cheqd/local
Browse files Browse the repository at this point in the history
Added Makefile build, clean
  • Loading branch information
Andrew Nikitin authored Dec 9, 2021
2 parents c0e5d97 + 3999ffb commit 74f0d84
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 26 deletions.
33 changes: 26 additions & 7 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 26 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ secret.yml
# Python
.pytest_cache
**/__pycache__
.vscode-upload.json
119 changes: 119 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 27 additions & 11 deletions docker/cheqd_node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,56 @@ 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 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 #####

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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions scripts/protocgen.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 74f0d84

Please sign in to comment.