forked from project-kessel/inventory-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
193 lines (160 loc) · 4.65 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
ifeq ($(GO),)
GO:=$(shell command -v go)
endif
GOHOSTOS:=$(shell $(GO) env GOHOSTOS)
GOPATH:=$(shell $(GO) env GOPATH)
IMAGE ?="quay.io/cloudservices/kessel-inventory"
IMAGE_TAG=$(git rev-parse --short=7 HEAD)
GIT_COMMIT=$(git rev-parse --short HEAD)
ifeq ($(DOCKER),)
DOCKER:=$(shell command -v podman || command -v docker)
endif
API_PROTO_FILES:=$(shell find api -name *.proto)
TITLE:="Kessel Asset Inventory API"
ifeq ($(VERSION),)
VERSION:=$(shell git describe --tags --always)
endif
INVENTORY_SCHEMA_VERSION=0.11.0
.PHONY: init
# init env
init:
$(GO) install github.com/go-kratos/kratos/cmd/kratos/v2@latest
$(GO) install github.com/google/wire/cmd/wire@latest
$(GO) install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$(GO) get google.golang.org/grpc/cmd/protoc-gen-go-grpc
$(GO) install google.golang.org/grpc/cmd/protoc-gen-go-grpc
$(GO) install github.com/go-kratos/kratos/cmd/protoc-gen-go-http/v2@latest
$(GO) install github.com/google/gnostic/cmd/protoc-gen-openapi@latest
$(GO) get github.com/envoyproxy/protoc-gen-validate
$(GO) install github.com/envoyproxy/protoc-gen-validate
.PHONY: api
# generate api proto
api:
@echo "Generating api protos"
@$(DOCKER) build -t custom-protoc ./api
@$(DOCKER) run -t --rm -v $(PWD)/api:/api:rw,z -v $(PWD)/openapi.yaml:/openapi.yaml:rw,z \
-w=/api/ custom-protoc sh -c "buf generate && \
buf lint && \
buf breaking --against 'buf.build/project-kessel/inventory-api' "
.PHONY: api_breaking
# generate api proto
api_breaking:
@echo "Generating api protos, allowing breaking changes"
@$(DOCKER) build -t custom-protoc ./api
@$(DOCKER) run -t --rm -v $(PWD)/api:/api:rw,z -v $(PWD)/openapi.yaml:/openapi.yaml:rw,z \
-w=/api/ custom-protoc sh -c "buf generate && \
buf lint"
# .PHONY: api
# # generate api proto
# api:
# @echo "Generating api protos"
# @$(DOCKER) build -t custom-protoc ./api
# @$(DOCKER) run -t --rm -v $(PWD)/api:/api:rw -v $(PWD)/openapi.yaml:/openapi.yaml:rw \
# -w=/api/ custom-protoc sh -c "buf generate && buf lint"
.PHONY: build
# build
build:
mkdir -p bin/ && $(GO) build -ldflags "-X cmd.Version=$(VERSION)" -o ./bin/ ./...
.PHONY: docker-build-push
docker-build-push:
./build_deploy.sh
.PHONY: build-push-minimal
build-push-minimal:
./build_push_minimal.sh
.PHONY: clean
# removes all binaries
clean:
rm -rf bin/
.PHONY: test
# run all tests
test:
@echo ""
@echo "Running tests."
# TODO: e2e tests are taking too long to be enabled by default. They need to be sped up.
@$(GO) test ./... -count=1 -coverprofile=coverage.out -skip 'TestInventoryAPIGRPC_*|TestInventoryAPIHTTP_*|Test_ACMKafkaConsumer'
@echo "Overall test coverage:"
@$(GO) tool cover -func=coverage.out | grep total: | awk '{print $$3}'
@rm coverage.out
.PHONY: generate
# generate
generate:
$(GO) mod tidy
$(GO) get github.com/google/wire/cmd/wire@latest
$(GO) generate ./...
.PHONY: all
# generate all
all:
make api;
# make config;
make generate;
.PHONY: lint
# run go linter with the repositories lint config
lint:
@echo "Linting code."
@$(DOCKER) run -t --rm -v $(PWD):/app -w /app golangci/golangci-lint golangci-lint run -v
.PHONY: pr-check
# generate pr-check
pr-check:
make generate;
make test;
make lint;
make build;
#
.PHONY: inventory-up
inventory-up:
./scripts/start-inventory.sh
.PHONY: inventory-up-sso
inventory-up-sso:
./scripts/start-inventory-kc.sh
.PHONY: inventory-up-kafka
inventory-up-kafka:
./scripts/start-inventory-kafka.sh
.PHONY: inventory-up-kind
inventory-up-kind:
./scripts/start-inventory-kind.sh
.PHONY: get-token
get-token:
./scripts/get-token.sh
.PHONY: inventory-down
inventory-down:
./scripts/stop-inventory.sh
.PHONY: inventory-down-sso
inventory-down-sso:
./scripts/stop-inventory-kc.sh
.PHONY: inventory-down-kafka
inventory-down-kafka:
./scripts/stop-inventory-kafka.sh
.PHONY: inventory-down-kind
inventory-down-kind:
./scripts/stop-inventory-kind.sh
.PHONY: run
# run api locally
run: build
$(GO) run main.go serve
run-help: build
$(GO) run main.go serve --help
.PHONY: migrate
# run database migrations
migrate: build
./bin/inventory-api migrate --config .inventory-api.yaml
.PHONY: update-schema
# fetch the latest schema from github.com/RedHatInsights/kessel-config
update-schema:
./scripts/get-schema-yaml.sh > ./deploy/schema.yaml
help:
# show help
@echo ''
@echo 'Usage:'
@echo ' make [target]'
@echo ''
@echo 'Targets:'
@awk '/^[a-zA-Z\-_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help