-
Notifications
You must be signed in to change notification settings - Fork 42
/
Makefile
318 lines (251 loc) · 11.9 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
OS := $(shell uname)
UNAME_S := $(shell uname -s)
OS_SED :=
ifeq ($(UNAME_S),Darwin)
OS_SED += ""
endif
OCI_TOOL=$(shell command -v podman || command -v docker)
# Match logic in build_deploy.sh
IMAGE_TAG=$(shell git rev-parse --short=7 HEAD)
EDGE_API_CONTAINER_TAG="quay.io/cloudservices/edge-api:$(IMAGE_TAG)"
EDGE_API_DEV_CONTAINER_TAG="localhost/edge-api:dev-$(IMAGE_TAG)"
TEST_CONTAINER_TAG="quay.io/fleet-management/libfdo-data:$(IMAGE_TAG)"
KUBECTL=kubectl
NAMESPACE=default
TEST_OPTIONS=-race
BUILD_TAGS=''
BUILD_FLAGS=-trimpath
GOLANGCI_LINT_COMMON_OPTIONS=\
--enable=errcheck,gocritic,gofmt,goimports,gosec,gosimple,govet,ineffassign,revive,staticcheck,typecheck,unused,bodyclose \
--fix=false \
--go=1.21 \
--max-same-issues=20 \
--print-issued-lines=true \
--print-linter-name=true \
--sort-results=true \
--timeout=5m0s \
--uniq-by-line=false
EXCLUDE_DIRS=-e /test/ -e /cmd/db -e /cmd/kafka \
-e /pkg/clients/imagebuilder/mock_imagebuilder \
-e /pkg/imagebuilder/mock_imagebuilder \
-e /pkg/clients/inventory/mock_inventory \
-e /pkg/errors -e /pkg/services/mock_services -e /unleash \
-e /api
CONTAINERFILE_NAME=Dockerfile
.PHONY: all bonfire-config-local bonfire-config-github build-containers \
build build-edge-api-container clean coverage coverage-html \
create-ns deploy-app deploy-env fmt generate-docs help lint pre-commit \
restart-app scale-down scale-up test test-clean vet
bonfire-config-local:
@cp default_config.yaml.local.example config.yaml
@sed -i $(OS_SED) 's|REPO|$(PWD)|g' config.yaml
bonfire-config-github:
@cp default_config.yaml.github.example config.yaml
build-containers: build-edge-api-container build-test-container
build-edge-api-container:
$(OCI_TOOL) build \
--file "$(CONTAINERFILE_NAME)" \
--no-cache \
--tag "$(EDGE_API_CONTAINER_TAG)" \
.
build-test-container:
cd test-container; \
$(OCI_TOOL) build \
--file "$(CONTAINERFILE_NAME)" \
--no-cache \
--tag "$(TEST_CONTAINER_TAG)" \
.
build-dev-container:
$(OCI_TOOL) build \
--file "$(CONTAINERFILE_NAME)" \
--no-cache \
--tag "$(EDGE_API_DEV_CONTAINER_TAG)" \
.
build:
mkdir -p build 2>/dev/null
go build $(BUILD_FLAGS) -o build/edge-api .
go build $(BUILD_FLAGS) -o build/edge-api-migrate cmd/migrate/main.go
go build $(BUILD_FLAGS) -o build/edge-api-wipe cmd/db/wipe.go
go build $(BUILD_FLAGS) -o build/edge-api-migrate-device cmd/db/updDb/set_account_on_device.go
go build $(BUILD_FLAGS) -o build/edge-api-migrate-repositories cmd/migraterepos/main.go
go build $(BUILD_FLAGS) -o build/edge-api-migrate-groups cmd/migrategroups/main.go
go build $(BUILD_FLAGS) -o build/edge-api-ibvents cmd/kafka/main.go
go build $(BUILD_FLAGS) -o build/edge-api-cleanup cmd/cleanup/main.go
clean:
rm -rf build
golangci-lint cache clean
coverage:
go test $(BUILD_TAGS) $$(go list $(BUILD_TAGS) ./... | grep -v $(EXCLUDE_DIRS)) $(TEST_OPTIONS) -coverprofile=coverage.txt -covermode=atomic
coverage-html:
go tool cover -html=coverage.txt -o coverage.html
create-ns:
$(KUBECTL) create ns $(NAMESPACE)
deploy-app:
bonfire deploy edge -n $(NAMESPACE)
deploy-env:
bonfire deploy-env -n $(NAMESPACE)
fmt:
go fmt $$(go list ./... | grep -v /vendor/)
generate-docs:
~/go/bin/swag init --generalInfo api.go --o ./cmd/spec/ --dir pkg/models,pkg/routes --parseDependency
go run ./cmd/swagger2openapi/main.go cmd/spec/swagger.json cmd/spec/openapi.json
help:
@echo "Please use \`make <target>' where <target> is one of:"
@echo ""
@echo "--- General Commands ---"
@echo "bonfire-config-local Create bonfire config for deploying from your local repository"
@echo "bonfire-config-github Create bonfire config for deploying from the github repository"
@echo "build-containers Builds all the container images"
@echo "build-edge-api-container Builds the edge-api container"
@echo "build-test-container Builds the test container"
@echo "build Build all binaries into ./build"
@echo "clean Removes binaries and cached golangci files"
@echo "coverage Runs 'go test' coverage on the project"
@echo "coverage-html Create HTML version of coverage report"
@echo "create-ns Creates a namespace in kubernetes"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "deploy-app Deploys the edge app in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "deploy-env Creates a ClowdEnvironment in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "fmt Runs 'go fmt' on the project"
@echo "generate-docs Creates OpenAPI specification for the project"
@echo "help Show this message"
@echo "lint Runs 'golint' on the project"
@echo "golangci-lint Runs 'golangci-lint' on the project"
@echo "openapi Generates an openapi.{json,yaml} file in /cmd/spec/"
@echo "update-clients Updates sources for OpenAPI clients"
@echo "pre-commit Runs fmt, vet, lint, and clean on the project"
@echo "restart-app Scales the edge-api-service deployment down to 0 then up to 1 in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "scale-down Scales the edge-api-service deployment down to 0 in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "scale-up Scales the edge-api-service deployment up to 1 in the given namespace"
@echo " @param NAMESPACE - (optional) the namespace to use"
@echo "swaggo Runs swaggo/swag and converts to openapi.json in /api"
@echo "swaggo_setup" Installs necessary packages to use swaggo
@echo "test Runs 'go test' on the project"
@echo "vet Runs 'go vet' on the project"
@echo ""
golangci-lint:
if [ "$(GITHUB_ACTION)" != '' ];\
then\
OUT_FORMAT="--out-format=line-number";\
TARGET_FILES=$$(go list $(BUILD_TAGS) ./... | grep -v /vendor/);\
else\
OUT_FORMAT="--out-format=colored-line-number";\
TARGET_FILES=$$(go list -f '{{.Dir}}' ${BUILD_TAGS} ./... | grep -v '/vendor/');\
fi;\
golangci-lint run $(GOLANGCI_LINT_COMMON_OPTIONS) $(OUT_FORMAT) \
$(TARGET_FILES)
lint:
golint $$(go list $(BUILD_TAGS) ./... | grep -v /vendor/)
openapi:
go run cmd/spec/main.go
# This needs github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
# Also workarounds a bug: https://github.com/oapi-codegen/oapi-codegen/issues/243
.PHONY: update-clients
update-clients:
curl -s "https://pulp.stage.devshift.net/api/pulp/api/v3/docs/api.json?pk_path=1" > pkg/clients/pulp/pulp_openapi.json
perl -i -pe 'BEGIN{undef $$/;} s/"additionalProperties": {\s*"type": "object"\s*}/"additionalProperties": true/g' pkg/clients/pulp/pulp_openapi.json
oapi-codegen -config pkg/clients/pulp/pulp_config.yaml pkg/clients/pulp/pulp_openapi.json
pre-commit:
$(MAKE) golangci-lint
$(MAKE) test-clean
restart-app:
$(MAKE) scale-down NAMESPACE=$(NAMESPACE)
sleep 5
$(MAKE) scale-up NAMESPACE=$(NAMESPACE)
scale-down:
$(KUBECTL) scale --replicas=0 deployment/edge-api-service -n $(NAMESPACE)
scale-up:
$(KUBECTL) scale --replicas=1 deployment/edge-api-service -n $(NAMESPACE)
swaggo_setup:
go install github.com/swaggo/swag/cmd/swag@latest
test:
go test $(BUILD_TAGS) $$(go list $(BUILD_TAGS) ./... | grep -v /test/) $(TEST_OPTIONS)
test-clean:
go test -count=1 $$(go list ./... | grep -v /test/) $(TEST_OPTIONS)
test_gha:
go test ./...
vet:
go mod tidy
go install -a
go vet $(BUILD_TAGS) $$(go list $(BUILD_TAGS) ./... | grep -v /vendor/)
pkg/services/mock_services/downloader.go: pkg/services/files/downloader.go go.mod
mockgen -source=$< -destination=$@ -package=mock_services
pkg/services/mock_services/updates.go: pkg/services/updates.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/thirdpartyrepo.go: pkg/services/thirdpartyrepo.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/repobuilder.go: pkg/services/repobuilder.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/imagesets.go: pkg/services/imagesets.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/images.go: pkg/services/images.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/devices.go: pkg/services/devices.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/commits.go: pkg/services/commits.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/repo.go: pkg/services/repo.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_files/uploader.go: pkg/services/files/uploader.go go.mod
mockgen -source=$< -destination=$@
# is a copy of the above, before this make target it was a manually created mess
pkg/services/mock_services/uploader.go: pkg/services/files/uploader.go go.mod
mockgen -source=$< -destination=$@ -package=mock_services
pkg/services/mock_services/files.go: pkg/services/files.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_files/s3.go: pkg/services/files/s3.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_services/devicegroups.go: pkg/services/devicegroups.go go.mod
mockgen -source=$< -destination=$@
pkg/services/mock_files/extrator.go: pkg/services/files/extractor.go go.mod
mockgen -source=$< -destination=$@
pkg/common/kafka/mock_kafka/mock_topics.go: pkg/common/kafka/topics.go go.mod
mockgen -source=$< -destination=$@
pkg/common/kafka/mock_kafka/mock_producer.go: pkg/common/kafka/producer.go go.mod
mockgen -source=$< -destination=$@
pkg/common/kafka/mock_kafka/mock_kafkaconfigmap.go: pkg/common/kafka/kafkaconfigmap.go go.mod
mockgen -source=$< -destination=$@
pkg/common/kafka/mock_kafka/mock_consumer.go: pkg/common/kafka/consumer.go go.mod
mockgen -source=$< -destination=$@
pkg/clients/repositories/mock_repositories/client.go: pkg/clients/repositories/client.go go.mod
mockgen -source=$< -destination=$@
pkg/clients/playbookdispatcher/mock_playbookdispatcher/playbookdispatcher.go: pkg/clients/playbookdispatcher/client.go go.mod
mockgen -source=$< -destination=$@
pkg/clients/rbac/mock_rbac/client.go: pkg/clients/rbac/client.go go.mod
mockgen -source=$< -destination=$@
pkg/clients/inventory/mock_inventory/inventory.go: pkg/clients/inventory/client.go go.mod
mockgen -source=$< -destination=$@
pkg/clients/inventorygroups/mock_inventorygroups/client.go: pkg/clients/inventorygroups/client.go go.mod
mockgen -source=$< -destination=$@
pkg/clients/imagebuilder/mock_imagebuilder/client.go: pkg/clients/imagebuilder/client.go go.mod
mockgen -source=$< -destination=$@
mockgen: \
pkg/services/mock_services/downloader.go \
pkg/services/mock_services/updates.go \
pkg/services/mock_services/thirdpartyrepo.go \
pkg/services/mock_services/repobuilder.go \
pkg/services/mock_services/imagesets.go \
pkg/services/mock_services/images.go \
pkg/services/mock_services/devices.go \
pkg/services/mock_services/commits.go \
pkg/services/mock_services/uploader.go \
pkg/services/mock_services/repo.go \
pkg/services/mock_files/uploader.go \
pkg/services/mock_services/files.go \
pkg/services/mock_files/s3.go \
pkg/services/mock_services/devicegroups.go \
pkg/services/mock_files/extrator.go \
pkg/common/kafka/mock_kafka/mock_topics.go \
pkg/common/kafka/mock_kafka/mock_producer.go \
pkg/common/kafka/mock_kafka/mock_kafkaconfigmap.go \
pkg/common/kafka/mock_kafka/mock_consumer.go \
pkg/clients/repositories/mock_repositories/client.go \
pkg/clients/playbookdispatcher/mock_playbookdispatcher/playbookdispatcher.go \
pkg/clients/rbac/mock_rbac/client.go \
pkg/clients/inventory/mock_inventory/inventory.go \
pkg/clients/inventorygroups/mock_inventorygroups/client.go \
pkg/clients/imagebuilder/mock_imagebuilder/client.go