-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMakefile
More file actions
154 lines (129 loc) · 4.33 KB
/
Makefile
File metadata and controls
154 lines (129 loc) · 4.33 KB
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
SHELL := /bin/bash
OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH ?= $(shell uname -m | tr '[:upper:]' '[:lower:]')
ifeq ($(ARCH), x86_64)
ARCH := amd64
endif
IMAGE ?= ghcr.io/ozontech/seq-db
VERSION ?= $(shell git describe --abbrev=4 --dirty --always --tags)
TIME := $(shell date '+%Y-%m-%d_%H:%M:%S')
LOCAL_BIN:=$(CURDIR)/bin
.PHONY: build-image
build-image:
docker buildx build --platform linux/amd64 \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_TIME=${TIME} \
--file build/package/Dockerfile \
-t ${IMAGE}:${VERSION} \
.
.PHONY: build-debug
build-debug:
CGO_ENABLED=0 \
go build -gcflags="all=-N -l" \
-o ${LOCAL_BIN}/${OS}-${ARCH}/ \
./cmd/...
.PHONY: run
run: build-debug
SEQDB_STORAGE_DATA_DIR=$(shell mktemp -d) \
${LOCAL_BIN}/${OS}-${ARCH}/seq-db \
--mode=single \
--config=config.example.yaml
.PHONY: debug
debug: build-debug
SEQDB_STORAGE_DATA_DIR=$(shell mktemp -d) \
${LOCAL_BIN}/${OS}-${ARCH}/seq-db \
--mode=single \
--config=config.example.yaml & \
DLV_PID=$$!; \
sleep 1; \
dlv attach $$DLV_PID --init=.dlv-init
.PHONY: push-image
push-image: build-image
docker push ${IMAGE}:${VERSION}
.PHONY: test-deps
test-deps:
@docker compose -f tests/docker-compose.yml up -d
.PHONY: test
test: test-deps
LOG_LEVEL=ERROR go test ./... -count 1
.bin-deps: export GOBIN := $(LOCAL_BIN)
.bin-deps:
$(info Installing binary dependencies...)
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v2.26.1
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@v2.26.1
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.36.5
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1
go install github.com/planetscale/vtprotobuf/cmd/protoc-gen-go-vtproto@v0.6.1-0.20240319094008-0393e58bdf10
.PHONY: bin-deps
bin-deps: .bin-deps
.PHONY: proto
proto: bin-deps
proto:
protoc \
-I=api \
-I=vendorpb \
--plugin=protoc-gen-go=$(LOCAL_BIN)/protoc-gen-go \
--plugin=protoc-gen-grpc-gateway=$(LOCAL_BIN)/protoc-gen-grpc-gateway \
--plugin=protoc-gen-go-vtproto=$(LOCAL_BIN)/protoc-gen-go-vtproto \
--go_out=pkg --go_opt=paths=source_relative \
--grpc-gateway_out=pkg --grpc-gateway_opt=paths=source_relative --grpc-gateway_opt=generate_unbound_methods=true \
--go-vtproto_out=pkg --go-vtproto_opt=paths=source_relative \
--go-vtproto_opt=features=all \
$(shell find api -name '*.proto')
# arg -count=1 is used to disable tests caching (it is necessary when we want reproduce bugs of broken test isolation)
.PHONY: ci-tests
ci-tests: test-deps
set -o pipefail ;\
go test -v -short -count=1 -coverpkg=github.com/ozontech/seq-db/... -covermode=atomic -coverprofile=cover-tmp.out ./... 2>&1 | \
tee /dev/stderr | go-junit-report -set-exit-code > junit.xml
grep -vE ".pb.go|pb.*.go" cover-tmp.out > cover.out || cp cover-tmp.out cover.out
go tool cover -func=./cover.out
.PHONY: ci-tests-race
ci-tests-race: test-deps
set -o pipefail ;\
go test -short ./... -count=1 -race
# run diff lint like in pipeline
.lint:
$(info Running lint...)
GOBIN=$(LOCAL_BIN) go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6 run \
--config=.golangci.yaml ./...
.PHONY: lint
lint: .lint
.PHONY: imports
imports:
find . \
-path './pkg' -prune -o \
-type f -name '*.go' \
! -name '*.pb.go' \
! -name '*.pb.gw.go' \
! -name '*_mock.go' \
-exec goimports -w -local 'github.com/ozontech/seq-db' {} +
.PHONY: mock
mock:
go run github.com/golang/mock/mockgen@latest \
-source=proxyapi/grpc_v1.go \
-destination=proxyapi/mock/grpc_v1.go \
-package mock
go run github.com/golang/mock/mockgen@latest \
-destination=proxy/search/mock/store_api_client_mock.go \
-package mock \
github.com/ozontech/seq-db/pkg/storeapi StoreApiClient
get-version:
@echo ${VERSION}
LOCALE ?= 'en' # Use 'en' or 'ru'.
DOCS_VERSION := v0.0.3
.PHONY: serve-docs
serve-docs:
docker run -e LOCALE=$(LOCALE) --rm -it -p 3000:3000 \
-v ./docs/en:/website/docs/seq-db \
-v ./docs/ru:/website/i18n/ru/docusaurus-plugin-content-docs/current/seq-db \
ghcr.io/ozontech/seq-db-docs:$(DOCS_VERSION)
.PHONY: build-docs
build-docs:
docker run --rm \
-v ./bin/docs:/website/build \
-v ./docs/en:/website/docs/seq-db \
-v ./docs/ru:/website/i18n/ru/docusaurus-plugin-content-docs/current/seq-db \
--entrypoint /bin/sh \
ghcr.io/ozontech/seq-db-docs:$(DOCS_VERSION) \
-c 'npm run build'