-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
171 lines (144 loc) · 5.03 KB
/
Makefile
File metadata and controls
171 lines (144 loc) · 5.03 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
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
LOCAL_BIN := $(CURDIR)/bin
GOLANGCI_LINT_VER=2.8.0
PROTOC_GEN_GO_VER=1.34.2
PROTOC_GEN_GO_GRPC_VER=1.4.0
MOCKGEN_VER=0.6.0
SWAG_VER=1.16.2
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: .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: deps
deps: .protoc-plugins .install-tools
.PHONY: mock
mock:
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/pkg/repository/repository.go \
-destination=internal/pkg/repository/mock/repository.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/pkg/repository_ch/repository.go \
-destination=internal/pkg/repository_ch/mock/repository.go
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 \
-source=internal/pkg/client/seqdb/seqproxyapi/v1/seq_proxy_api_grpc.pb.go \
-destination=internal/pkg/client/seqdb/seqproxyapi/v1/mock/seq_proxy_api_grpc.pb.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/pkg/cache/cache.go \
-destination=internal/pkg/cache/mock/cache.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/app/auth/oidc.go \
-destination=internal/app/auth/mock/oidc.go
PATH="$(LOCAL_BIN):$(PATH)" mockgen \
-source=internal/app/auth/jwt.go \
-destination=internal/app/auth/mock/jwt.go
.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