Roman Ognev
4bc3159f26
Some checks failed
/ DCO (pull_request) Failing after 1m15s
/ Builds (1.21) (pull_request) Successful in 1m20s
/ Builds (1.22) (pull_request) Successful in 1m25s
/ Vulncheck (pull_request) Successful in 1m24s
/ Lint (pull_request) Successful in 2m38s
/ Tests (1.21) (pull_request) Successful in 1m35s
/ Tests (1.22) (pull_request) Successful in 1m34s
212 lines
5.6 KiB
Makefile
Executable file
212 lines
5.6 KiB
Makefile
Executable file
#!/usr/bin/make -f
|
|
|
|
REPO ?= $(shell go list -m)
|
|
VERSION ?= $(shell git describe --tags --match "v*" --dirty --always --abbrev=8 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
|
|
GO_VERSION ?= 1.22
|
|
LINT_VERSION ?= 1.54.0
|
|
TRUECLOUDLAB_LINT_VERSION ?= 0.0.2
|
|
BUILD ?= $(shell date -u --iso=seconds)
|
|
|
|
HUB_IMAGE ?= truecloudlab/frostfs-http-gw
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
METRICS_DUMP_OUT ?= ./metrics-dump.json
|
|
|
|
OUTPUT_LINT_DIR ?= $(shell pwd)/bin
|
|
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
|
|
TMP_DIR := .cache
|
|
|
|
# List of binaries to build. For now just one.
|
|
BINDIR = bin
|
|
CMDS = $(addprefix frostfs-, $(notdir $(wildcard cmd/*)))
|
|
BINS = $(addprefix $(BINDIR)/, $(CMDS))
|
|
|
|
.PHONY: all $(BINS) $(DIRS) dep docker/ test cover fmt image image-push dirty-image lint docker/lint pre-commit unpre-commit version clean
|
|
|
|
# .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}
|
|
.PHONY: debpackage debclean
|
|
|
|
FUZZING_DIR = $(shell pwd)/tests/fuzzing/files
|
|
NGFUZZ_REPO = https://b.yadro.com/scm/sdl/ngfuzz.git
|
|
NGFUZZ_BRANCH = feature/go-118-fuzz-build
|
|
GO_118_FUZZ_BUILD_REPO = b.yadro.com/obj/go-118-fuzz-build
|
|
|
|
FUZZ_TIMEOUT ?= 30
|
|
FUZZ_FUNCTIONS ?= "all"
|
|
FUZZ_AUX ?= ""
|
|
|
|
# Make all binaries
|
|
all: $(BINS)
|
|
$(BINS): $(DIRS) dep
|
|
@echo "⇒ Build $@"
|
|
CGO_ENABLED=0 \
|
|
go build -v -trimpath \
|
|
-ldflags "-X main.Version=$(VERSION)" \
|
|
-o $@ ./cmd/$(subst frostfs-,,$(notdir $@))
|
|
|
|
$(DIRS):
|
|
@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
|
|
|
|
# Run `make %` in Golang container, for more information run `make help.docker/%`
|
|
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 \
|
|
golang:$(GO_VERSION) make $*,\
|
|
@echo "supported docker targets: all $(BINS) lint")
|
|
|
|
# Run tests
|
|
test:
|
|
@go test ./... -cover
|
|
|
|
# Run integration tests
|
|
.PHONY: integration-test
|
|
integration-test:
|
|
@go test ./... -cover --tags=integration
|
|
|
|
# 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
|
|
|
|
CLANG := $(shell which clang-17 2>/dev/null)
|
|
|
|
# Run fuzzing tests
|
|
.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: install-ngfuzz
|
|
install-ngfuzz:
|
|
ifeq (,$(wildcard $(FUZZING_DIR)/ngfuzz))
|
|
@rm -rf $(FUZZING_DIR)/ngfuzz
|
|
@git clone -b $(NGFUZZ_BRANCH) $(NGFUZZ_REPO) $(FUZZING_DIR)/ngfuzz
|
|
@cd $(FUZZING_DIR)/ngfuzz && make
|
|
endif
|
|
|
|
.PHONY: install-fuzzing-deps
|
|
install-fuzzing-deps: check-clang install-ngfuzz
|
|
ifeq (,$(wildcard $(FUZZING_DIR)/go-118-fuzz-build))
|
|
GOBIN=$(FUZZING_DIR) go install $(GO_118_FUZZ_BUILD_REPO)
|
|
endif
|
|
|
|
.PHONY: fuzz
|
|
fuzz: install-fuzzing-deps
|
|
cd $(FUZZING_DIR)/ngfuzz && \
|
|
./ngfuzz -fuzz $(FUZZ_FUNCTIONS) -rootdir ../../../.. -timeout $(FUZZ_TIMEOUT) $(FUZZ_AUX) && \
|
|
./ngfuzz -report
|
|
|
|
# Reformat code
|
|
fmt:
|
|
@echo "⇒ Processing gofmt check"
|
|
@gofmt -s -w ./
|
|
|
|
# Build clean Docker image
|
|
image:
|
|
@echo "⇒ Build FrostFS HTTP Gateway docker image "
|
|
@docker build \
|
|
--build-arg REPO=$(REPO) \
|
|
--build-arg VERSION=$(VERSION) \
|
|
--rm \
|
|
-f .docker/Dockerfile \
|
|
-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:
|
|
@echo "⇒ Build FrostFS HTTP Gateway dirty docker image "
|
|
@docker build \
|
|
--build-arg REPO=$(REPO) \
|
|
--build-arg VERSION=$(VERSION) \
|
|
--rm \
|
|
-f .docker/Dockerfile.dirty \
|
|
-t $(HUB_IMAGE)-dirty:$(HUB_TAG) .
|
|
|
|
# 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)
|
|
|
|
# Run linters
|
|
lint:
|
|
@if [ ! -d "$(LINT_DIR)" ]; then \
|
|
echo "Run make lint-install"; \
|
|
exit 1; \
|
|
fi
|
|
$(LINT_DIR)/golangci-lint --timeout=5m run
|
|
|
|
# Run linters in Docker
|
|
docker/lint:
|
|
docker run --rm -it \
|
|
-v `pwd`:/src \
|
|
-u `stat -c "%u:%g" .` \
|
|
--env HOME=/src \
|
|
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
|
|
|
# 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
|
|
|
|
# Print version
|
|
version:
|
|
@echo $(VERSION)
|
|
|
|
# Clean up
|
|
clean:
|
|
rm -rf vendor
|
|
rm -rf $(BINDIR)
|
|
rm -rf $(FUZZING_DIR)
|
|
|
|
# Package for Debian
|
|
debpackage:
|
|
dch --package frostfs-http-gw \
|
|
--controlmaint \
|
|
--newversion $(PKG_VERSION) \
|
|
--distribution $(OS_RELEASE) \
|
|
"Please see CHANGELOG.md for code changes for $(VERSION)"
|
|
dpkg-buildpackage --no-sign -b
|
|
|
|
debclean:
|
|
dh clean
|
|
|
|
# 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))
|
|
|
|
|
|
include help.mk
|