-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
195 lines (155 loc) · 5.63 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
PROJECT := arangodb-exporter
ifndef SCRIPTDIR
SCRIPTDIR := $(shell pwd)
endif
ROOTDIR := $(shell cd $(SCRIPTDIR) && pwd)
VERSION := $(shell cat $(ROOTDIR)/VERSION)
VERSION_MAJOR_MINOR_PATCH := $(shell echo $(VERSION) | cut -f 1 -d '+')
VERSION_MAJOR_MINOR := $(shell echo $(VERSION_MAJOR_MINOR_PATCH) | cut -f 1,2 -d '.')
VERSION_MAJOR := $(shell echo $(VERSION_MAJOR_MINOR) | cut -f 1 -d '.')
COMMIT := $(shell git rev-parse --short HEAD)
MAKEFILE := $(ROOTDIR)/Makefile
UBI := registry.access.redhat.com/ubi8/ubi-minimal:8.0
ifndef NODOCKER
DOCKERCLI := $(shell which docker)
GOBUILDLINKTARGET := ../../../..
else
DOCKERCLI :=
GOBUILDLINKTARGET := $(ROOTDIR)
endif
ifndef BUILDDIR
BUILDDIR := $(ROOTDIR)
endif
GOBUILDDIR := $(BUILDDIR)/.gobuild
SRCDIR := $(SCRIPTDIR)
BINDIR := $(BUILDDIR)/bin
VENDORDIR := $(SCRIPTDIR)/vendor
ORGPATH := github.com/arangodb-helper
ORGDIR := $(GOBUILDDIR)/src/$(ORGPATH)
REPONAME := $(PROJECT)
REPODIR := $(ORGDIR)/$(REPONAME)
REPOPATH := $(ORGPATH)/$(REPONAME)
GOPATH := $(GOBUILDDIR)
GOVERSION := 1.10.1-alpine
ifndef DOCKERTAG
DOCKERTAG := dev
endif
DOCKERIMAGE := $(DOCKERNAMESPACE)/arangodb-exporter:$(DOCKERTAG)
RELEASE := $(SRCDIR)/bin/release$(shell go env GOEXE)
GHRELEASE := $(SRCDIR)/bin/github-release$(shell go env GOEXE)
GOX := $(SRCDIR)/bin/gox$(shell go env GOEXE)
GOIMPORTS := $(SRCDIR)/bin/fmt$(shell go env GOEXE)
ADDLICENSE := $(SRCDIR)/bin/addlicense$(shell go env GOEXE)
# Magical rubbish to teach make what commas and spaces are.
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
COMMA := $(EMPTY),$(EMPTY)
ARCHS:=amd64 arm arm64
PLATFORMS:=$(subst $(SPACE),$(COMMA),$(foreach arch,$(ARCHS),linux/$(arch)))
GO_IGNORED:=vendor .gobuild
GO_SOURCES_QUERY := find $(SRCDIR) -name '*.go' -type f $(foreach IGNORED,$(GO_IGNORED),-not -path '$(SRCDIR)/$(IGNORED)/*' )
GO_SOURCES := $(shell $(GO_SOURCES_QUERY) | sort | uniq)
GO_SOURCES_PACKAGES := $(shell $(GO_SOURCES_QUERY) -exec dirname {} \; | sort | uniq)
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
.PHONY: all clean build docker
all: build
clean:
rm -Rf $(BINDIR) $(ROOTDIR)/arangodb-exporter
build: $(GOX)
CGO_ENABLED=0 $(GOX) \
-os="darwin linux windows" \
-arch="$(ARCHS)" \
-osarch="!darwin/arm !darwin/arm64" \
-ldflags="-X main.projectVersion=${VERSION} -X main.projectBuild=${COMMIT}" \
-output="bin/{{.OS}}/{{.Arch}}/arangodb-exporter" \
-tags="netgo" \
github.com/arangodb-helper/arangodb-exporter
.PHONY: check-vars
check-vars:
ifndef DOCKERNAMESPACE
@echo "DOCKERNAMESPACE must be set"
@exit 1
endif
@echo "Using docker namespace: $(DOCKERNAMESPACE)"
$(GOBUILDDIR):
# pass
.PHONY: run-tests
run-tests:
go test $(REPOPATH)
docker-ubi-base: check-vars
docker build --no-cache -t $(DOCKERIMAGE)-base-image-ubi -f Dockerfile.ubi .
docker-ubi: docker-ubi-base build
ifndef LOCAL
for arch in amd64; do \
docker build --build-arg "GOARCH=$$arch" --build-arg "VERSION=$(VERSION_MAJOR_MINOR_PATCH)" -t $(DOCKERIMAGE)-ubi --build-arg "BASE_IMAGE=$(DOCKERIMAGE)-base-image-ubi" -f Dockerfile.scratch . ; \
docker push $(DOCKERIMAGE)-ubi ; \
done
else
for arch in amd64; do \
docker build --build-arg "GOARCH=$$arch" --build-arg "VERSION=$(VERSION_MAJOR_MINOR_PATCH)" -t $(DOCKERIMAGE)-ubi --build-arg "BASE_IMAGE=$(DOCKERIMAGE)-base-image-ubi" -f Dockerfile.scratch . ; \
done
endif
ifndef IGNORE_UBI
docker: docker-ubi
endif
docker: check-vars build
ifndef LOCAL
for arch in $(ARCHS); do \
docker build --build-arg "GOARCH=$$arch" --build-arg "VERSION=$(VERSION_MAJOR_MINOR_PATCH)" -t $(DOCKERIMAGE)-$$arch -f Dockerfile.scratch . ; \
docker push $(DOCKERIMAGE)-$$arch ; \
done
docker tag $(DOCKERIMAGE)-amd64 $(DOCKERIMAGE)
docker push $(DOCKERIMAGE)
else
for arch in $(ARCHS); do \
docker build --build-arg "GOARCH=$$arch" --build-arg "VERSION=$(VERSION_MAJOR_MINOR_PATCH)" -t $(DOCKERIMAGE)-$$arch -f Dockerfile.scratch . ; \
done
endif
$(RELEASE): $(GOBUILDDIR) $(SOURCES) $(GHRELEASE)
go build -o $(RELEASE) $(REPOPATH)/tools/release
$(GHRELEASE): $(GOBUILDDIR)
@go build -mod='' -o "$(GHRELEASE)" github.com/aktau/github-release
github-release: $(GHRELEASE)
$(GOX):
go build -mod='' -o $(GOX) github.com/mitchellh/gox
release-patch: $(RELEASE) $(GHRELEASE)
$(RELEASE) -type=patch
release-minor: $(RELEASE) $(GHRELEASE)
$(RELEASE) -type=minor
release-major: $(RELEASE) $(GHRELEASE)
$(RELEASE) -type=major
## LINT
GOLANGCI_ENABLED=deadcode gocyclo golint varcheck structcheck maligned errcheck \
ineffassign interfacer unconvert goconst \
megacheck
.PHONY: tools
tools: $(ADDLICENSE) $(GOIMPORTS) $(GHRELEASE)
$(ADDLICENSE):
@go build -mod='' -o "$(ADDLICENSE)" github.com/google/addlicense
.PHONY: license
license: $(ADDLICENSE)
@echo ">> Verify license of files"
@$(ADDLICENSE) -f "./LICENSE.BOILERPLATE" $(GO_SOURCES)
.PHONY: license-verify
license-verify: $(ADDLICENSE)
@echo ">> Ensuring license of files"
@$(ADDLICENSE) -f "./LICENSE.BOILERPLATE" -check $(GO_SOURCES)
$(GOIMPORTS):
@go build -mod='' -o "$(GOIMPORTS)" golang.org/x/tools/cmd/goimports
.PHONY: fmt
fmt: $(GOIMPORTS)
@echo ">> Ensuring style of files"
@$(GOIMPORTS) -w $(GO_SOURCES)
.PHONY: fmt-verify
fmt-verify: license-verify $(GOIMPORTS)
@echo ">> Verify files style"
@if [ X"$$($(GOIMPORTS) -l $(GO_SOURCES) | wc -l)" != X"0" ]; then echo ">> Style errors"; $(GOIMPORTS) -l $(GO_SOURCES); exit 1; fi
.PHONY: linter
linter: fmt
@golangci-lint run --no-config --issues-exit-code=1 --deadline=30m --disable-all \
$(foreach MODE,$(GOLANGCI_ENABLED),--enable $(MODE) ) \
--exclude-use-default=false \
$(GO_SOURCES_PACKAGES)
.PHONY: vendor
vendor:
@go mod vendor