github.com/sunriselayer/sunrise-da@v0.13.1-sr3/Makefile (about) 1 SHELL=/usr/bin/env bash 2 PROJECTNAME=$(shell basename "$(PWD)") 3 DIR_FULLPATH=$(shell pwd) 4 versioningPath := "github.com/sunriselayer/sunrise-da/nodebuilder/node" 5 LDFLAGS=-ldflags="-X '$(versioningPath).buildTime=$(shell date)' -X '$(versioningPath).lastCommit=$(shell git rev-parse HEAD)' -X '$(versioningPath).semanticVersion=$(shell git describe --tags --dirty=-dev 2>/dev/null || git rev-parse --abbrev-ref HEAD)'" 6 TAGS=integration 7 SHORT= 8 ifeq (${PREFIX},) 9 PREFIX := /usr/local 10 endif 11 ifeq ($(ENABLE_VERBOSE),true) 12 LOG_AND_FILTER = | tee debug.log 13 VERBOSE = -v 14 else 15 VERBOSE = 16 LOG_AND_FILTER = 17 endif 18 ifeq ($(SHORT),true) 19 INTEGRATION_RUN_LENGTH = -short 20 else 21 INTEGRATION_RUN_LENGTH = 22 endif 23 ## help: Get more info on make commands. 24 help: Makefile 25 @echo " Choose a command run in "$(PROJECTNAME)":" 26 @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' 27 .PHONY: help 28 29 ## install-hooks: Install git-hooks from .githooks directory. 30 install-hooks: 31 @echo "--> Installing git hooks" 32 @git config core.hooksPath .githooks 33 .PHONY: install-hooks 34 35 ## build: Build sunrise-da binary. 36 build: 37 @echo "--> Building Sunrise-DA" 38 @go build -o build/ ${LDFLAGS} ./cmd/sunrise-da 39 .PHONY: build 40 41 ## build-jemalloc: Build sunrise-da binary with jemalloc allocator for BadgerDB instead of Go's native one 42 build-jemalloc: jemalloc 43 @echo "--> Building Sunrise-DA with jemalloc" 44 @go build -o build/ ${LDFLAGS} -tags jemalloc ./cmd/sunrise-da 45 .PHONY: build-jemalloc 46 47 ## clean: Clean up sunrise-da binary. 48 clean: 49 @echo "--> Cleaning up ./build" 50 @rm -rf build/* 51 .PHONY: clean 52 53 ## cover: generate to code coverage report. 54 cover: 55 @echo "--> Generating Code Coverage" 56 @go install github.com/ory/go-acc@latest 57 @go-acc -o coverage.txt `go list ./... | grep -v nodebuilder/tests` -- -v 58 .PHONY: cover 59 60 ## deps: install dependencies. 61 deps: 62 @echo "--> Installing Dependencies" 63 @go mod download 64 .PHONY: deps 65 66 ## install: Install all build binaries into the $PREFIX (/usr/local/ by default) directory. 67 install: 68 @echo "--> Installing Sunrise-DA" 69 @install -v ./build/* -t ${PREFIX}/bin/ 70 .PHONY: install 71 72 ## go-install: Build and install the sunrise-da binary into the GOBIN directory. 73 go-install: 74 @echo "--> Installing Sunrise-DA" 75 @go install ${LDFLAGS} ./cmd/sunrise-da 76 .PHONY: go-install 77 78 ## cel-shed: Build cel-shed binary. 79 cel-shed: 80 @echo "--> Building cel-shed" 81 @go build ./cmd/cel-shed 82 .PHONY: cel-shed 83 84 ## install-shed: Build and install the cel-shed binary into the GOBIN directory. 85 install-shed: 86 @echo "--> Installing cel-shed" 87 @go install ./cmd/cel-shed 88 .PHONY: install-shed 89 90 ## cel-key: Build cel-key binary. 91 cel-key: 92 @echo "--> Building cel-key" 93 @go build ./cmd/cel-key 94 .PHONY: cel-key 95 96 ## install-key: Build and install the cel-key binary into the GOBIN directory. 97 install-key: 98 @echo "--> Installing cel-key" 99 @go install ./cmd/cel-key 100 .PHONY: install-key 101 102 ## fmt: Formats only *.go (excluding *.pb.go *pb_test.go). Runs `gofmt & goimports` internally. 103 fmt: sort-imports 104 @find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs gofmt -w -s 105 @find . -name '*.go' -type f -not -path "*.git*" -not -name '*.pb.go' -not -name '*pb_test.go' | xargs goimports -w -local github.com/sunirse-zone 106 @go mod tidy -compat=1.20 107 @cfmt -w -m=100 ./... 108 @markdownlint --fix --quiet --config .markdownlint.yaml . 109 .PHONY: fmt 110 111 ## lint: Linting *.go files using golangci-lint. Look for .golangci.yml for the list of linters. Also lint *.md files using markdownlint. 112 lint: lint-imports 113 @echo "--> Running linter" 114 @golangci-lint run 115 @markdownlint --config .markdownlint.yaml '**/*.md' 116 @cfmt -m=100 ./... 117 .PHONY: lint 118 119 ## test-unit: Running unit tests 120 test-unit: 121 @echo "--> Running unit tests" 122 @go test $(VERBOSE) -covermode=atomic -coverprofile=coverage.txt `go list ./... | grep -v nodebuilder/tests` $(LOG_AND_FILTER) 123 .PHONY: test-unit 124 125 ## test-unit-race: Running unit tests with data race detector 126 test-unit-race: 127 @echo "--> Running unit tests with data race detector" 128 @go test $(VERBOSE) -race -covermode=atomic -coverprofile=coverage.txt `go list ./... | grep -v nodebuilder/tests` $(LOG_AND_FILTER) 129 .PHONY: test-unit-race 130 131 ## test-integration: Running /integration tests located in nodebuilder/tests 132 test-integration: 133 @echo "--> Running integrations tests $(VERBOSE) -tags=$(TAGS) $(INTEGRATION_RUN_LENGTH)" 134 @go test $(VERBOSE) -tags=$(TAGS) $(INTEGRATION_RUN_LENGTH) ./nodebuilder/tests 135 .PHONY: test-integration 136 137 ## test-integration-race: Running integration tests with data race detector located in node/tests 138 test-integration-race: 139 @echo "--> Running integration tests with data race detector -tags=$(TAGS)" 140 @go test -race -tags=$(TAGS) ./nodebuilder/tests 141 .PHONY: test-integration-race 142 143 ## benchmark: Running all benchmarks 144 benchmark: 145 @echo "--> Running benchmarks" 146 @go test -run="none" -bench=. -benchtime=100x -benchmem ./... 147 .PHONY: benchmark 148 149 PB_PKGS=$(shell find . -name 'pb' -type d) 150 PB_CORE=$(shell go list -f {{.Dir}} -m github.com/cometbft/cometbft) 151 PB_GOGO=$(shell go list -f {{.Dir}} -m github.com/gogo/protobuf) 152 PB_CELESTIA_APP=$(shell go list -f {{.Dir}} -m github.com/sunriselayer/sunrise) 153 PB_NMT=$(shell go list -f {{.Dir}} -m github.com/celestiaorg/nmt) 154 155 ## pb-gen: Generate protobuf code for all /pb/*.proto files in the project. 156 pb-gen: 157 @echo '--> Generating protobuf' 158 @for dir in $(PB_PKGS); \ 159 do for file in `find $$dir -type f -name "*.proto"`; \ 160 do protoc -I=. -I=${PB_CORE}/proto/ -I=${PB_GOGO} -I=${PB_CELESTIA_APP}/proto -I=${PB_NMT} --gogofaster_out=paths=source_relative:. $$file; \ 161 echo '-->' $$file; \ 162 done; \ 163 done; 164 .PHONY: pb-gen 165 166 ## openrpc-gen: Generate OpenRPC spec for Sunrise-DA's RPC api 167 openrpc-gen: 168 @echo "--> Generating OpenRPC spec" 169 @go run ./cmd/docgen fraud header state share das p2p node blob da 170 .PHONY: openrpc-gen 171 172 ## lint-imports: Lint only Go imports. 173 ## flag -set-exit-status doesn't exit with code 1 as it should, so we use find until it is fixed by goimports-reviser 174 lint-imports: 175 @echo "--> Running imports linter" 176 @for file in `find . -type f -name '*.go'`; \ 177 do goimports-reviser -list-diff -set-exit-status -company-prefixes "github.com/sunriselayer" -project-name "github.com/sunriselayer/sunrise-da" -output stdout $$file \ 178 || exit 1; \ 179 done; 180 .PHONY: lint-imports 181 182 ## sort-imports: Sort Go imports. 183 sort-imports: 184 @goimports-reviser -company-prefixes "github.com/sunriselayer" -project-name "github.com/sunriselayer/sunrise-da" -output stdout ./... 185 .PHONY: sort-imports 186 187 ## adr-gen: Generate ADR from template. Must set NUM and TITLE parameters. 188 adr-gen: 189 @echo "--> Generating ADR" 190 @curl -sSL https://raw.githubusercontent.com/celestiaorg/.github/main/adr-template.md > docs/architecture/adr-$(NUM)-$(TITLE).md 191 .PHONY: adr-gen 192 193 ## telemetry-infra-up: launches local telemetry infrastructure. This includes grafana, jaeger, loki, pyroscope, and an otel-collector. 194 ## you can access the grafana instance at localhost:3000 and login with admin:admin. 195 telemetry-infra-up: 196 PWD="${DIR_FULLPATH}/docker/telemetry" docker-compose -f ./docker/telemetry/docker-compose.yml up 197 .PHONY: telemetry-infra-up 198 199 ## telemetry-infra-down: tears the telemetry infrastructure down. The stores for grafana, prometheus, and loki will persist. 200 telemetry-infra-down: 201 PWD="${DIR_FULLPATH}/docker/telemetry" docker-compose -f ./docker/telemetry/docker-compose.yml down 202 .PHONY: telemetry-infra-down 203 204 ## goreleaser: List Goreleaser commands and checks if GoReleaser is installed. 205 goreleaser: Makefile 206 @echo " Choose a goreleaser command to run:" 207 @sed -n 's/^## goreleaser/goreleaser/p' $< | column -t -s ':' | sed -e 's/^/ /' 208 @goreleaser --version 209 .PHONY: goreleaser 210 211 ## goreleaser-build: Builds the sunrise binary using GoReleaser for your local OS. 212 goreleaser-build: 213 goreleaser build --snapshot --clean --single-target 214 .PHONY: goreleaser-build 215 216 ## goreleaser-release: Builds the release sunrise binaries as defined in .goreleaser.yaml. This requires there be a git tag for the release in the local git history. 217 goreleaser-release: 218 goreleaser release --clean --fail-fast --skip-publish 219 .PHONY: goreleaser-release 220 221 # Copied from https://github.com/dgraph-io/badger/blob/main/Makefile 222 USER_ID = $(shell id -u) 223 HAS_JEMALLOC = $(shell test -f /usr/local/lib/libjemalloc.a && echo "jemalloc") 224 JEMALLOC_URL = "https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2" 225 226 ## jemalloc installs jemalloc allocator 227 jemalloc: 228 @if [ -z "$(HAS_JEMALLOC)" ] ; then \ 229 mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \ 230 echo "Downloading jemalloc..." ; \ 231 curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \ 232 tar xjf ./jemalloc.tar.bz2 ; \ 233 cd jemalloc-5.2.1 ; \ 234 ./configure --with-jemalloc-prefix='je_' --with-malloc-conf='background_thread:true,metadata_thp:auto'; \ 235 make ; \ 236 if [ "$(USER_ID)" -eq "0" ]; then \ 237 make install ; \ 238 else \ 239 echo "==== Need sudo access to install jemalloc" ; \ 240 sudo make install ; \ 241 fi ; \ 242 cd /tmp ; \ 243 rm -rf /tmp/jemalloc-temp ; \ 244 fi 245 .PHONY: jemalloc