Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
217 lines (187 loc) · 6.96 KB
/
Copy pathMakefile
File metadata and controls
217 lines (187 loc) · 6.96 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
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
IMAGE ?= ghcr.io/ozontech/seq-ui
VERSION ?= $(shell git describe --abbrev=4 --dirty --always --tags)
TIME := $(shell date '+%Y-%m-%d_%H:%M:%S')
MIGRATION_DSN ?= postgresql://localhost/postgres?sslmode=disable&user=postgres&password=postgres
MIGRATION_DSN_CLICKHOUSE ?= tcp://default@localhost:9000/seq_ui_server
SOURCE_CONFIG ?= config/config.local.yaml
LOCAL_BIN := $(CURDIR)/bin
GOLANGCI_LINT_VER=2.14.0
GCI_VER=0.14.0
PROTOC_GEN_GO_VER=1.36.12
PROTOC_GEN_GO_GRPC_VER=1.6.2
MOCKGEN_VER=0.6.0
SWAG_VER=1.16.6
export GOBIN=$(LOCAL_BIN)
.PHONY: build-bin
build-bin:
$(info Building binaries)
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-trimpath \
-ldflags "-X github.com/ozontech/seq-ui/buildinfo.Version=${VERSION} \
-X github.com/ozontech/seq-ui/buildinfo.BuildTime=${TIME}" \
-o ${LOCAL_BIN}/seq-ui \
./cmd/seq-ui
.PHONY: build-image
build-image:
$(info Building image)
docker buildx build --platform linux/amd64 \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_TIME=${TIME} \
--file build/package/Dockerfile \
-t ${IMAGE}:${VERSION} \
.
.PHONY: push-image
push-image: build-image
docker push ${IMAGE}:${VERSION}
.PHONY: build-migration-image
build-migration-image:
$(info Building pg-migration image)
docker buildx build --platform linux/amd64 \
--build-arg VERSION=${VERSION} \
--build-arg BUILD_TIME=${TIME} \
--file migration/Dockerfile \
-t ${IMAGE}-pg-migration:${VERSION} \
.
.PHONY: push-migration-image
push-migration-image: build-migration-image
docker push ${IMAGE}-pg-migration:${VERSION}
.PHONY: run
run: .check-config
go run ./cmd/seq-ui -config=config/config.local.yaml
.PHONY: config-migrate
config-migrate:
go run ./cmd/config-migrate -source=${SOURCE_CONFIG}
.PHONY: .check-config
.check-config:
@if [ ! -f config/config.local.yaml ]; then\
cp config/config.example.yaml config/config.local.yaml;\
fi
.PHONY: clean
clean:
rm -rf bin
.PHONY: test
test:
CGO_ENABLED=1 go test -count=1 -v -race ./...
.PHONY: lint
lint:
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VER) run \
--new-from-rev=origin/main --config=.golangci.yaml --timeout=5m
.PHONY: lint-full
lint-full:
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VER) run \
--config=.golangci.yaml --timeout=5m
.PHONY: gci
gci:
go run github.com/daixiang0/gci@v$(GCI_VER) write . \
-s standard -s default -s localmodule --skip-generated
.PHONY: deps
deps: .protoc-plugins .install-tools
SEQPROXY_MOCK_INTERFACES = SeqProxyApiClient,SeqProxyApiServer,UnsafeSeqProxyApiServer
SEQPROXY_MOCK_CLIENT_STREAMS = SeqProxyApi_FetchClient,SeqProxyApi_ExportClient,SeqProxyApi_ExportAsyncSearchClient
SEQPROXY_MOCK_SERVER_STREAMS = SeqProxyApi_FetchServer,SeqProxyApi_ExportServer,SeqProxyApi_ExportAsyncSearchServer
.PHONY: mock
mock:
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/errorgroups/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/errorgroups \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/pkg/repository/repository.go \
-destination=internal/pkg/repository/mock/repository.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/repository_ch/mock/repository_ch.go \
-package=mock_repositorych \
github.com/ozontech/seq-ui/internal/pkg/repository_ch \
Repository
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/repository_ch/mock/ch_driver.go \
-package=mock_repositorych \
github.com/ClickHouse/clickhouse-go/v2/lib/driver \
Conn,Rows,Row
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/pkg/client/seqdb/client.go \
-destination=internal/pkg/client/seqdb/mock/client.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/client/seqdb/seqproxyapi/v1/mock/seq_proxy_api_grpc.pb.go \
-package=mock_seqproxyapi \
github.com/ozontech/seq-ui/internal/pkg/client/seqdb/seqproxyapi/v1 \
$(SEQPROXY_MOCK_INTERFACES),$(SEQPROXY_MOCK_SERVER_STREAMS),$(SEQPROXY_MOCK_CLIENT_STREAMS)
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/pkg/cache/cache.go \
-destination=internal/pkg/cache/mock/cache.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/app/auth/mock/auth.go \
github.com/ozontech/seq-ui/internal/app/auth \
OIDCProvider,JWTProvider
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/dashboards/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/dashboards \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/async_searches/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/async_searches \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/userprofile/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/userprofile \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/massexport/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/massexport \
Service
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-destination=internal/pkg/service/admin/mock/service.go \
github.com/ozontech/seq-ui/internal/pkg/service/admin \
Service
.PHONY: protoc
protoc:
PATH="$(LOCAL_BIN):$(PATH)" protoc \
-I api \
--go_out=pkg --go_opt=paths=source_relative \
--go-grpc_out=pkg --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false \
$(shell find api -name '*.proto' | grep -v vendor)
PATH="$(LOCAL_BIN):$(PATH)" protoc \
-I internal/pkg/client/seqdb/seqproxyapi \
--go_out=internal/pkg/client/seqdb/seqproxyapi --go_opt=paths=source_relative \
--go-grpc_out=internal/pkg/client/seqdb/seqproxyapi --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false \
$(shell find internal/pkg/client/seqdb/seqproxyapi -name '*.proto')
.PHONY: swagger
swagger:
PATH="$(LOCAL_BIN):$(PATH)" swag fmt \
-g registrar.go \
-d internal/api
PATH="$(LOCAL_BIN):$(PATH)" swag init \
-q \
-g registrar.go \
-d internal/api \
-o swagger \
-ot json
.PHONY: generate
generate: protoc mock swagger
.PHONY: .protoc-plugins
.protoc-plugins:
$(info Downloading protoc plugins)
go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(PROTOC_GEN_GO_VER)
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$(PROTOC_GEN_GO_GRPC_VER)
.PHONY: .install-tools
.install-tools:
$(info Downloading tools)
go install go.uber.org/mock/mockgen@v$(MOCKGEN_VER)
go install github.com/swaggo/swag/cmd/swag@v$(SWAG_VER)
.PHONY: cover
cover:
go test -v -race -count=1 -coverprofile=coverage.out ./...
go tool cover -html=coverage.out
rm coverage.out
.PHONY: migrate
migrate:
goose -dir='migration' postgres "$(MIGRATION_DSN)" up
.PHONY: undo-last-migration
undo-last-migration:
goose -dir='migration' postgres "$(MIGRATION_DSN)" down
.PHONY: migrate-ch
migrate-ch:
goose -dir='migration_ch' clickhouse "$(MIGRATION_DSN_CLICKHOUSE)" up
.PHONY: undo-last-migration-ch
undo-last-migration-ch:
goose -dir='migration_ch' clickhouse "$(MIGRATION_DSN_CLICKHOUSE)" down