2021-04-09 15:29:18 +00:00
|
|
|
#!/usr/bin/make -f
|
2021-02-05 13:51:20 +00:00
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
REPO ?= $(shell go list -m)
|
|
|
|
VERSION ?= $(shell git describe --tags --dirty --always)
|
2022-06-07 16:58:33 +00:00
|
|
|
GO_VERSION ?= 1.17
|
2022-06-07 17:10:23 +00:00
|
|
|
LINT_VERSION ?= 1.46.2
|
2021-04-09 15:29:18 +00:00
|
|
|
BUILD ?= $(shell date -u --iso=seconds)
|
2019-11-06 12:33:46 +00:00
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
HUB_IMAGE ?= nspccdev/neofs-http-gw
|
|
|
|
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
|
2020-02-25 15:38:47 +00:00
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
# List of binaries to build. For now just one.
|
|
|
|
BINDIR = bin
|
|
|
|
DIRS = $(BINDIR)
|
2022-06-07 16:58:33 +00:00
|
|
|
BINS = $(BINDIR)/neofs-http-gw
|
2019-11-06 12:33:46 +00:00
|
|
|
|
2022-06-07 19:05:57 +00:00
|
|
|
.PHONY: all docker/all $(BINS) $(DIRS) docker/$(BINS) dep test cover fmt image image-push dirty-image lint docker/lint version clean
|
2019-11-06 12:33:46 +00:00
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
# Make all binaries
|
|
|
|
all: $(BINS)
|
2021-02-05 13:51:20 +00:00
|
|
|
|
2022-06-07 19:05:57 +00:00
|
|
|
docker/all:
|
|
|
|
@echo "=> Building binary using clean Docker environment"
|
|
|
|
@docker run --rm -t \
|
|
|
|
-v `pwd`:/src \
|
|
|
|
-w /src \
|
|
|
|
-u "$$(id -u):$$(id -g)" \
|
|
|
|
--env HOME=/src \
|
|
|
|
golang:$(GO_VERSION) make all
|
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
$(BINS): $(DIRS) dep
|
|
|
|
@echo "⇒ Build $@"
|
|
|
|
CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
go build -v -trimpath \
|
2021-05-25 10:19:40 +00:00
|
|
|
-ldflags "-X main.Version=$(VERSION)" \
|
2021-04-09 15:29:18 +00:00
|
|
|
-o $@ ./
|
|
|
|
|
|
|
|
$(DIRS):
|
|
|
|
@echo "⇒ Ensure dir: $@"
|
|
|
|
@mkdir -p $@
|
|
|
|
|
2022-06-07 16:58:33 +00:00
|
|
|
docker/$(BINS):
|
|
|
|
@echo "=> Building binary using clean Docker environment"
|
|
|
|
@docker run --rm -t \
|
|
|
|
-v `pwd`:/src \
|
|
|
|
-w /src \
|
|
|
|
-u "$$(id -u):$$(id -g)" \
|
|
|
|
--env HOME=/src \
|
|
|
|
golang:$(GO_VERSION) make $(BINS)
|
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
# Pull go dependencies
|
|
|
|
dep:
|
|
|
|
@printf "⇒ Download requirements: "
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
go mod download && echo OK
|
|
|
|
@printf "⇒ Tidy requirements: "
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
GO111MODULE=on \
|
|
|
|
go mod tidy -v && echo OK
|
|
|
|
|
2021-04-30 15:58:26 +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
|
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
# Reformat code
|
|
|
|
fmt:
|
|
|
|
@echo "⇒ Processing gofmt check"
|
|
|
|
@GO111MODULE=on gofmt -s -w ./
|
|
|
|
|
|
|
|
# Build clean Docker image
|
|
|
|
image:
|
|
|
|
@echo "⇒ Build NeoFS HTTP Gateway docker image "
|
|
|
|
@docker build \
|
|
|
|
--build-arg REPO=$(REPO) \
|
|
|
|
--build-arg VERSION=$(VERSION) \
|
|
|
|
--rm \
|
|
|
|
-f Dockerfile \
|
|
|
|
-t $(HUB_IMAGE):$(HUB_TAG) .
|
|
|
|
|
2021-04-30 15:53:20 +00:00
|
|
|
# Push Docker image to the hub
|
|
|
|
image-push:
|
|
|
|
@echo "⇒ Publish image"
|
|
|
|
@docker push $(HUB_IMAGE):$(HUB_TAG)
|
|
|
|
|
2021-04-09 15:29:18 +00:00
|
|
|
# Build dirty Docker image
|
|
|
|
dirty-image:
|
|
|
|
@echo "⇒ Build NeoFS HTTP Gateway dirty docker image "
|
2019-11-06 12:33:46 +00:00
|
|
|
@docker build \
|
2021-04-09 15:29:18 +00:00
|
|
|
--build-arg REPO=$(REPO) \
|
2020-02-28 16:50:54 +00:00
|
|
|
--build-arg VERSION=$(VERSION) \
|
2021-04-09 15:29:18 +00:00
|
|
|
--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 \
|
2022-06-07 17:10:23 +00:00
|
|
|
golangci/golangci-lint:v$(LINT_VERSION) bash -c 'cd /src/ && make lint'
|
2021-04-09 15:29:18 +00:00
|
|
|
|
|
|
|
# Print version
|
|
|
|
version:
|
|
|
|
@echo $(VERSION)
|
|
|
|
|
|
|
|
# Clean up
|
|
|
|
clean:
|
|
|
|
rm -rf vendor
|
|
|
|
rm -rf $(BINDIR)
|