forked from moira-alert/moira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
179 lines (156 loc) · 6 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
MARK_NIGHTLY := "nightly"
MARK_UNSTABLE := "unstable"
GIT_BRANCH := "unknown"
GIT_HASH := $(shell git log --pretty=format:%H -n 1)
GIT_HASH_SHORT := $(shell echo "${GIT_HASH}" | cut -c1-7)
GIT_TAG := $(shell git describe --always --tags --abbrev=0 | tail -c+2)
GIT_COMMIT := $(shell git rev-list v${GIT_TAG}..HEAD --count)
GIT_COMMIT_DATE := $(shell git show -s --format=%ci | cut -d\ -f1)
VERSION_FEATURE := ${GIT_TAG}-$(shell echo $(GIT_BRANCH) | cut -c1-100).${GIT_COMMIT_DATE}.${GIT_HASH_SHORT}
VERSION_NIGHTLY := ${GIT_COMMIT_DATE}.${GIT_HASH_SHORT}
VERSION_RELEASE := ${GIT_TAG}.${GIT_COMMIT}
GO_VERSION := 1.18
GO_PATH := $(shell go env GOPATH)
GO111MODULE := on
GOLANGCI_LINT_VERSION := ""
VENDOR := "SKB Kontur"
URL := "https://github.com/moira-alert/moira"
LICENSE := "MIT"
SERVICES := "notifier" "api" "checker" "cli"
.PHONY: default
default: test build
.PHONY: install-lint
install-lint:
# The recommended way to install golangci-lint into CI/CD
wget -O - -q https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b ${GO_PATH}/bin ${GOLANGCI_LINT_VERSION}
.PHONY: lint
lint:
golangci-lint run
.PHONY: mock
mock:
. ./generate_mocks.sh
.PHONY: install-swag
install-swag:
go install github.com/swaggo/swag/cmd/[email protected]
.PHONY: spec
spec:
echo "Generating Swagger documentation"
swag init -g api/handler/handler.go
swag fmt
.PHONY: validate-spec
validate-spec:
openapi-generator-cli validate -i docs/swagger.yaml
.PHONY: test
test:
echo 'mode: atomic' > coverage.txt && go list ./... | xargs -n1 -I{} sh -c 'go test -race -v -bench=. -covermode=atomic -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.txt' && rm coverage.tmp
.PHONY: ci-test
ci-test:
echo 'mode: atomic' > coverage.txt && go list ./... | xargs -n1 -I{} sh -c 'go test -race -v -covermode=atomic -coverprofile=coverage.tmp {} && tail -n +2 coverage.tmp >> coverage.txt' && rm coverage.tmp
.PHONY: build
build:
for service in "filter" $(SERVICES) ; do \
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags "-X main.MoiraVersion=${VERSION_RELEASE} -X main.GoVersion=${GO_VERSION} -X main.GitCommit=${GIT_HASH}" -o build/$$service github.com/moira-alert/moira/cmd/$$service ; \
done
.PHONY: clean
clean:
rm -rf build
.PHONY: tar
tar:
for service in "filter" $(SERVICES) ; do \
mkdir -p build/root/$$service/usr/bin ; \
mkdir -p build/root/$$service/etc/moira ; \
cp build/$$service build/root/$$service/usr/bin/moira-$$service ; \
cp pkg/$$service/$$service.yml build/root/$$service/etc/moira/$$service.yml ; \
done
for service in "filter" "notifier" "api" "checker" ; do \
mkdir -p build/root/$$service/usr/lib/systemd/system ; \
cp pkg/$$service/moira-$$service.service build/root/$$service/usr/lib/systemd/system/moira-$$service.service ; \
done
cp pkg/filter/storage-schemas.conf build/root/filter/etc/moira/storage-schemas.conf
for service in "filter" "notifier" "api" "checker" "cli" ; do \
tar -czvPf build/moira-$$service-${VERSION_RELEASE}.tar.gz -C build/root/$$service . ; \
done
.PHONY: rpm
rpm: tar
for service in $(SERVICES) ; do \
fpm -t rpm \
-s "tar" \
--description "Moira $$service" \
--vendor ${VENDOR} \
--url ${URL} \
--license ${LICENSE} \
--name "moira-$$service" \
--version "${VERSION_RELEASE}" \
--iteration "1" \
--config-files "/etc/moira/$$service.yml" \
--after-install "./pkg/$$service/postinst" \
-p build \
build/moira-$$service-${VERSION_RELEASE}.tar.gz ; \
done
fpm -t rpm \
-s "tar" \
--description "Moira filter" \
--vendor ${VENDOR} \
--url ${URL} \
--license ${LICENSE} \
--name "moira-filter" \
--version "${VERSION_RELEASE}" \
--iteration "1" \
--config-files "/etc/moira/filter.yml" \
--config-files "/etc/moira/storage-schemas.conf" \
--after-install "./pkg/filter/postinst" \
-p build \
build/moira-filter-${VERSION_RELEASE}.tar.gz
.PHONY: deb
deb: tar
for service in $(SERVICES) ; do \
fpm -t deb \
-s "tar" \
--description "Moira $$service" \
--vendor ${VENDOR} \
--url ${URL} \
--license ${LICENSE} \
--name "moira-$$service" \
--version "${VERSION_RELEASE}" \
--iteration "1" \
--config-files "/etc/moira/$$service.yml" \
--after-install "./pkg/$$service/postinst" \
-p build \
build/moira-$$service-${VERSION_RELEASE}.tar.gz ; \
done
fpm -t deb \
-s "tar" \
--description "Moira filter" \
--vendor ${VENDOR} \
--url ${URL} \
--license ${LICENSE} \
--name "moira-filter" \
--version "${VERSION_RELEASE}" \
--iteration "1" \
--config-files "/etc/moira/filter.yml" \
--config-files "/etc/moira/storage-schemas.conf" \
--after-install "./pkg/filter/postinst" \
-p build \
build/moira-filter-${VERSION_RELEASE}.tar.gz
.PHONY: packages
packages: clean build tar rpm deb
.PHONY: docker_feature_images
docker_feature_images:
for service in "filter" $(SERVICES) ; do \
docker build --build-arg MoiraVersion=${VERSION_FEATURE} --build-arg GO_VERSION=${GO_VERSION} --build-arg GIT_COMMIT=${GIT_HASH} -f Dockerfile.$$service -t moira/$$service-${MARK_UNSTABLE}:${VERSION_FEATURE} . ; \
docker push moira/$$service-${MARK_UNSTABLE}:${VERSION_FEATURE} ; \
done
.PHONY: docker_nightly_images
docker_nightly_images:
for service in "filter" $(SERVICES) ; do \
docker build --build-arg MoiraVersion=${VERSION_NIGHTLY} --build-arg GO_VERSION=${GO_VERSION} --build-arg GIT_COMMIT=${GIT_HASH} -f Dockerfile.$$service -t moira/$$service-${MARK_NIGHTLY}:${VERSION_NIGHTLY} -t moira/$$service-${MARK_NIGHTLY}:latest . ; \
docker push moira/$$service-${MARK_NIGHTLY}:${VERSION_NIGHTLY} ; \
docker push moira/$$service-${MARK_NIGHTLY}:latest ; \
done
.PHONY: docker_release_images
docker_release_images:
for service in "filter" $(SERVICES) ; do \
docker build --build-arg MoiraVersion=${VERSION_RELEASE} --build-arg GO_VERSION=${GO_VERSION} --build-arg GIT_COMMIT=${GIT_HASH} -f Dockerfile.$$service -t moira/$$service:${VERSION_RELEASE} -t moira/$$service:latest . ; \
docker push moira/$$service:${VERSION_RELEASE} ; \
docker push moira/$$service:latest ; \
done