Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Merge pull request #445 from BitCannaGlobal/v4
Browse files Browse the repository at this point in the history
Update v4-devnet-1 with v4 changes
  • Loading branch information
RaulBernal authored Oct 3, 2024
2 parents 07792dc + 2bae26e commit 5a98918
Show file tree
Hide file tree
Showing 7 changed files with 218 additions and 41,349 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This is a basic workflow that is manually triggered

name: compile bcna

# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
# This workflow makes x86_64 binaries for mac, windows, and linux.

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
targetos: [darwin, linux]
include:
- targetos: windows
arch: amd64
name: bcna ${{ matrix.arch }} for ${{ matrix.targetos }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: "^1.23"
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}

- name: run tests
run: go test ./...

# we build and install in case we want to run it or capture an artifact as we do in the step below.
- name: Compile bcnad
run: |
go build ./...
go install ./...
# now uploads genesis.json and bin
- uses: actions/upload-artifact@v3
with:
name: bcnad ${{ matrix.targetos }} ${{ matrix.arch }}
path: build/bcnad
37 changes: 37 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: "Release"

on:
push:
tags:
- v*
branches:
- v4
jobs:
draft-release:
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Copy Binary
run: |
make build-reproducible-all
- name: List files
run: ls -R

- name: Draft Release
uses: softprops/action-gh-release@v1
with:
draft: true
files: |
build/bcnad_linux_arm64
build/bcnad_linux_amd64
build/bcnad_sha256.txt
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG IMG_TAG=latest
ARG PLATFORM="linux/amd64"
ARG GO_VERSION="1.23.1"
ARG RUNNER_IMAGE="gcr.io/distroless/static"

FROM --platform=${PLATFORM} golang:${GO_VERSION}-alpine3.20 as builder
WORKDIR /src/app/
COPY go.mod go.sum* ./
RUN go mod download
COPY . .

# From https://github.com/CosmWasm/wasmd/blob/master/Dockerfile
# For more details see https://github.com/CosmWasm/wasmvm#builds-of-libwasmvm
ARG ARCH=x86_64
# See https://github.com/CosmWasm/wasmvm/releases
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm_muslc.aarch64.a /lib/libwasmvm_muslc.aarch64.a
ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a
#ADD https://github.com/CosmWasm/wasmvm/releases/download/v2.1.3/libwasmvmstatic_darwin.a /lib/libwasmvm_muslc.darwin.a
RUN sha256sum /lib/libwasmvm_muslc.aarch64.a | grep faea4e15390e046d2ca8441c21a88dba56f9a0363f92c5d94015df0ac6da1f2d
RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep 8dab08434a5fe57a6fbbcb8041794bc3c31846d31f8ff5fb353ee74e0fcd3093
#RUN sha256sum /lib/libwasmvm_muslc.darwin.a | grep f7a997c6a769e5624dac910dc2f0bec4c386aeb54342dd04ef6d5eba0340a20d
RUN cp /lib/libwasmvm_muslc.${ARCH}.a /lib/libwasmvm_muslc.a

ENV PACKAGES curl make git libc-dev bash gcc linux-headers eudev-dev python3
RUN apk add --no-cache $PACKAGES
RUN set -eux; apk add --no-cache ca-certificates build-base;

ARG VERSION=""
RUN BUILD_TAGS=muslc LINK_STATICALLY=true LDFLAGS=-buildid=$VERSION make build

# Add to a distroless container
ARG PLATFORM="linux/amd64"
FROM --platform=${PLATFORM} gcr.io/distroless/cc:$IMG_TAG
ARG IMG_TAG
COPY --from=builder /src/app/build/bcnad /usr/local/bin/bcnad

EXPOSE 26656 26657 1317 9090

ENTRYPOINT ["bcnad"]
170 changes: 94 additions & 76 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
#!/usr/bin/make -f

BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
BUILD_DIR ?= $(CURDIR)/build
DIST_DIR ?= $(CURDIR)/dist
LEDGER_ENABLED ?= true
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
DOCKER := $(shell which docker)
PROJECT_NAME := bitcanna
HTTPS_GIT := https://github.com/BitCannaGlobal/bcna.git

###############################################################################
## Version ##
###############################################################################
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
GO_VERSION := "1.23"
BUILD_DIR ?= $(CURDIR)/build

# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --tags | sed 's/^v//')
VERSION := $(shell git describe --tags)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif

GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
###############################################################################
## Build ##
###############################################################################
PACKAGES_SIMTEST=$(shell go list ./... | grep '/simulation')
LEDGER_ENABLED ?= true
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::') # grab everything after the space in "github.com/cometbft/cometbft v0.37.0"
BUILDDIR ?= $(CURDIR)/build
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.7.0

build_tags = netgo
export GO111MODULE = on

# process build tags

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
Expand All @@ -53,94 +50,115 @@ ifeq ($(LEDGER_ENABLED),true)
endif
endif

ifeq (cleveldb,$(findstring cleveldb,$(bitcanna_BUILD_OPTIONS)))
build_tags += gcc cleveldb
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

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=bcna \
-X github.com/cosmos/cosmos-sdk/version.AppName=bcnad \
-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/cometbft/cometbft/version.TMCoreSemVer=$(TM_VERSION)

ifeq (cleveldb,$(findstring cleveldb,$(bitcanna_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq (,$(findstring nostrip,$(bitcanna_BUILD_OPTIONS)))
ldflags += -w -s
endif
ifeq ($(LINK_STATICALLY),true)
ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static"
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'

check_version:
ifeq ($(shell expr $(GO_MINOR_VERSION) \< 23), 1)
@echo "ERROR: Go version 1.23 or newer is required for building BCNAD."
exit 1
# check for nostrip option
ifeq (,$(findstring nostrip,$(bitcanna_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

#$(info $$BUILD_FLAGS is [$(BUILD_FLAGS)])


all: check-go-version install

build: check_version go.sum
@echo "--> Building..."
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILD_DIR)/ ./...
install: check-go-version go.sum
go install -mod=readonly $(BUILD_FLAGS) ./...

install: check_version go.sum
@echo "--> Installing..."
go install -mod=readonly $(BUILD_FLAGS) ./...
build: check-go-version
go build $(BUILD_FLAGS) -o $(BUILD_DIR)/ ./...

build-linux: check_version go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build
BUILD_TARGETS := build install

go-mod-cache: check_version go.sum
@echo "--> Download go modules to local cache"
@go mod download
build-reproducible-all: build-reproducible-amd64 build-reproducible-arm64

go.sum: check_version go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify
build-reproducible-amd64:
ARCH=x86_64 PLATFORM=linux/amd64 $(MAKE) build-reproducible-generic

go-mod-tidy:
@contrib/scripts/go-mod-tidy-all.sh
build-reproducible-arm64:
ARCH=aarch64 PLATFORM=linux/arm64 $(MAKE) build-reproducible-generic

build-reproducible-generic: go.sum
$(DOCKER) rm $(subst /,-,latest-build-$(PLATFORM)) || true
DOCKER_BUILDKIT=1 $(DOCKER) build -t latest-build-$(PLATFORM) \
--build-arg ARCH=$(ARCH) \
--build-arg GO_VERSION=$(GO_VERSION) \
--build-arg PLATFORM=$(PLATFORM) \
--build-arg VERSION="$(VERSION)" \
-f Dockerfile .
mkdir -p build
$(DOCKER) create -ti --name $(subst /,-,latest-build-$(PLATFORM)) latest-build-$(PLATFORM) bcnad
$(DOCKER) cp -a $(subst /,-,latest-build-$(PLATFORM)):/usr/local/bin/bcnad $(BUILD_DIR)/bcnad_$(subst /,_,$(PLATFORM))
sha256sum $(BUILD_DIR)/bcnad_$(subst /,_,$(PLATFORM)) >> $(BUILD_DIR)/bcnad_sha256.txt

# Add check to make sure we are using the proper Go version before proceeding with anything
check-go-version:
@if ! go version | grep -q "go$(GO_VERSION)"; then \
echo "\033[0;31mERROR:\033[0m Go version $(GO_VERSION) is required for compiling BCNAD. It looks like you are using" "$(shell go version) \nThere are potential consensus-breaking changes that can occur when running binaries compiled with different versions of Go. Please download Go version $(GO_VERSION) and retry. Thank you!"; \
exit 1; \
fi

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

.PHONY: install build build-linux clean

###############################################################################
## Protobuf ##
### Protobuf ###
###############################################################################

DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf

containerProtoVer=v0.2
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(containerProtoVer)
containerProtoFmt=$(PROJECT_NAME)-proto-fmt-$(containerProtoVer)
containerProtoGenSwagger=$(PROJECT_NAME)-proto-gen-swagger-$(containerProtoVer)

proto-all: proto-format proto-lint proto-gen proto-swagger-gen
containerProtoVer=0.13.0
containerProtoImage=ghcr.io/cosmos/proto-builder:$(containerProtoVer)

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen.sh; fi

proto-swagger-gen:
@echo "Generating Swagger of Protobuf"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenSwagger}$$"; then docker start -a $(containerProtoGenSwagger); else docker run --name $(containerProtoGenSwagger) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protoc-swagger-gen.sh; fi

proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./ -name "*.proto" -exec sh -c 'clang-format -style=file -i {}' \; ; fi

proto-lint:
@echo "Linting Protobuf files"
@$(DOCKER_BUF) lint --error-format=json

proto-check-breaking:
@echo "Checking for breaking changes"
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=main


.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-format proto-swagger-gen
@$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
sh ./scripts/protocgen.sh;

docs:
@echo
@echo "=========== Generate Message ============"
@echo
./scripts/protoc-swagger-gen.sh

statik -src=docs/static -dest=docs -f -m
@if [ -n "$(git status --porcelain)" ]; then \
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
exit 1;\
else \
echo "\033[92mSwagger docs are in sync\033[0m";\
fi
@echo
@echo "=========== Generate Complete ============"
@echo
.PHONY: docs
Loading

0 comments on commit 5a98918

Please sign in to comment.