-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMakefile
132 lines (108 loc) · 3.03 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/make -f
REPO ?= "$(shell go list -m)"
VERSION ?= "$(shell git describe --tags --match "v*" --dirty --always --abbrev=8 | sed 's/^v//' 2>/dev/null || cat VERSION 2>/dev/null || echo "develop")"
BUILD_OS ?= linux
BUILD_ARCH ?= amd64
GO_VERSION ?= 1.23
HUB_IMAGE ?= nspccdev/neofs-rest-gw
HUB_TAG ?= "$(shell echo ${VERSION} | sed 's/^v//')"
UNAME = "$(shell uname)/$(shell uname -m)"
ifeq ($(UNAME), "Darwin/arm64")
BUILD_OS=darwin
BUILD_ARCH=arm64
endif
ifeq ($(UNAME), "Darwin/x86_64")
BUILD_OS=darwin
endif
# List of binaries to build. For now just one.
BINDIR = bin
DIRS = "$(BINDIR)"
BINS = "$(BINDIR)/neofs-rest-gw"
.PHONY: help all clean format test cover lint docker/lint
# Make all binaries
all: generate-server $(BINS)
$(BINS): $(DIRS)
@echo "⇒ Build $@"
CGO_ENABLED=0 \
GOOS=$(BUILD_OS) \
GOARCH=$(BUILD_ARCH) \
go build -v -trimpath \
-ldflags "-X main.Version=$(VERSION)" \
-o $@ ./cmd/neofs-rest-gw
$(DIRS):
@echo "⇒ Ensure dir: $@"
@mkdir -p $@
# Install generator
install-generator:
@go install github.com/deepmap/oapi-codegen/v2/cmd/[email protected]
# Generate server by openapi spec
generate-server: install-generator
@oapi-codegen --config=./oapi-generator.cfg.yaml ./spec/rest.yaml
# 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
# Reformat code
format:
@echo "⇒ Processing gofmt check"
@gofmt -s -w ./
@echo "⇒ Processing goimports check"
@goimports -w ./
# Build clean Docker image
image:
@echo "⇒ Build NeoFS REST Gateway docker image "
@docker build \
--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
image-dirty:
@echo "⇒ Build NeoFS REST Gateway dirty docker image "
@docker build \
--build-arg REPO=$(REPO) \
--build-arg VERSION=$(VERSION) \
--rm \
-f Dockerfile.dirty \
-t $(HUB_IMAGE)-dirty:$(HUB_TAG) .
# Fetch linter configuration.
.golangci.yml:
wget -O $@ https://github.com/nspcc-dev/.github/raw/master/.golangci.yml
# Run linters
lint: .golangci.yml
@golangci-lint --timeout=5m run
# Make all binaries in clean docker environment
docker/all:
@echo "=> Running 'make all' in clean Docker environment" && \
docker run --rm -t \
-v `pwd`:/src \
-w /src \
-u `stat -c "%u:%g" .` \
--env HOME=/src \
--env BUILD_OS=$(BUILD_OS) \
--env BUILD_ARCH=$(BUILD_ARCH) \
golang:$(GO_VERSION) make all
# Print 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 .cache
rm -rf $(BINDIR)