forked from prymitive/karma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (118 loc) · 4.01 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
NAME := karma
VERSION := $(shell git describe --tags --always --dirty='-dev')
# Alertmanager instance used when running locally, points to mock data
MOCK_PATH := $(CURDIR)/internal/mock/0.15.3
ALERTMANAGER_URI := "file://$(MOCK_PATH)"
# Listen port when running locally
PORT := 8080
# define a recursive wildcard function, we'll need it to find deeply nested
# sources in the ui directory
# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
SOURCES := $(wildcard *.go) $(wildcard */*.go) $(wildcard */*/*.go)
ASSET_SOURCES := $(call rwildcard, ui/public ui/src, *)
GO_BINDATA_MODE := prod
ifdef DEBUG
GO_BINDATA_MODE = debug
endif
.DEFAULT_GOAL := $(NAME)
.build/deps-build-go.ok:
@mkdir -p .build
GO111MODULE=on go install github.com/go-bindata/go-bindata/...
GO111MODULE=on go install github.com/elazarl/go-bindata-assetfs/...
touch $@
.build/deps-lint-go.ok:
@mkdir -p .build
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
touch $@
.build/deps-build-node.ok: ui/package.json ui/yarn.lock
@mkdir -p .build
cd ui && yarn install
touch $@
.build/artifacts-bindata_assetfs.%:
@mkdir -p .build
rm -f .build/artifacts-bindata_assetfs.*
touch $@
.build/artifacts-ui.ok: .build/deps-build-node.ok $(ASSET_SOURCES)
@mkdir -p .build
cd ui && yarn build
touch $@
bindata_assetfs.go: .build/deps-build-go.ok .build/artifacts-bindata_assetfs.$(GO_BINDATA_MODE) .build/artifacts-ui.ok
go-bindata-assetfs -o bindata_assetfs.go ui/build/... ui/src/...
$(NAME): .build/deps-build-go.ok go.mod bindata_assetfs.go $(SOURCES)
GO111MODULE=on go build -ldflags "-X main.version=$(VERSION)"
.PHONY: clean
clean:
rm -fr .build bindata_assetfs.go $(NAME) ui/build ui/node_modules coverage.txt
.PHONY: run
run: $(NAME)
ALERTMANAGER_INTERVAL=36000h \
ALERTMANAGER_URI=$(ALERTMANAGER_URI) \
ANNOTATIONS_HIDDEN="help" \
LABELS_COLOR_UNIQUE="@receiver instance cluster" \
LABELS_COLOR_STATIC="job" \
FILTERS_DEFAULT="@state=active @receiver=by-cluster-service" \
PORT=$(PORT) \
./$(NAME)
.PHONY: docker-image
docker-image:
docker build --build-arg VERSION=$(VERSION) -t $(NAME):$(VERSION) .
.PHONY: run-docker
run-docker: docker-image
@docker rm -f $(NAME) || true
docker run \
--name $(NAME) \
-v $(MOCK_PATH):$(MOCK_PATH) \
-e ALERTMANAGER_INTERVAL=36000h \
-e ALERTMANAGER_URI=$(ALERTMANAGER_URI) \
-e ANNOTATIONS_HIDDEN="help" \
-e LABELS_COLOR_UNIQUE="instance cluster" \
-e LABELS_COLOR_STATIC="job" \
-e FILTERS_DEFAULT="@state=active @receiver=by-cluster-service" \
-e PORT=$(PORT) \
-p $(PORT):$(PORT) \
$(NAME):$(VERSION)
.PHONY: run-demo
run-demo:
docker build --build-arg VERSION=$(VERSION) -t $(NAME):demo -f demo/Dockerfile .
@docker rm -f $(NAME)-demo || true
docker run --name $(NAME)-demo -p $(PORT):$(PORT) -p 9093:9093 -p 9094:9094 $(NAME):demo
.PHONY: lint-git-ci
lint-git-ci: .build/deps-build-node.ok
ui/node_modules/.bin/commitlint-travis
.PHONY: lint-go
lint-go: .build/deps-lint-go.ok
GO111MODULE=on golangci-lint run
.PHONY: lint-js
lint-js: .build/deps-build-node.ok
cd ui && ./node_modules/.bin/eslint --quiet src
.PHONY: lint-docs
lint-docs: .build/deps-build-node.ok
$(CURDIR)/ui/node_modules/.bin/markdownlint *.md docs
.PHONY: lint
lint: lint-go lint-js lint-docs
.PHONY: test-go
test-go:
GO111MODULE=on go test -v \
-bench=. -benchmem \
-cover -coverprofile=coverage.txt -covermode=atomic \
./...
.PHONY: test-js
test-js: .build/deps-build-node.ok
cd ui && CI=true yarn test --coverage
.PHONY: test
test: lint test-go test-js
.PHONY: show-version
show-version:
@echo $(VERSION)
# Creates mock bindata_assetfs.go with source assets
.PHONY: mock-assets
mock-assets: .build/deps-build-go.ok
rm -fr ui/build
mkdir ui/build
cp ui/public/* ui/build/
go-bindata-assetfs -o bindata_assetfs.go -nometadata ui/build/...
# force assets rebuild on next make run
rm -f .build/bindata_assetfs.*
.PHONY: ui
ui: .build/artifacts-ui.ok