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-07-05 11:19:09 +00:00
|
|
|
VERSION ?= $(shell git describe --tags --dirty --always 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")
|
2022-06-15 10:30:55 +00:00
|
|
|
GO_VERSION ?= 1.17
|
2022-06-15 11:17:01 +00:00
|
|
|
LINT_VERSION ?= 1.46.2
|
2021-05-19 10:22:39 +00:00
|
|
|
BINDIR = bin
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2021-05-20 09:52:58 +00:00
|
|
|
# Binaries to build
|
|
|
|
CMDS = $(addprefix neofs-, $(notdir $(wildcard cmd/*)))
|
|
|
|
BINS = $(addprefix $(BINDIR)/, $(CMDS))
|
2020-07-03 15:08:57 +00:00
|
|
|
|
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`)
|
|
|
|
HUB_IMAGE ?= "nspccdev/$(REPO_BASENAME)"
|
2021-05-19 10:22:39 +00:00
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
|
2022-06-15 11:17:01 +00:00
|
|
|
.PHONY: all $(BINS) $(BINDIR) dep docker/ test cover format image image-push dirty-image lint docker/lint version clean protoc
|
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
|
|
|
|
2021-05-20 09:52:58 +00:00
|
|
|
$(BINS): $(BINDIR) dep
|
2021-05-19 09:18:20 +00:00
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go build -v -trimpath \
|
2021-05-20 12:41:32 +00:00
|
|
|
-ldflags "-X $(REPO)/internal/version.Version=$(VERSION)" \
|
2021-05-20 09:52:58 +00:00
|
|
|
-o $@ ./cmd/$(subst neofs-,,$(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-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 \
|
|
|
|
golang:$(GO_VERSION) make $*,\
|
|
|
|
@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
|
|
|
|
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:
|
2021-05-13 19:06:02 +00:00
|
|
|
@echo "⇒ Build NeoFS 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) \
|
|
|
|
--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:
|
|
|
|
@echo "⇒ Build NeoFS S3 Gateway dirty docker image "
|
|
|
|
@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) .
|
|
|
|
|
|
|
|
# Run linters
|
|
|
|
lint:
|
|
|
|
@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 \
|
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
|
|
|
|
|
|
|
# Show current version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
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
|
|
|
|
|
|
|
protoc:
|
|
|
|
# Protoc generate
|
|
|
|
@for f in `find . -type f -name '*.proto' -not -path './vendor/*'`; do \
|
|
|
|
echo "⇒ Processing $$f "; \
|
|
|
|
protoc \
|
|
|
|
--go_out=paths=source_relative:. $$f; \
|
|
|
|
done
|
|
|
|
rm -rf vendor
|