2020-07-10 14:17:51 +00:00
|
|
|
#!/usr/bin/make -f
|
|
|
|
SHELL = bash
|
|
|
|
|
|
|
|
REPO ?= $(shell go list -m)
|
2020-08-04 14:46:12 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --dirty --always)
|
|
|
|
BUILD ?= $(shell date -u --iso=seconds)
|
|
|
|
DEBUG ?= false
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
HUB_IMAGE ?= nspccdev/neofs
|
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
|
|
|
|
BIN = bin
|
|
|
|
DIRS= $(BIN)
|
|
|
|
|
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))
|
|
|
|
|
2020-07-31 21:01:10 +00:00
|
|
|
.PHONY: help all dep clean fmts fmt imports test lint docker/lint
|
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)
|
|
|
|
|
|
|
|
$(BINS): $(DIRS) dep
|
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
2020-07-31 21:01:10 +00:00
|
|
|
GO111MODULE=on \
|
|
|
|
go build -v -trimpath \
|
2020-08-04 14:46:12 +00:00
|
|
|
-ldflags "-X $(REPO)/misc.Version=$(VERSION) \
|
|
|
|
-X $(REPO)/misc.Build=$(BUILD) \
|
|
|
|
-X $(REPO)/misc.Debug=$(DEBUG)" \
|
2020-07-10 14:17:51 +00:00
|
|
|
-o $@ ./cmd/$(notdir $@)
|
|
|
|
|
|
|
|
$(DIRS):
|
|
|
|
@echo "⇒ Ensure dir: $@"
|
|
|
|
@mkdir -p $@
|
|
|
|
|
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Download requirements: "
|
2020-07-31 21:01:10 +00:00
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
go mod download && echo OK
|
2021-03-30 15:01:11 +00:00
|
|
|
@printf "⇒ Tidy requirements : "
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
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
|
|
|
|
@go list -f '{{.Path}}/...@{{.Version}}' -m github.com/golang/protobuf | xargs go get -v
|
|
|
|
# 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 \
|
|
|
|
--go_out=plugins=grpc,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 all-in-one NeoFS docker image
|
|
|
|
image-aio: images
|
|
|
|
@echo "⇒ Build NeoFS All-In-One Docker image "
|
|
|
|
@docker build \
|
|
|
|
--build-arg HUB_IMAGE=$(HUB_IMAGE) \
|
|
|
|
--build-arg HUB_TAG=$(HUB_TAG) \
|
|
|
|
--rm \
|
2021-07-09 13:29:52 +00:00
|
|
|
-f .docker/Dockerfile.aio \
|
2021-07-02 18:07:36 +00:00
|
|
|
-t $(HUB_IMAGE)-aio:$(HUB_TAG) .
|
|
|
|
|
|
|
|
# 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-07-09 10:40:18 +00:00
|
|
|
images: image-storage image-ir image-cli image-adm
|
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
|
|
|
|
|
|
|
# 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"
|
|
|
|
@GO111MODULE=on gofmt -s -w cmd/ pkg/ misc/
|
|
|
|
|
|
|
|
# Reformat imports
|
|
|
|
imports:
|
|
|
|
@echo "⇒ Processing goimports check"
|
|
|
|
@GO111MODULE=on goimports -w cmd/ pkg/ misc/
|
|
|
|
|
|
|
|
# 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"
|
2020-07-31 21:01:10 +00:00
|
|
|
@GO111MODULE=on go test ./...
|
|
|
|
|
|
|
|
# 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:
|
|
|
|
docker run --rm -it \
|
|
|
|
-v `pwd`:/src \
|
|
|
|
-u `stat -c "%u:%g" .` \
|
|
|
|
--env HOME=/src \
|
|
|
|
golangci/golangci-lint:v1.30 bash -c 'cd /src/ && make lint'
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Show this help prompt
|
|
|
|
help:
|
|
|
|
@echo ' Usage:'
|
|
|
|
@echo ''
|
|
|
|
@echo ' make <target>'
|
|
|
|
@echo ''
|
|
|
|
@echo ' Targets:'
|
|
|
|
@echo ''
|
2020-07-31 21:01:10 +00:00
|
|
|
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
|
2020-07-10 14:17:51 +00:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -rf vendor
|
|
|
|
rm -rf $(BIN)
|