2021-05-13 19:06:02 +00:00
|
|
|
#!/usr/bin/make -f
|
2021-02-08 09:45:18 +00:00
|
|
|
|
2021-05-19 10:22:39 +00:00
|
|
|
# Common variables
|
2021-05-13 19:06:02 +00:00
|
|
|
REPO ?= $(shell go list -m)
|
2022-09-05 09:06:18 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --dirty --match "v*" --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
|
2024-07-17 06:08:12 +00:00
|
|
|
GO_VERSION ?= 1.22
|
2024-08-22 16:13:52 +00:00
|
|
|
LINT_VERSION ?= 1.60.1
|
|
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.6
|
2021-05-19 10:22:39 +00:00
|
|
|
BINDIR = bin
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2023-04-07 14:28:21 +00:00
|
|
|
METRICS_DUMP_OUT ?= ./metrics-dump.json
|
|
|
|
|
2021-05-20 09:52:58 +00:00
|
|
|
# Binaries to build
|
2022-12-15 14:08:25 +00:00
|
|
|
CMDS = $(addprefix frostfs-, $(notdir $(wildcard cmd/*)))
|
2021-05-20 09:52:58 +00:00
|
|
|
BINS = $(addprefix $(BINDIR)/, $(CMDS))
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2024-07-12 12:31:43 +00:00
|
|
|
GOFLAGS ?=
|
|
|
|
|
2021-05-19 10:22:39 +00:00
|
|
|
# Variables for docker
|
2021-05-24 11:24:01 +00:00
|
|
|
REPO_BASENAME = $(shell basename `go list -m`)
|
2022-12-15 14:08:25 +00:00
|
|
|
HUB_IMAGE ?= "truecloudlab/$(REPO_BASENAME)"
|
2021-05-19 10:22:39 +00:00
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
|
2023-08-25 14:16:24 +00:00
|
|
|
OUTPUT_LINT_DIR ?= $(shell pwd)/bin
|
|
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
|
|
|
TMP_DIR := .cache
|
|
|
|
|
2024-06-17 11:36:53 +00:00
|
|
|
# Variables for fuzzing
|
|
|
|
FUZZ_NGFUZZ_DIR ?= ""
|
|
|
|
FUZZ_TIMEOUT ?= 30
|
|
|
|
FUZZ_FUNCTIONS ?= "all"
|
|
|
|
FUZZ_AUX ?= ""
|
|
|
|
|
2023-03-22 14:16:05 +00:00
|
|
|
.PHONY: all $(BINS) $(BINDIR) dep docker/ test cover format image image-push dirty-image lint docker/lint pre-commit unpre-commit version clean protoc
|
2021-05-13 19:06:02 +00:00
|
|
|
|
2022-11-01 07:27:24 +00:00
|
|
|
# .deb package versioning
|
|
|
|
OS_RELEASE = $(shell lsb_release -cs)
|
|
|
|
PKG_VERSION ?= $(shell echo $(VERSION) | sed "s/^v//" | \
|
|
|
|
sed -E "s/(.*)-(g[a-fA-F0-9]{6,8})(.*)/\1\3~\2/" | \
|
|
|
|
sed "s/-/~/")-${OS_RELEASE}
|
2023-03-22 14:16:05 +00:00
|
|
|
.PHONY: debpackage debclean
|
2022-11-01 07:27:24 +00:00
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
# Make all binaries
|
2021-05-20 09:52:58 +00:00
|
|
|
all: $(BINS)
|
2021-05-13 19:06:02 +00:00
|
|
|
|
2023-06-09 06:34:36 +00:00
|
|
|
$(BINS): $(BINDIR) dep
|
2021-05-19 09:18:20 +00:00
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
2024-07-12 12:31:43 +00:00
|
|
|
GOFLAGS=$(GOFLAGS) \
|
2021-05-19 09:18:20 +00:00
|
|
|
go build -v -trimpath \
|
2021-05-20 12:41:32 +00:00
|
|
|
-ldflags "-X $(REPO)/internal/version.Version=$(VERSION)" \
|
2022-12-15 14:08:25 +00:00
|
|
|
-o $@ ./cmd/$(subst frostfs-,,$(notdir $@))
|
2021-05-19 09:18:20 +00:00
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
$(BINDIR):
|
|
|
|
@echo "⇒ Ensure dir: $@"
|
|
|
|
@mkdir -p $@
|
|
|
|
|
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Download requirements: "
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
go mod download && echo OK
|
|
|
|
@printf "⇒ Tidy requirements: "
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
go mod tidy -v && echo OK
|
|
|
|
|
2022-10-16 15:14:02 +00:00
|
|
|
# Run `make %` in Golang container, for more information run `make help.docker/%`
|
2022-06-15 10:30:55 +00:00
|
|
|
docker/%:
|
|
|
|
$(if $(filter $*,all $(BINS)), \
|
|
|
|
@echo "=> Running 'make $*' in clean Docker environment" && \
|
|
|
|
docker run --rm -t \
|
|
|
|
-v `pwd`:/src \
|
|
|
|
-w /src \
|
|
|
|
-u `stat -c "%u:%g" .` \
|
|
|
|
--env HOME=/src \
|
2024-07-12 12:31:43 +00:00
|
|
|
golang:$(GO_VERSION) make GOFLAGS=$(GOFLAGS) $*,\
|
2022-06-15 10:30:55 +00:00
|
|
|
@echo "supported docker targets: all $(BINS) lint")
|
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
# Run tests
|
|
|
|
test:
|
|
|
|
@go test ./... -cover
|
|
|
|
|
|
|
|
# Run tests with race detection and produce coverage output
|
|
|
|
cover:
|
|
|
|
@go test -v -race ./... -coverprofile=coverage.txt -covermode=atomic
|
|
|
|
@go tool cover -html=coverage.txt -o coverage.html
|
2020-07-14 11:33:52 +00:00
|
|
|
|
2024-06-17 11:36:53 +00:00
|
|
|
# Run fuzzing
|
|
|
|
CLANG := $(shell which clang-17 2>/dev/null)
|
|
|
|
.PHONY: check-clang all
|
|
|
|
check-clang:
|
|
|
|
ifeq ($(CLANG),)
|
|
|
|
@echo "clang-17 is not installed. Please install it before proceeding - https://apt.llvm.org/llvm.sh "
|
|
|
|
@exit 1
|
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: check-ngfuzz all
|
|
|
|
check-ngfuzz:
|
|
|
|
@if [ -z "$(FUZZ_NGFUZZ_DIR)" ]; then \
|
|
|
|
echo "Please set a variable FUZZ_NGFUZZ_DIR to specify path to the ngfuzz"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: install-fuzzing-deps
|
|
|
|
install-fuzzing-deps: check-clang check-ngfuzz
|
|
|
|
|
|
|
|
.PHONY: fuzz
|
|
|
|
fuzz: install-fuzzing-deps
|
|
|
|
@START_PATH=$$(pwd); \
|
|
|
|
ROOT_PATH=$$(realpath --relative-to=$(FUZZ_NGFUZZ_DIR) $$START_PATH) ; \
|
|
|
|
cd $(FUZZ_NGFUZZ_DIR) && \
|
|
|
|
./ngfuzz -clean && \
|
|
|
|
./ngfuzz -fuzz $(FUZZ_FUNCTIONS) -rootdir $$ROOT_PATH -timeout $(FUZZ_TIMEOUT) $(FUZZ_AUX) && \
|
|
|
|
./ngfuzz -report
|
|
|
|
|
2020-07-03 15:08:57 +00:00
|
|
|
# Reformat code
|
|
|
|
format:
|
2021-05-13 19:06:02 +00:00
|
|
|
@echo "⇒ Processing gofmt check"
|
|
|
|
@gofmt -s -w ./
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
# Build clean Docker image
|
2022-07-05 11:19:09 +00:00
|
|
|
image:
|
2022-12-15 14:08:25 +00:00
|
|
|
@echo "⇒ Build FrostFS S3 Gateway docker image "
|
2020-07-03 15:08:57 +00:00
|
|
|
@docker build \
|
2021-05-13 19:06:02 +00:00
|
|
|
--build-arg REPO=$(REPO) \
|
|
|
|
--build-arg VERSION=$(VERSION) \
|
2024-07-12 12:31:43 +00:00
|
|
|
--build-arg GOFLAGS=$(GOFLAGS) \
|
2021-05-13 19:06:02 +00:00
|
|
|
--rm \
|
2022-07-05 11:19:09 +00:00
|
|
|
-f .docker/Dockerfile \
|
2021-05-13 19:06:02 +00:00
|
|
|
-t $(HUB_IMAGE):$(HUB_TAG) .
|
|
|
|
|
|
|
|
# Push Docker image to the hub
|
|
|
|
image-push:
|
|
|
|
@echo "⇒ Publish image"
|
|
|
|
@docker push $(HUB_IMAGE):$(HUB_TAG)
|
|
|
|
|
|
|
|
# Build dirty Docker image
|
|
|
|
dirty-image:
|
2022-12-15 14:08:25 +00:00
|
|
|
@echo "⇒ Build FrostFS S3 Gateway dirty docker image "
|
2021-05-13 19:06:02 +00:00
|
|
|
@docker build \
|
|
|
|
--build-arg REPO=$(REPO) \
|
|
|
|
--build-arg VERSION=$(VERSION) \
|
|
|
|
--rm \
|
2022-07-05 11:19:09 +00:00
|
|
|
-f .docker/Dockerfile.dirty \
|
2021-05-13 19:06:02 +00:00
|
|
|
-t $(HUB_IMAGE)-dirty:$(HUB_TAG) .
|
|
|
|
|
2023-08-25 14:16:24 +00:00
|
|
|
# Install linters
|
|
|
|
lint-install:
|
|
|
|
@mkdir -p $(TMP_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
|
|
|
|
@@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
|
|
|
|
@rm -rf $(TMP_DIR)/linters
|
|
|
|
@rmdir $(TMP_DIR) 2>/dev/null || true
|
|
|
|
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
|
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
# Run linters
|
|
|
|
lint:
|
2023-08-25 14:16:24 +00:00
|
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
|
|
echo "Run make lint-install"; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
$(LINT_DIR)/golangci-lint --timeout=5m run
|
2021-05-13 19:06:02 +00:00
|
|
|
|
|
|
|
# Run linters in Docker
|
|
|
|
docker/lint:
|
|
|
|
docker run --rm -it \
|
|
|
|
-v `pwd`:/src \
|
|
|
|
-u `stat -c "%u:%g" .` \
|
|
|
|
--env HOME=/src \
|
2022-06-15 11:17:01 +00:00
|
|
|
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
2021-05-13 19:06:02 +00:00
|
|
|
|
2023-03-22 14:16:05 +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
|
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
# Show current version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
2022-10-16 15:14:02 +00:00
|
|
|
# Clean up files
|
2021-05-13 19:06:02 +00:00
|
|
|
clean:
|
2022-07-06 06:03:29 +00:00
|
|
|
rm -rf .cache
|
2021-05-13 19:06:02 +00:00
|
|
|
rm -rf $(BINDIR)
|
2021-06-14 13:20:49 +00:00
|
|
|
|
2022-10-16 15:14:02 +00:00
|
|
|
# Generate code from .proto files
|
2021-06-14 13:20:49 +00:00
|
|
|
protoc:
|
2023-10-17 14:49:57 +00:00
|
|
|
# Install specific version for protobuf lib
|
|
|
|
@GOBIN=$(abspath $(BINDIR)) go install -mod=mod -v git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/util/protogen
|
2021-06-14 13:20:49 +00:00
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
|
|
|
|
echo "⇒ Processing $$f "; \
|
|
|
|
protoc \
|
2023-10-17 14:49:57 +00:00
|
|
|
--go_out=paths=source_relative:. \
|
|
|
|
--plugin=protoc-gen-go-frostfs=$(BINDIR)/protogen \
|
|
|
|
--go-frostfs_out=. --go-frostfs_opt=paths=source_relative \
|
|
|
|
--go-grpc_opt=require_unimplemented_servers=false \
|
|
|
|
--go-grpc_out=. --go-grpc_opt=paths=source_relative $$f; \
|
2021-06-14 13:20:49 +00:00
|
|
|
done
|
|
|
|
rm -rf vendor
|
2022-10-16 15:14:02 +00:00
|
|
|
|
2022-11-01 07:27:24 +00:00
|
|
|
# Package for Debian
|
|
|
|
debpackage:
|
2022-12-15 14:08:25 +00:00
|
|
|
dch --package frostfs-s3-gw \
|
2022-11-01 07:27:24 +00:00
|
|
|
--controlmaint \
|
|
|
|
--newversion $(PKG_VERSION) \
|
|
|
|
--distribution $(OS_RELEASE) \
|
|
|
|
"Please see CHANGELOG.md for code changes for $(VERSION)"
|
|
|
|
dpkg-buildpackage --no-sign -b
|
|
|
|
|
|
|
|
debclean:
|
2023-03-22 14:16:05 +00:00
|
|
|
dh clean
|
2022-11-01 07:27:24 +00:00
|
|
|
|
2023-04-07 14:28:21 +00:00
|
|
|
# Dump metrics (use METRICS_DUMP_OUT variable to override default out file './metrics-dump.json')
|
|
|
|
.PHONY: dump-metrics
|
|
|
|
dump-metrics:
|
|
|
|
@go test ./metrics -run TestDescribeAll --tags=dump_metrics --out=$(abspath $(METRICS_DUMP_OUT))
|
|
|
|
|
2022-10-16 15:14:02 +00:00
|
|
|
include help.mk
|