2020-07-10 14:17:51 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
SHELL = bash
|
|
|
|
|
|
|
|
REPO ?= $(shell go list -m)
|
2022-09-06 07:34:57 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
HUB_IMAGE ?= nspccdev/neofs
|
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
|
2022-03-18 10:42:43 +00:00
|
|
|
GO_VERSION ?= 1.17
|
2022-08-15 16:28:30 +00:00
|
|
|
LINT_VERSION ?= 1.48.0
|
2021-09-15 14:18:44 +00:00
|
|
|
ARCH = amd64
|
2021-08-31 13:13:36 +00:00
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
BIN = bin
|
2021-08-31 13:13:36 +00:00
|
|
|
RELEASE = release
|
2021-09-15 14:18:44 +00:00
|
|
|
DIRS = $(BIN) $(RELEASE)
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-08-04 14:46:12 +00:00
|
|
|
# List of binaries to build.
|
|
|
|
CMDS = $(notdir $(basename $(wildcard cmd/*)))
|
2020-07-10 14:17:51 +00:00
|
|
|
BINS = $(addprefix $(BIN)/, $(CMDS))
|
|
|
|
|
2022-09-19 18:10:14 +00:00
|
|
|
# .deb package versioning
|
|
|
|
OS_RELEASE = $(shell lsb_release -cs)
|
2022-10-26 06:48:00 +00:00
|
|
|
PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \
|
2022-09-19 18:10:14 +00:00
|
|
|
sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \
|
2022-10-27 14:32:33 +00:00
|
|
|
sed "s/-/~/")-${OS_RELEASE}
|
2022-10-26 06:48:00 +00:00
|
|
|
|
|
|
|
.PHONY: help all images dep clean fmts fmt imports test lint docker/lint
|
2022-09-19 18:10:14 +00:00
|
|
|
prepare-release debpackage
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2020-07-24 13:54:03 +00:00
|
|
|
# To build a specific binary, use it's name prefix with bin/ as a target
|
|
|
|
# For example `make bin/neofs-node` will build only storage node binary
|
|
|
|
# Just `make` will build all possible binaries
|
2020-07-10 14:17:51 +00:00
|
|
|
all: $(DIRS) $(BINS)
|
|
|
|
|
2022-07-05 13:56:30 +00:00
|
|
|
# help target
|
|
|
|
include help.mk
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
$(BINS): $(DIRS) dep
|
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
2020-07-31 21:01:10 +00:00
|
|
|
go build -v -trimpath \
|
2022-07-13 14:45:33 +00:00
|
|
|
-ldflags "-X $(REPO)/misc.Version=$(VERSION)" \
|
2020-07-10 14:17:51 +00:00
|
|
|
-o $@ ./cmd/$(notdir $@)
|
|
|
|
|
|
|
|
$(DIRS):
|
|
|
|
@echo "⇒ Ensure dir: $@"
|
|
|
|
@mkdir -p $@
|
|
|
|
|
2021-08-31 13:13:36 +00:00
|
|
|
# Prepare binaries and archives for release
|
2021-09-15 14:18:44 +00:00
|
|
|
.ONESHELL:
|
|
|
|
prepare-release: docker/all
|
|
|
|
@for file in `ls -1 $(BIN)/neofs-*`; do
|
|
|
|
cp $$file $(RELEASE)/`basename $$file`-$(ARCH)
|
|
|
|
strip $(RELEASE)/`basename $$file`-$(ARCH)
|
|
|
|
tar -czf $(RELEASE)/`basename $$file`-$(ARCH).tar.gz $(RELEASE)/`basename $$file`-$(ARCH)
|
2021-08-31 13:13:36 +00:00
|
|
|
done
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Download requirements: "
|
2020-07-31 21:01:10 +00:00
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go mod download && echo OK
|
2021-03-30 15:01:11 +00:00
|
|
|
@printf "⇒ Tidy requirements : "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go mod tidy -v && echo OK
|
2020-10-16 12:45:29 +00:00
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
# Regenerate proto files:
|
|
|
|
protoc:
|
|
|
|
@GOPRIVATE=github.com/nspcc-dev go mod vendor
|
|
|
|
# Install specific version for protobuf lib
|
2022-01-24 09:40:22 +00:00
|
|
|
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go install -v
|
2022-06-20 10:24:30 +00:00
|
|
|
@GOBIN=$(abspath $(BIN)) go install -mod=mod -v github.com/nspcc-dev/neofs-api-go/v2/util/protogen
|
2020-07-10 14:17:51 +00:00
|
|
|
# Protoc generate
|
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
|
|
|
|
echo "⇒ Processing $$f "; \
|
|
|
|
protoc \
|
2021-01-15 06:22:56 +00:00
|
|
|
--proto_path=.:./vendor:/usr/local/include \
|
2022-06-20 10:24:30 +00:00
|
|
|
--plugin=protoc-gen-go-neofs=$(BIN)/protogen \
|
|
|
|
--go-neofs_out=. --go-neofs_opt=paths=source_relative \
|
2021-09-28 15:22:02 +00:00
|
|
|
--go_out=. --go_opt=paths=source_relative \
|
|
|
|
--go-grpc_opt=require_unimplemented_servers=false \
|
|
|
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
2020-07-10 14:17:51 +00:00
|
|
|
done
|
2020-07-31 21:01:10 +00:00
|
|
|
rm -rf vendor
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2021-07-02 18:07:36 +00:00
|
|
|
# Build NeoFS component's docker image
|
2020-08-03 18:44:42 +00:00
|
|
|
image-%:
|
|
|
|
@echo "⇒ Build NeoFS $* docker image "
|
2020-07-10 14:17:51 +00:00
|
|
|
@docker build \
|
|
|
|
--build-arg REPO=$(REPO) \
|
|
|
|
--build-arg VERSION=$(VERSION) \
|
2020-07-31 21:01:10 +00:00
|
|
|
--rm \
|
2021-07-09 13:29:52 +00:00
|
|
|
-f .docker/Dockerfile.$* \
|
2020-08-03 18:44:42 +00:00
|
|
|
-t $(HUB_IMAGE)-$*:$(HUB_TAG) .
|
2020-07-24 13:54:03 +00:00
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
# Build all Docker images
|
2021-09-14 09:07:34 +00:00
|
|
|
images: image-storage image-ir image-cli image-adm image-storage-testnet
|
2020-07-10 14:17:51 +00:00
|
|
|
|
2021-03-17 16:58:31 +00:00
|
|
|
# Build dirty local Docker images
|
2021-07-09 10:40:18 +00:00
|
|
|
dirty-images: image-dirty-storage image-dirty-ir image-dirty-cli image-dirty-adm
|
2021-03-17 16:58:31 +00:00
|
|
|
|
2021-09-13 14:47:09 +00:00
|
|
|
# Run `make %` in Golang container
|
|
|
|
docker/%:
|
2021-10-13 15:37:40 +00:00
|
|
|
docker run --rm -t \
|
2021-09-13 14:47:09 +00:00
|
|
|
-v `pwd`:/src \
|
|
|
|
-w /src \
|
|
|
|
-u "$$(id -u):$$(id -g)" \
|
|
|
|
--env HOME=/src \
|
|
|
|
golang:$(GO_VERSION) make $*
|
|
|
|
|
|
|
|
|
2021-03-17 16:58:31 +00:00
|
|
|
# Run all code formatters
|
2020-07-31 21:01:10 +00:00
|
|
|
fmts: fmt imports
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
# Reformat code
|
|
|
|
fmt:
|
2020-07-31 21:01:10 +00:00
|
|
|
@echo "⇒ Processing gofmt check"
|
2022-07-05 13:56:30 +00:00
|
|
|
@gofmt -s -w cmd/ pkg/ misc/
|
2020-07-31 21:01:10 +00:00
|
|
|
|
|
|
|
# Reformat imports
|
|
|
|
imports:
|
|
|
|
@echo "⇒ Processing goimports check"
|
2022-07-05 13:56:30 +00:00
|
|
|
@goimports -w cmd/ pkg/ misc/
|
2020-07-31 21:01:10 +00:00
|
|
|
|
|
|
|
# Run Unit Test with go test
|
2021-06-09 12:28:23 +00:00
|
|
|
test:
|
2020-12-30 10:07:48 +00:00
|
|
|
@echo "⇒ Running go test"
|
2022-07-05 13:56:30 +00:00
|
|
|
@go test ./...
|
2020-07-31 21:01:10 +00:00
|
|
|
|
|
|
|
# Run linters
|
|
|
|
lint:
|
2020-11-18 16:27:05 +00:00
|
|
|
@golangci-lint --timeout=5m run
|
2020-07-31 21:01:10 +00:00
|
|
|
|
|
|
|
# Run linters in Docker
|
|
|
|
docker/lint:
|
2021-10-13 15:37:40 +00:00
|
|
|
docker run --rm -t \
|
2020-07-31 21:01:10 +00:00
|
|
|
-v `pwd`:/src \
|
|
|
|
-u `stat -c "%u:%g" .` \
|
|
|
|
--env HOME=/src \
|
2022-07-05 13:56:30 +00:00
|
|
|
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf vendor
|
2022-07-05 13:56:30 +00:00
|
|
|
rm -rf .cache
|
2020-07-10 14:17:51 +00:00
|
|
|
rm -rf $(BIN)
|
2021-08-31 13:13:36 +00:00
|
|
|
rm -rf $(RELEASE)
|
2022-09-19 18:10:14 +00:00
|
|
|
|
|
|
|
# Package for Debian
|
|
|
|
debpackage:
|
2022-10-26 06:48:00 +00:00
|
|
|
dch --package neofs-node \
|
|
|
|
--controlmaint \
|
|
|
|
--newversion $(PKG_VERSION) \
|
|
|
|
--distribution $(OS_RELEASE) \
|
|
|
|
"Please see CHANGELOG.md for code changes for $(VERSION)"
|
|
|
|
dpkg-buildpackage --no-sign -b
|
2022-09-19 18:10:14 +00:00
|
|
|
|
|
|
|
debclean:
|
2022-10-26 06:48:00 +00:00
|
|
|
dh clean
|