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//')"
|
|
|
|
|
2024-02-19 14:03:32 +00:00
|
|
|
GO_VERSION ?= 1.21
|
2023-12-11 10:01:32 +00:00
|
|
|
LINT_VERSION ?= 1.55.2
|
|
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.3
|
2023-11-08 12:43:54 +00:00
|
|
|
PROTOC_VERSION ?= 25.0
|
|
|
|
PROTOC_GEN_GO_VERSION ?= $(shell go list -f '{{.Version}}' -m google.golang.org/protobuf)
|
|
|
|
PROTOGEN_FROSTFS_VERSION ?= $(shell go list -f '{{.Version}}' -m git.frostfs.info/TrueCloudLab/frostfs-api-go/v2)
|
|
|
|
PROTOC_OS_VERSION=osx-x86_64
|
|
|
|
ifeq ($(shell uname), Linux)
|
|
|
|
PROTOC_OS_VERSION=linux-x86_64
|
|
|
|
endif
|
|
|
|
STATICCHECK_VERSION ?= 2023.1.6
|
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-11-08 12:43:54 +00:00
|
|
|
OUTPUT_LINT_DIR ?= $(abspath $(BIN))/linters
|
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
|
2023-11-08 12:43:54 +00:00
|
|
|
PROTOBUF_DIR ?= $(abspath $(BIN))/protobuf
|
|
|
|
PROTOC_DIR ?= $(PROTOBUF_DIR)/protoc-v$(PROTOC_VERSION)
|
|
|
|
PROTOC_GEN_GO_DIR ?= $(PROTOBUF_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION)
|
|
|
|
PROTOGEN_FROSTFS_DIR ?= $(PROTOBUF_DIR)/protogen-$(PROTOGEN_FROSTFS_VERSION)
|
|
|
|
STATICCHECK_DIR ?= $(abspath $(BIN))/staticcheck
|
|
|
|
STATICCHECK_VERSION_DIR ?= $(STATICCHECK_DIR)/$(STATICCHECK_VERSION)
|
2023-08-09 12:53:01 +00:00
|
|
|
|
2024-03-01 08:44:03 +00:00
|
|
|
GOPLS_VERSION ?= v0.15.1
|
|
|
|
GOPLS_DIR ?= $(abspath $(BIN))/gopls
|
|
|
|
GOPLS_VERSION_DIR ?= $(GOPLS_DIR)/$(GOPLS_VERSION)
|
|
|
|
|
2023-12-29 11:16:40 +00:00
|
|
|
FROSTFS_CONTRACTS_PATH=$(abspath ./../frostfs-contract)
|
|
|
|
LOCODE_DB_PATH=$(abspath ./.cache/locode_db)
|
|
|
|
LOCODE_DB_VERSION=v0.4.0
|
|
|
|
|
2023-10-31 13:59:38 +00:00
|
|
|
.PHONY: help all images dep clean fmts fumpt 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:
|
2023-11-08 12:43:54 +00:00
|
|
|
@if [ ! -d "$(PROTOC_DIR)" ] || [ ! -d "$(PROTOC_GEN_GO_DIR)" ] || [ ! -d "$(PROTOGEN_FROSTFS_DIR)" ]; then \
|
|
|
|
make protoc-install; \
|
|
|
|
fi
|
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './bin/*'`; do \
|
2020-07-10 14:17:51 +00:00
|
|
|
echo "⇒ Processing $$f "; \
|
2023-11-08 12:43:54 +00:00
|
|
|
$(PROTOC_DIR)/bin/protoc \
|
|
|
|
--proto_path=.:$(PROTOC_DIR)/include:/usr/local/include \
|
|
|
|
--plugin=protoc-gen-go=$(PROTOC_GEN_GO_DIR)/protoc-gen-go \
|
|
|
|
--plugin=protoc-gen-go-frostfs=$(PROTOGEN_FROSTFS_DIR)/protogen \
|
2022-12-23 17:35:35 +00:00
|
|
|
--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
|
2023-11-08 12:43:54 +00:00
|
|
|
|
|
|
|
protoc-install:
|
|
|
|
@rm -rf $(PROTOBUF_DIR)
|
|
|
|
@mkdir $(PROTOBUF_DIR)
|
|
|
|
@echo "⇒ Installing protoc... "
|
|
|
|
@wget -q -O $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip 'https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-$(PROTOC_OS_VERSION).zip'
|
|
|
|
@unzip -q -o $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip -d $(PROTOC_DIR)
|
|
|
|
@rm $(PROTOBUF_DIR)/protoc-$(PROTOC_VERSION).zip
|
|
|
|
@echo "⇒ Installing protoc-gen-go..."
|
|
|
|
@GOBIN=$(PROTOC_GEN_GO_DIR) go install -v google.golang.org/protobuf/...@$(PROTOC_GEN_GO_VERSION)
|
|
|
|
@echo "⇒ Instaling protogen FrostFS plugin..."
|
|
|
|
@GOBIN=$(PROTOGEN_FROSTFS_DIR) go install -mod=mod -v git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen@$(PROTOGEN_FROSTFS_VERSION)
|
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
|
2023-10-31 13:59:38 +00:00
|
|
|
fmts: fumpt imports
|
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
|
|
|
|
2023-10-31 13:59:38 +00:00
|
|
|
fumpt:
|
|
|
|
@echo "⇒ Processing gofumpt check"
|
|
|
|
@gofumpt -l -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:
|
2023-11-08 12:43:54 +00:00
|
|
|
@rm -rf $(OUTPUT_LINT_DIR)
|
|
|
|
@mkdir $(OUTPUT_LINT_DIR)
|
2023-08-09 12:53:01 +00:00
|
|
|
@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 \
|
2023-11-08 12:43:54 +00:00
|
|
|
make lint-install; \
|
2023-08-11 10:05:16 +00:00
|
|
|
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:
|
2023-11-08 12:43:54 +00:00
|
|
|
@rm -rf $(STATICCHECK_DIR)
|
|
|
|
@mkdir $(STATICCHECK_DIR)
|
|
|
|
@GOBIN=$(STATICCHECK_VERSION_DIR) go install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
|
2023-07-05 08:57:16 +00:00
|
|
|
|
2023-04-03 14:05:10 +00:00
|
|
|
# Run staticcheck
|
2023-07-05 08:57:16 +00:00
|
|
|
staticcheck-run:
|
2023-11-08 12:43:54 +00:00
|
|
|
@if [ ! -d "$(STATICCHECK_VERSION_DIR)" ]; then \
|
|
|
|
make staticcheck-install; \
|
|
|
|
fi
|
|
|
|
@$(STATICCHECK_VERSION_DIR)/staticcheck ./...
|
2023-04-03 14:05:10 +00:00
|
|
|
|
2024-03-01 08:44:03 +00:00
|
|
|
gopls-install:
|
|
|
|
@rm -rf $(GOPLS_DIR)
|
|
|
|
@mkdir $(GOPLS_DIR)
|
|
|
|
@GOBIN=$(GOPLS_VERSION_DIR) go install golang.org/x/tools/gopls@$(GOPLS_VERSION)
|
|
|
|
|
|
|
|
gopls-run:
|
|
|
|
@if [ ! -d "$(GOPLS_VERSION_DIR)" ]; then \
|
|
|
|
make gopls-install; \
|
|
|
|
fi
|
|
|
|
@if [[ $$(find . -type f -name "*.go" -print | xargs $(GOPLS_VERSION_DIR)/gopls check | tee /dev/tty | wc -l) -ne 0 ]]; then \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
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:
|
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
|
2023-12-29 11:16:40 +00:00
|
|
|
|
|
|
|
locode-download:
|
|
|
|
@wget -q -O ./.cache/locode_db.gz 'https://git.frostfs.info/TrueCloudLab/frostfs-locode-db/releases/download/${LOCODE_DB_VERSION}/locode_db.gz'
|
|
|
|
gzip -dfk ./.cache/locode_db.gz
|
|
|
|
|
|
|
|
env-up: all
|
|
|
|
docker compose -f dev/docker-compose.yml up -d
|
|
|
|
@if [ ! -d "$(FROSTFS_CONTRACTS_PATH)" ]; then \
|
|
|
|
echo "Frostfs contracts not found"; exit 1; \
|
|
|
|
fi
|
|
|
|
${BIN}/frostfs-adm --config ./dev/adm/frostfs-adm.yml morph init --contracts ${FROSTFS_CONTRACTS_PATH}
|
|
|
|
${BIN}/frostfs-adm --config ./dev/adm/frostfs-adm.yml morph refill-gas --storage-wallet ./dev/storage/wallet.json --gas 10.0
|
|
|
|
@if [ ! -f "$(LOCODE_DB_PATH)" ]; then \
|
|
|
|
make locode-download; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
env-down:
|
|
|
|
docker compose -f dev/docker-compose.yml down
|
|
|
|
docker volume rm -f frostfs-node_neo-go
|
|
|
|
rm -f ./.cache/.frostfs-ir-state
|
|
|
|
rm -f ./.cache/.frostfs-node-state
|
2024-01-26 14:13:40 +00:00
|
|
|
rm -rf ./.cache/storage
|