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
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
HUB_IMAGE ?= truecloudlab/frostfs
|
2020-07-10 14:17:51 +00:00
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
|
2023-08-09 06:40:50 +00:00
|
|
|
GO_VERSION ?= 1.21
|
2023-08-11 10:05:16 +00:00
|
|
|
LINT_VERSION ?= 1.54.0
|
2023-08-16 15:26:36 +00:00
|
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.2
|
2023-08-11 10:05:16 +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.
|
2023-01-16 09:20:16 +00:00
|
|
|
CMDS = $(notdir $(basename $(wildcard cmd/frostfs-*)))
|
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
|
|
|
|
2023-08-09 12:53:01 +00:00
|
|
|
OUTPUT_LINT_DIR ?= $(shell pwd)/bin
|
2023-08-16 15:26:36 +00:00
|
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
2023-08-09 12:53:01 +00:00
|
|
|
TMP_DIR := .cache
|
|
|
|
|
2022-10-26 06:48:00 +00:00
|
|
|
.PHONY: help all images dep clean fmts fmt imports test lint docker/lint
|
2023-03-13 07:36:16 +00:00
|
|
|
prepare-release debpackage pre-commit unpre-commit
|
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
|
2022-12-23 17:35:35 +00:00
|
|
|
# For example `make bin/frostfs-node` will build only storage node binary
|
2020-07-24 13:54:03 +00:00
|
|
|
# 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
|
2022-12-23 17:35:35 +00:00
|
|
|
@for file in `ls -1 $(BIN)/frostfs-*`; do
|
2021-09-15 14:18:44 +00:00
|
|
|
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
|
|
|
|
2023-10-05 15:00:16 +00:00
|
|
|
# Build export-metrics
|
|
|
|
export-metrics: dep
|
|
|
|
@printf "⇒ Build export-metrics\n"
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go build -v -trimpath -o bin/export-metrics ./scripts/export-metrics
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
# Regenerate proto files:
|
|
|
|
protoc:
|
2022-12-23 17:35:35 +00:00
|
|
|
@GOPRIVATE=github.com/TrueCloudLab go mod vendor
|
2020-07-10 14:17:51 +00:00
|
|
|
# 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
|
2023-03-07 13:38:26 +00:00
|
|
|
@GOBIN=$(abspath $(BIN)) go install -mod=mod -v git.frostfs.info/TrueCloudLab/frostfs-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-12-23 17:35:35 +00:00
|
|
|
--plugin=protoc-gen-go-frostfs=$(BIN)/protogen \
|
|
|
|
--go-frostfs_out=. --go-frostfs_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
|
|
|
|
2023-01-09 07:04:58 +00:00
|
|
|
# Build FrostFS component's docker image
|
2020-08-03 18:44:42 +00:00
|
|
|
image-%:
|
2023-01-09 07:04:58 +00:00
|
|
|
@echo "⇒ Build FrostFS $* 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
|
2023-06-26 10:52:58 +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
|
|
|
|
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"
|
2023-05-18 09:21:12 +00:00
|
|
|
@go test ./... -count=1
|
2020-07-31 21:01:10 +00:00
|
|
|
|
2023-04-03 14:05:10 +00:00
|
|
|
pre-commit-run:
|
|
|
|
@pre-commit run -a --hook-stage manual
|
|
|
|
|
2023-08-09 12:53:01 +00:00
|
|
|
# Install linters
|
|
|
|
lint-install:
|
|
|
|
@mkdir -p $(TMP_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
2023-08-16 15:26:36 +00:00
|
|
|
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
|
2023-08-11 10:05:16 +00:00
|
|
|
@@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
|
2023-08-09 12:53:01 +00:00
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@rmdir $(TMP_DIR) 2>/dev/null || true
|
2023-08-11 10:05:16 +00:00
|
|
|
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
2023-08-09 12:53:01 +00:00
|
|
|
|
2020-07-31 21:01:10 +00:00
|
|
|
# Run linters
|
|
|
|
lint:
|
2023-08-11 10:05:16 +00:00
|
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
|
|
echo "Run make lint-install"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
$(LINT_DIR)/golangci-lint run
|
2020-07-31 21:01:10 +00:00
|
|
|
|
2023-07-05 08:57:16 +00:00
|
|
|
# Install staticcheck
|
|
|
|
staticcheck-install:
|
|
|
|
@go install honnef.co/go/tools/cmd/staticcheck@latest
|
|
|
|
|
2023-04-03 14:05:10 +00:00
|
|
|
# Run staticcheck
|
2023-07-05 08:57:16 +00:00
|
|
|
staticcheck-run:
|
2023-04-03 14:05:10 +00:00
|
|
|
@staticcheck ./...
|
|
|
|
|
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
|
|
|
|
2023-03-13 07:36:16 +00:00
|
|
|
# Activate pre-commit hooks
|
|
|
|
pre-commit:
|
|
|
|
pre-commit install -t pre-commit -t commit-msg
|
|
|
|
|
|
|
|
# Deactivate pre-commit hooks
|
|
|
|
unpre-commit:
|
|
|
|
pre-commit uninstall -t pre-commit -t commit-msg
|
|
|
|
|
2020-07-10 14:17:51 +00:00
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
2023-03-13 07:36:16 +00:00
|
|
|
# Delete built artifacts
|
2020-07-10 14:17:51 +00:00
|
|
|
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:
|
2023-01-30 09:25:46 +00:00
|
|
|
dch -b --package frostfs-node \
|
2022-10-26 06:48:00 +00:00
|
|
|
--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
|