-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(make): put Makefile workflows in separate directory (#1138)
- Loading branch information
Showing
15 changed files
with
256 additions
and
276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
FROM golang:1.18 AS builder | ||
FROM golang:1.19 AS builder | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
jq \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
WORKDIR /nibiru | ||
ARG ARCH=aarch64 | ||
ENV BUILD_TAGS=muslc \ | ||
CGO_ENABLED=1 \ | ||
LDFLAGS='-s -w -linkmode=external -extldflags "-Wl,-z,muldefs -static -lm"' | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
musl-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
RUN wget https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.${ARCH}.a -O /lib/libwasmvm_muslc.a | ||
|
||
WORKDIR /nibid | ||
COPY . ./ | ||
RUN CGO_ENABLED=0 make build | ||
RUN make build | ||
|
||
FROM alpine:latest | ||
WORKDIR /root | ||
RUN apk --no-cache add ca-certificates | ||
WORKDIR /root/ | ||
COPY --from=builder /nibid/build/nibid /usr/local/bin/nibid | ||
COPY --from=builder /nibiru/build/nibid /usr/local/bin/nibid | ||
ENTRYPOINT ["nibid"] | ||
CMD [ "start" ] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,197 +1,12 @@ | ||
############################################################################### | ||
### Proto ### | ||
############################################################################### | ||
UNAME_OS := $(shell uname -s) | ||
UNAME_ARCH := $(shell uname -m) | ||
|
||
containerProtoVer=v0.3 | ||
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer) | ||
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer) | ||
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer) | ||
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer) | ||
include contrib/make/build.mk | ||
include contrib/make/localnet.mk | ||
include contrib/make/proto.mk | ||
include contrib/make/mock.mk | ||
include contrib/make/lint.mk | ||
include contrib/make/test.mk | ||
include contrib/make/simulation.mk | ||
|
||
mock-gen: | ||
go generate ./... | ||
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 | ||
|
||
.PHONY: proto | ||
|
||
############################################################################### | ||
### Build Flags ### | ||
############################################################################### | ||
|
||
BRANCH := $(shell git rev-parse --abbrev-ref HEAD) | ||
COMMIT := $(shell git log -1 --format='%H') | ||
|
||
# don't override user values | ||
ifeq (,$(VERSION)) | ||
VERSION := $(shell git describe --exact-match 2>/dev/null) | ||
# if VERSION is empty, then populate it with branch's name and raw commit hash | ||
ifeq (,$(VERSION)) | ||
VERSION := $(BRANCH)-$(COMMIT) | ||
endif | ||
endif | ||
|
||
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') | ||
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7" | ||
DOCKER := $(shell which docker) | ||
BUILDDIR ?= $(CURDIR)/build | ||
|
||
export GO111MODULE = on | ||
|
||
# process build tags | ||
build_tags = netgo | ||
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=nibiru \ | ||
-X github.com/cosmos/cosmos-sdk/version.AppName=nibid \ | ||
-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=$(TM_VERSION) | ||
ldflags += $(LDFLAGS) | ||
ldflags := $(strip $(ldflags)) | ||
|
||
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' | ||
|
||
############################################################################### | ||
### Build ### | ||
############################################################################### | ||
|
||
# command for make build and make install | ||
build: BUILD_ARGS=-o $(BUILDDIR)/ | ||
build install: go.sum $(BUILDDIR)/ | ||
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... | ||
|
||
# ensure build directory exists | ||
$(BUILDDIR)/: | ||
mkdir -p $(BUILDDIR)/ | ||
|
||
# build for linux architecture | ||
build-linux: go.sum | ||
CGO_ENABLED=1 LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build | ||
|
||
go.sum: go.mod | ||
@echo "--> Ensure dependencies have not been modified" | ||
@go mod verify | ||
|
||
.PHONY: build install | ||
|
||
############################################################################### | ||
### Docker Localnet ### | ||
############################################################################### | ||
|
||
build-docker-nibidnode: | ||
docker build --tag nibiru/nibidnode . | ||
|
||
# Run a 4-node testnet locally | ||
localnet-start: build-linux localnet-stop | ||
@if ! [ -f build/node0/nibid/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/nibid:Z nibiru/nibidnode testnet --v 4 -o . --starting-ip-address 192.168.11.2 --keyring-backend=test ; fi | ||
docker-compose up -d | ||
|
||
# Stop testnet | ||
localnet-stop: | ||
docker-compose down | ||
|
||
.PHONY: localnet | ||
|
||
############################################################################### | ||
### Shell Localnet ### | ||
############################################################################### | ||
|
||
# Run a single testnet locally | ||
localnet: | ||
./scripts/localnet.sh | ||
|
||
.PHONY: localnet | ||
|
||
############################################################################### | ||
### Tests & Simulations ### | ||
############################################################################### | ||
|
||
BINDIR ?= $(GOPATH)/bin | ||
BUILDDIR ?= $(CURDIR)/build | ||
SIMAPP = ./simapp | ||
PACKAGES_NOSIMULATION = $(shell go list ./... | grep -v '/simapp') | ||
RUNSIM = $(BINDIR)/runsim | ||
|
||
test-unit: | ||
@go test $(PACKAGES_NOSIMULATION) -short -cover | ||
|
||
test-integration: | ||
@go test -v $(PACKAGES_NOSIMULATION) -cover | ||
|
||
runsim: $(RUNSIM) | ||
$(RUNSIM): | ||
@echo "Installing runsim..." | ||
@(cd /tmp && go install github.com/cosmos/tools/cmd/[email protected]) | ||
|
||
test-sim-nondeterminism: | ||
@echo "Running non-determinism test..." | ||
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \ | ||
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h | ||
|
||
test-sim-default-genesis-fast: | ||
@echo "Running default genesis simulation..." | ||
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation \ | ||
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v | ||
|
||
test-sim-custom-genesis-multi-seed: runsim | ||
@echo "Running multi-seed custom genesis simulation..." | ||
@$(RUNSIM) -SimAppPkg=$(SIMAPP) -ExitOnFail 400 5 TestFullAppSimulation | ||
|
||
test-sim-multi-seed-long: runsim | ||
@echo "Running long multi-seed application simulation. This may take awhile!" | ||
@$(RUNSIM) -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestFullAppSimulation | ||
|
||
test-sim-multi-seed-short: runsim | ||
@echo "Running short multi-seed application simulation. This may take awhile!" | ||
@$(RUNSIM) -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 50 10 TestFullAppSimulation | ||
|
||
test-sim-benchmark-invariants: | ||
@echo "Running simulation invariant benchmarks..." | ||
@go test -mod=readonly $(SIMAPP) -benchmem -bench=BenchmarkInvariants -run=^$ \ | ||
-Enabled=true -NumBlocks=1000 -BlockSize=200 \ | ||
-Period=1 -Commit=true -Seed=57 -v -timeout 24h | ||
|
||
# Require Python3 | ||
test-create-test-cases: | ||
@python scripts/testing/stableswap_model.py | ||
|
||
############################################################################### | ||
### Lint ### | ||
############################################################################### | ||
release: | ||
docker run --rm -v "$(CURDIR)":/code -w /code goreleaser/goreleaser-cross --skip-publish --rm-dist | ||
|
||
build-docker: go.sum $(BUILDDIR)/ | ||
go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/nibid/main.go | ||
tar -czvf build/$(TARNAME).tar.gz build/nibid | ||
rm build/nibid | ||
|
||
build-linux-docker: | ||
BUILD_TAGS=muslc LINK_STATICALLY=true TARNAME="nibiru_linux_amd64" CC=aarch64-linux-gnu-gcc BUILD_ARGS="-o $(BUILDDIR)/nibid -tags=muslc" CGO_ENABLED=1 LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build-docker | ||
# TARNAME="nibiru_linux_arm64" BUILD_ARGS="-o $(BUILDDIR)/nibid -tags=muslc" CGO_ENABLED=1 LEDGER_ENABLED=false GOOS=linux GOARCH=arm64 $(MAKE) build-docker | ||
|
||
############################################################################### | ||
### Lint ### | ||
############################################################################### | ||
|
||
lint: | ||
docker run -v $(CURDIR):/code --rm -w /code golangci/golangci-lint:v1.49-alpine golangci-lint run | ||
|
||
.PHONY: \ | ||
test-sim-nondeterminism \ | ||
test-sim-custom-genesis-fast \ | ||
test-sim-custom-genesis-multi-seed \ | ||
test-sim-multi-seed-short \ | ||
test-sim-multi-seed-long \ | ||
test-sim-benchmark-invariants |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM golang:1.19 | ||
|
||
WORKDIR /nibiru | ||
ARG ARCH=aarch64 | ||
ENV BUILD_TAGS=muslc \ | ||
CGO_ENABLED=1 \ | ||
LDFLAGS='-s -w -linkmode=external -extldflags "-Wl,-z,muldefs -static -lm"' | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
musl-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
RUN wget https://github.com/CosmWasm/wasmvm/releases/download/v1.1.1/libwasmvm_muslc.${ARCH}.a -O /lib/libwasmvm_muslc.a | ||
|
||
COPY . ./ | ||
|
||
ENTRYPOINT ["make"] | ||
CMD [ "build" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
############################################################################### | ||
### Build Flags ### | ||
############################################################################### | ||
|
||
BRANCH := $(shell git rev-parse --abbrev-ref HEAD) | ||
COMMIT := $(shell git log -1 --format='%H') | ||
|
||
# don't override user values | ||
ifeq (,$(VERSION)) | ||
VERSION := $(shell git describe --exact-match 2>/dev/null) | ||
# if VERSION is empty, then populate it with branch's name and raw commit hash | ||
ifeq (,$(VERSION)) | ||
VERSION := $(BRANCH)-$(COMMIT) | ||
endif | ||
endif | ||
|
||
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g') | ||
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') # grab everything after the space in "github.com/tendermint/tendermint v0.34.7" | ||
DOCKER := $(shell which docker) | ||
BUILDDIR ?= $(CURDIR)/build | ||
|
||
export GO111MODULE = on | ||
|
||
# process build tags | ||
build_tags = netgo | ||
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=nibiru \ | ||
-X github.com/cosmos/cosmos-sdk/version.AppName=nibid \ | ||
-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=$(TM_VERSION) | ||
ldflags += $(LDFLAGS) | ||
ldflags := $(strip $(ldflags)) | ||
|
||
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' | ||
|
||
############################################################################### | ||
### Build ### | ||
############################################################################### | ||
|
||
# command for make build and make install | ||
build: BUILDARGS=-o $(BUILDDIR)/ | ||
build install: go.sum $(BUILDDIR)/ | ||
go $@ -mod=readonly $(BUILD_FLAGS) $(BUILDARGS) ./... | ||
|
||
# ensure build directory exists | ||
$(BUILDDIR)/: | ||
mkdir -p $(BUILDDIR)/ | ||
|
||
# build for linux architecture | ||
build-linux: go.sum | ||
docker build -f contrib/docker/linux.Dockerfile -t nibiru-builder . | ||
docker run --rm -it -v `pwd`:/nibiru nibiru-builder | ||
|
||
go.sum: go.mod | ||
@echo "--> Ensure dependencies have not been modified" | ||
@go mod verify | ||
|
||
.PHONY: build install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
############################################################################### | ||
### Lint ### | ||
############################################################################### | ||
|
||
.PHONY: lint | ||
lint: | ||
docker run -v $(CURDIR):/code --rm -w /code golangci/golangci-lint:v1.49-alpine golangci-lint run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
############################################################################### | ||
### Simple Localnet ### | ||
############################################################################### | ||
|
||
# Simple localnet script for testing | ||
.PHONY: localnet | ||
localnet: | ||
./scripts/localnet.sh | ||
|
||
############################################################################### | ||
### Docker Localnet ### | ||
############################################################################### | ||
|
||
.PHONY: build-docker-node | ||
build-docker-node: | ||
docker build -t nibiru/node . | ||
|
||
# Run a 4-node testnet locally | ||
.PHONY: localnet-start | ||
localnet-start: build-docker-node localnet-stop | ||
@if ! [ -f data/node0/nibid/config/genesis.json ]; then \ | ||
docker run --rm -v $(CURDIR)/data:/nibiru:Z nibiru/node testnet \ | ||
--v 4 \ | ||
-o /nibiru \ | ||
--chain-id nibiru-localnet-0 \ | ||
--starting-ip-address 192.168.11.2 \ | ||
--keyring-backend=test; \ | ||
fi | ||
docker-compose up -d | ||
|
||
# Stop testnet | ||
.PHONY: localnet-stop | ||
localnet-stop: | ||
docker-compose down |
Oops, something went wrong.