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)
|
2020-07-14 11:33:52 +00:00
|
|
|
VERSION ?= "$(shell git describe --tags 2>/dev/null || git rev-parse --short HEAD | sed 's/^v//')"
|
2021-05-19 10:22:39 +00:00
|
|
|
BINDIR = bin
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2021-05-19 16:27:02 +00:00
|
|
|
# s3 gw variables
|
2021-05-13 19:06:02 +00:00
|
|
|
BIN_NAME=neofs-s3-gw
|
|
|
|
BIN = "$(BINDIR)/$(BIN_NAME)"
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2021-05-19 10:22:39 +00:00
|
|
|
# Variables for docker
|
|
|
|
HUB_IMAGE ?= "nspccdev/$(BIN_NAME)"
|
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
|
|
|
|
2021-05-19 16:27:02 +00:00
|
|
|
# Authmate variables
|
2021-05-19 10:22:39 +00:00
|
|
|
AUTHMATE_BIN_NAME=neofs-authmate
|
2021-05-19 09:18:20 +00:00
|
|
|
AUTHMATE_BIN = "$(BINDIR)/$(AUTHMATE_BIN_NAME)"
|
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
.PHONY: help all dep clean format test cover lint docker/lint image-push image dirty-image
|
|
|
|
|
|
|
|
# Make all binaries
|
2021-05-19 09:18:20 +00:00
|
|
|
all: $(BIN) $(AUTHMATE_BIN)
|
2021-05-13 19:06:02 +00:00
|
|
|
|
|
|
|
$(BIN): $(BINDIR) dep
|
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go build -v -trimpath \
|
|
|
|
-ldflags "-X main.Version=$(VERSION)" \
|
|
|
|
-o $@ ./cmd/gate
|
|
|
|
|
2021-05-19 09:18:20 +00:00
|
|
|
$(AUTHMATE_BIN): $(BINDIR) dep
|
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
go build -v -trimpath \
|
|
|
|
-ldflags "-X main.Version=$(VERSION)" \
|
|
|
|
-o $@ ./cmd/authmate
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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 ./
|
|
|
|
@echo "⇒ Processing goimports check"
|
|
|
|
@goimports -w ./
|
2020-07-03 15:08:57 +00:00
|
|
|
|
2021-05-13 19:06:02 +00:00
|
|
|
# Build clean Docker image
|
|
|
|
image:
|
|
|
|
@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 \
|
|
|
|
-f 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 NeoFS S3 Gateway dirty docker image "
|
|
|
|
@docker build \
|
|
|
|
--build-arg REPO=$(REPO) \
|
|
|
|
--build-arg VERSION=$(VERSION) \
|
|
|
|
--rm \
|
|
|
|
-f Dockerfile.dirty \
|
|
|
|
-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 \
|
|
|
|
golangci/golangci-lint:v1.40 bash -c 'cd /src/ && make lint'
|
|
|
|
|
|
|
|
# Show current version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Show this help prompt
|
|
|
|
help:
|
|
|
|
@echo ' Usage:'
|
|
|
|
@echo ''
|
|
|
|
@echo ' make <target>'
|
|
|
|
@echo ''
|
|
|
|
@echo ' Targets:'
|
|
|
|
@echo ''
|
|
|
|
@awk '/^#/{ comment = substr($$0,3) } comment && /^[a-zA-Z][a-zA-Z0-9_-]+ ?:/{ print " ", $$1, comment }' $(MAKEFILE_LIST) | column -t -s ':' | grep -v 'IGNORE' | sort -u
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
clean:
|
|
|
|
rm -rf $(BINDIR)
|