-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMakefile
More file actions
479 lines (414 loc) Β· 21.9 KB
/
Makefile
File metadata and controls
479 lines (414 loc) Β· 21.9 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
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
GOBASE=$(shell pwd)
GOBIN=$(GOBASE)/bin
GO_BUILD_FLAGS := ${GO_BUILD_FLAGS}
ROOT_DIR := $(or ${ROOT_DIR},$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))))
GO_FILES := $(shell find ./ -name ".go" -not -path "./bin" -not -path "./packaging/*")
GO_CACHE := -v $${HOME}/go/migration-planner-go-cache:/opt/app-root/src/go:Z -v $${HOME}/go/migration-planner-go-cache/.cache:/opt/app-root/src/.cache:Z
TIMEOUT ?= 30m
VERBOSE ?= false
REGISTRY ?= quay.io
MIGRATION_PLANNER_IMAGE_TAG ?= latest
MIGRATION_PLANNER_IMAGE_TAG := $(MIGRATION_PLANNER_IMAGE_TAG)$(if $(DEBUG_MODE),-debug)
MIGRATION_PLANNER_AGENT_IMAGE ?= $(REGISTRY)/redhat-user-workloads/assisted-migration-tenant/migration-planner-agent
MIGRATION_PLANNER_API_IMAGE ?= $(REGISTRY)/redhat-user-workloads/assisted-migration-tenant/migration-planner-api
MIGRATION_PLANNER_ISO_IMAGE ?= $(REGISTRY)/redhat-user-workloads/assisted-migration-tenant/migration-planner-rhcos-iso
MIGRATION_PLANNER_IMAGE_PULL_POLICY ?= Always
MIGRATION_PLANNER_NAMESPACE ?= assisted-migration
MIGRATION_PLANNER_REPLICAS ?= 1
# API path prefix for the service (allows multiple instances in same namespace)
SERVICE_API_PATH ?= /api/migration-assessment
MIGRATION_PLANNER_AUTH ?= local
PERSISTENT_DISK_DEVICE ?= /dev/sda
INSECURE_REGISTRY ?= "true"
DOWNLOAD_RHCOS ?= true
RHCOS_PASSWORD ?= '$$$$y$$$$j9T$$$$hUUbW8zoB.Qcmpwm4/RuK1$$$$FMtuDAxNLp3sEa2PnGiJdXr8uYbvUNPlVDXpcJim529'
IFACE ?= eth0
GREP ?= grep
PODMAN ?= podman
DOCKER_CONF ?= $(CURDIR)/docker-config
DOCKER_AUTH_FILE ?= ${DOCKER_CONF}/auth.json
PKG_MANAGER ?= apt
SIZER_IMAGE ?= quay.io/redhat-user-workloads/odf-sizer-lib-tenant/sizer
SIZER_IMAGE_TAG ?= latest
SIZER_PORT ?= 9200
# OPA Configuration for eval mode
MIGRATION_PLANNER_OPA_POLICIES_FOLDER ?= $(CURDIR)/policies
FORKLIFT_POLICIES_TMP_DIR ?= /tmp/forklift-policies
# Get version ldflags from script
GO_LD_FLAGS := -ldflags "$(shell bash -c 'source hack/version.sh && echo $$GO_LDFLAGS')"
GO_BUILD_FLAGS += $(GO_LD_FLAGS)
.EXPORT_ALL_VARIABLES:
all: build build-containers
help:
@echo "Targets:"
@echo " generate: regenerate all generated files"
@echo " tidy: tidy go mod"
@echo " lint: run golangci-lint"
@echo " build: run all builds"
@echo " clean: clean up all containers and volumes"
@echo " test: run unit tests"
@echo " run: run the service for development"
@echo " setup-opa-policies: download OPA policies from Forklift project"
@echo " clean-opa-policies: clean OPA policies directory"
@echo " generate: regenerate all generated files"
@echo " tidy: tidy go mod"
@echo " lint: run golangci-lint"
@echo " build: run all builds"
@echo " clean: clean up all containers and volumes"
@echo " migrate: run database migrations"
@echo " run: run the OpenShift Migration Advisor API service"
@echo " integration-test: run e2e integration tests"
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
OC_VERSION ?= 4.17.9
OC_BIN := $(shell command -v oc)
oc: # Verify oc installed, in linux install it if not already installed
ifeq ($(OC_BIN),)
@if [ "$(OS)" = "darwin" ]; then \
echo "Error: macOS detected. Please install oc manually from https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$(OC_VERSION)/"; \
exit 1; \
fi
@echo "oc not found. Installing for Linux..."
@curl -sL "https://mirror.openshift.com/pub/openshift-v4/clients/ocp/$(OC_VERSION)/openshift-client-linux.tar.gz" | tar -xz
@chmod +x oc kubectl
@sudo mv oc kubectl /usr/local/bin/
@echo "oc installed successfully."
else
@echo "oc is already installed at $(OC_BIN)"
endif
tidy:
git ls-files go.mod '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && go mod tidy'
migrate:
MIGRATION_PLANNER_MIGRATIONS_FOLDER=$(CURDIR)/pkg/migrations/sql ./bin/planner-api migrate
AIR := $(GOBIN)/air
$(AIR):
@go install github.com/air-verse/air@v1.63.4
run: $(AIR) image
MIGRATION_PLANNER_MIGRATIONS_FOLDER=$(CURDIR)/pkg/migrations/sql \
MIGRATION_PLANNER_OPA_POLICIES_FOLDER=$(MIGRATION_PLANNER_OPA_POLICIES_FOLDER) \
$(AIR) --build.cmd "make build" --build.bin "./bin/planner-api" --build.args_bin "run" --build.include_dir "cmd,internal,pkg,api"
run-agent: build-agent
@echo "Running agent from agent-v2 submodule..."
$(MAKE) -C agent-v2 run
# Build agent-v2 container image (includes UI)
build-agent-image: submodules
@echo "Building agent-v2 container image..."
$(MAKE) -C agent-v2 image
# Run agent-v2 container image locally
# Usage: make run-agent-image AGENT_ID=<uuid> SOURCE_ID=<uuid>
run-agent-image: submodules
@echo "Running agent-v2 container image..."
$(MAKE) -C agent-v2 run.image AGENT_ID=$(AGENT_ID) SOURCE_ID=$(SOURCE_ID)
# Run agent-v2 UI dev server
run-agent-ui: submodules
@echo "Starting agent-v2 UI dev server..."
$(MAKE) -C agent-v2 run.ui
run-sizer:
@echo "π Starting sizer service container on port $(SIZER_PORT)..."
@$(PODMAN) rm -f migration-planner-sizer-local 2>/dev/null || true
@$(PODMAN) run -d --name migration-planner-sizer-local \
-p $(SIZER_PORT):$(SIZER_PORT) \
-e PORT=$(SIZER_PORT) \
$(SIZER_IMAGE):$(SIZER_IMAGE_TAG)
@echo "β
Sizer service running at http://localhost:$(SIZER_PORT)"
@echo " Health: http://localhost:$(SIZER_PORT)/health"
@echo " API: http://localhost:$(SIZER_PORT)/api/v1/size/custom"
image:
ifeq ($(DOWNLOAD_RHCOS), true)
@if [ ! -f rhcos-live-iso.x86_64.iso ]; then \
curl --progress-bar -C - -O https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/rhcos-live-iso.x86_64.iso; \
fi
endif
build: bin
go build -buildvcs=false $(GO_BUILD_FLAGS) -o $(GOBIN) ./cmd/...
build-api: bin
go build -buildvcs=false $(GO_BUILD_FLAGS) -o $(GOBIN) ./cmd/planner-api
build-agent: bin submodules
@echo "Building agent from agent-v2 submodule..."
$(MAKE) -C agent-v2 build
@echo "Agent binary built at agent-v2/bin/agent"
build-cli: bin
go build -buildvcs=false $(GO_BUILD_FLAGS) -o $(GOBIN) ./cmd/planner
# rebuild container only on source changes
bin/.migration-planner-agent-container: bin submodules agent-v2/Containerfile
$(PODMAN) build agent-v2/ $(if $(DEBUG_MODE),--build-arg GCFLAGS="all=-N -l") -f agent-v2/Containerfile $(if $(LABEL),--label "$(LABEL)") -t $(MIGRATION_PLANNER_AGENT_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG)
bin/.migration-planner-api-container: bin Containerfile.api go.mod go.sum $(GO_FILES)
$(PODMAN) build . $(if $(DEBUG_MODE),--build-arg GCFLAGS="all=-N -l") -f Containerfile.api $(if $(LABEL),--label "$(LABEL)") -t $(MIGRATION_PLANNER_API_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG)
if [ "$(DEBUG_MODE)" = "true" ]; then $(PODMAN) build . --build-arg BASE_IMAGE=$(MIGRATION_PLANNER_API_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG) -f Containerfile.api-debug -t $(MIGRATION_PLANNER_API_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG); fi
migration-planner-api-container: bin/.migration-planner-api-container
migration-planner-agent-container: bin/.migration-planner-agent-container
bin/.migration-planner-iso-container: build/migration-planner-iso/Containerfile build/migration-planner-iso/build-ove-image.sh build/migration-planner-iso/config
@ISO_URL=$$(grep '^ISO_URL=' build/migration-planner-iso/config | cut -d'=' -f2); \
ISO_CHECKSUM=$$(grep '^ISO_CHECKSUM=' build/migration-planner-iso/config | cut -d'=' -f2); \
TLS_VERIFY=$${TLS_VERIFY:-true}; \
$(PODMAN) build . \
--network=host \
--build-arg AGENT_IMAGE=$(MIGRATION_PLANNER_AGENT_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG) \
--build-arg ISO_URL=$$ISO_URL \
--build-arg ISO_CHECKSUM=$$ISO_CHECKSUM \
--build-arg FINAL_ISO_PATH=/rhcos.iso \
--build-arg TLS_VERIFY=$$TLS_VERIFY \
-f build/migration-planner-iso/Containerfile \
$(if $(LABEL),--label "$(LABEL)") \
-t $(MIGRATION_PLANNER_ISO_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG)
migration-planner-iso-container: bin/.migration-planner-iso-container
build-containers: migration-planner-api-container migration-planner-agent-container
.PHONY: build-containers
quay-login:
@if [ ! -f $(DOCKER_AUTH_FILE) ] && [ $(QUAY_USER) ] && [ $(QUAY_TOKEN) ]; then \
$(info Create Auth File: $(DOCKER_AUTH_FILE)) \
mkdir -p "$(DOCKER_CONF)"; \
$(PODMAN) login --authfile $(DOCKER_AUTH_FILE) -u=$(QUAY_USER) -p=$(QUAY_TOKEN) quay.io; \
fi;
push-api-container: migration-planner-api-container quay-login
if [ -f $(DOCKER_AUTH_FILE) ]; then \
$(PODMAN) push --authfile $(DOCKER_AUTH_FILE) $(MIGRATION_PLANNER_API_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG); \
else \
$(PODMAN) push $(MIGRATION_PLANNER_API_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG); \
fi;
push-agent-container: migration-planner-agent-container quay-login
if [ -f $(DOCKER_AUTH_FILE) ]; then \
$(PODMAN) push --authfile=$(DOCKER_AUTH_FILE) $(MIGRATION_PLANNER_AGENT_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG); \
else \
$(PODMAN) push $(MIGRATION_PLANNER_AGENT_IMAGE):$(MIGRATION_PLANNER_IMAGE_TAG); \
fi;
push-containers: push-api-container push-agent-container
deploy-on-openshift: oc
@openshift_base_url=$$(oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
openshift_project=$$(oc project -q); \
echo "*** Deploy OpenShift Migration Advisor on OpenShift. Project: $${openshift_project}, Base URL: $${openshift_base_url} ***";\
oc process -f deploy/templates/postgres-template.yml | oc apply -f -; \
oc process -f deploy/templates/s3-secret-template.yml | oc apply -f -; \
oc process -f deploy/templates/service-template.yml \
-p DEBUG_MODE=$(DEBUG_MODE) \
-p MIGRATION_PLANNER_ISO_IMAGE=$(MIGRATION_PLANNER_ISO_IMAGE) \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=${MIGRATION_PLANNER_REPLICAS} \
-p IMAGE_TAG=$(MIGRATION_PLANNER_IMAGE_TAG) \
-p SERVICE_API_PATH=$(SERVICE_API_PATH) \
-p MIGRATION_PLANNER_URL=http://planner-agent-$${openshift_project}.apps.$${openshift_base_url}$(SERVICE_API_PATH) \
-p MIGRATION_PLANNER_UI_URL=http://planner-ui-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_IMAGE_URL=http://planner-image-$${openshift_project}.apps.$${openshift_base_url}$(SERVICE_API_PATH) \
| oc apply -f -; \
oc expose service migration-planner-agent --name planner-agent; \
oc expose service migration-planner-image --name planner-image; \
echo "*** OpenShift Migration Advisor has been deployed successfully on OpenShift ***"; \
delete-from-openshift: oc
@openshift_base_url=$$(oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
openshift_project=$$(oc project -q); \
echo "*** Delete OpenShift Migration Advisor from OpenShift. Project: $${openshift_project}, Base URL: $${openshift_base_url} ***"; \
openshift_base_url=$$(oc whoami --show-server | sed -E 's~https?://api\.~~; s~:[0-9]+/?$$~~'); \
openshift_project=$$(oc project -q); \
oc process -f deploy/templates/service-template.yml \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_ISO_IMAGE=$(MIGRATION_PLANNER_ISO_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p IMAGE_TAG=$(MIGRATION_PLANNER_IMAGE_TAG) \
-p SERVICE_API_PATH=$(SERVICE_API_PATH) \
-p SIZER_IMAGE=$(SIZER_IMAGE) \
-p SIZER_PORT=$(SIZER_PORT) \
-p MIGRATION_PLANNER_URL=http://planner-agent-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_UI_URL=http://planner-ui-$${openshift_project}.apps.$${openshift_base_url} \
-p MIGRATION_PLANNER_IMAGE_URL=http://planner-image-$${openshift_project}.apps.$${openshift_base_url} \
| oc delete -f -; \
oc process -f deploy/templates/postgres-template.yml | oc delete -f -; \
oc process -f deploy/templates/s3-secret-template.yml | oc delete -f -; \
oc delete route planner-agent planner-image; \
echo "*** OpenShift Migration Advisor has been deleted successfully from OpenShift ***"
deploy-on-kind: oc
@inet_ip=$$(ip addr show ${IFACE} | $(GREP) -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
echo "*** Deploy OpenShift Migration Advisor on Kind. Namespace: $${MIGRATION_PLANNER_NAMESPACE}, inet_ip: $${inet_ip}, PERSISTENT_DISK_DEVICE: $${PERSISTENT_DISK_DEVICE} ***"; \
oc process --local -f deploy/templates/pk-secret-template.yml \
-p E2E_PRIVATE_KEY_BASE64=$(shell base64 -w 0 $(E2E_PRIVATE_KEY_FOLDER_PATH)/private-key) \
| oc apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/postgres-template.yml | oc apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/s3-secret-template.yml | oc apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/service-template.yml \
-p SERVICE_API_PATH=$(SERVICE_API_PATH) \
-p MIGRATION_PLANNER_URL=http://$${inet_ip}:7443$(SERVICE_API_PATH) \
-p MIGRATION_PLANNER_UI_URL=http://$${inet_ip}:3333 \
-p MIGRATION_PLANNER_IMAGE_URL=http://$${inet_ip}:7443$(SERVICE_API_PATH) \
-p MIGRATION_PLANNER_IMAGE_PULL_POLICY=Never \
-p MIGRATION_PLANNER_ISO_IMAGE=$(MIGRATION_PLANNER_ISO_IMAGE) \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p PERSISTENT_DISK_DEVICE=$(PERSISTENT_DISK_DEVICE) \
-p INSECURE_REGISTRY=$(INSECURE_REGISTRY) \
-p MIGRATION_PLANNER_AUTH=$(MIGRATION_PLANNER_AUTH) \
-p RHCOS_PASSWORD=${RHCOS_PASSWORD} \
| oc apply -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
echo "*** OpenShift Migration Advisor has been deployed successfully on Kind ***"
delete-from-kind: oc
inet_ip=$$(ip addr show ${IFACE} | $(GREP) -oP '(?<=inet\s)\d+\.\d+\.\d+\.\d+'); \
oc process --local -f deploy/templates/service-template.yml \
-p SERVICE_API_PATH=$(SERVICE_API_PATH) \
-p MIGRATION_PLANNER_URL=http://$${inet_ip}:7443 \
-p MIGRATION_PLANNER_UI_URL=http://$${inet_ip}:3333 \
-p MIGRATION_PLANNER_IMAGE_URL=http://$${inet_ip}:11443 \
-p MIGRATION_PLANNER_IMAGE_PULL_POLICY=Never \
-p MIGRATION_PLANNER_IMAGE=$(MIGRATION_PLANNER_API_IMAGE) \
-p MIGRATION_PLANNER_ISO_IMAGE=$(MIGRATION_PLANNER_ISO_IMAGE) \
-p MIGRATION_PLANNER_REPLICAS=$(MIGRATION_PLANNER_REPLICAS) \
-p PERSISTENT_DISK_DEVICE=$(PERSISTENT_DISK_DEVICE) \
-p INSECURE_REGISTRY=$(INSECURE_REGISTRY) \
| oc delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/postgres-template.yml | oc delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/pk-secret-template.yml \
-p E2E_PRIVATE_KEY_BASE64=$(shell base64 -w 0 $(E2E_PRIVATE_KEY_FOLDER_PATH)/private-key) \
| oc delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
oc process --local -f deploy/templates/s3-secret-template.yml | oc delete -n "${MIGRATION_PLANNER_NAMESPACE}" -f -; \
deploy-local-obs:
@podman play kube --network host deploy/observability.yml
undeploy-local-obs:
@podman kube down deploy/observability.yml
bin:
mkdir -p bin
# Initialize git submodules if needed
submodules:
@if [ -f .gitmodules ]; then \
git submodule update --init --recursive || true; \
fi
clean:
- rm -f -r bin
##################### "make lint" support start ##########################
GOLANGCI_LINT_VERSION := v2.10.1
GOLANGCI_LINT := $(GOBIN)/golangci-lint
# Run every time: if installed version != required, remove binary so $(GOLANGCI_LINT) will re-install
.PHONY: check-golangci-lint-version
check-golangci-lint-version:
@if [ -f '$(GOLANGCI_LINT)' ]; then \
installed=$$('$(GOLANGCI_LINT)' version 2>/dev/null | sed -n 's/.*version \([0-9.]*\).*/\1/p' | head -1); \
required=$$(echo '$(GOLANGCI_LINT_VERSION)' | sed 's/^v//'); \
if [ -n "$$installed" ] && [ "$$installed" != "$$required" ]; then \
echo "π Installed golangci-lint $$installed != required $(GOLANGCI_LINT_VERSION), re-installing..."; \
rm -f '$(GOLANGCI_LINT)'; \
fi; \
fi
# Download golangci-lint if not present
$(GOLANGCI_LINT):
@echo "π Installing golangci-lint $(GOLANGCI_LINT_VERSION)..."
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | \
sh -s -- -b $(CURDIR)/bin $(GOLANGCI_LINT_VERSION)
@echo "β
'golangci-lint' installed successfully."
# Run linter
lint: check-golangci-lint-version $(GOLANGCI_LINT)
@echo "π Running golangci-lint..."
@$(GOLANGCI_LINT) run --timeout=5m
@echo "β
Lint passed successfully!"
##################### "make lint" support end ##########################
##################### "make generate" support start ##########################
MOQ := $(GOBIN)/moq
# Install moq if not already present
$(MOQ):
@echo "π¦ Installing moq..."
@go install github.com/matryer/moq@latest
@echo "β
'moq' installed successfully."
# Code generation (exclude agent-v2 submodule)
generate: $(MOQ)
@echo "βοΈ Running go generate..."
@PATH="$(GOBIN):$$PATH" go generate -v $(shell go list ./... | grep -v 'agent-v2' || true)
@echo "βοΈ Running mockgen script..."
@hack/mockgen.sh
@$(MAKE) format
@echo "β
Generate complete."
# Check if generate changes the repo
check-generate: generate
@echo "π Checking if generated files are up to date..."
@git diff --quiet || (echo "β Detected uncommitted changes after generate. Run 'make generate' and commit the result." && git status && exit 1)
@echo "β
All generated files are up to date."
##################### "make generate" support end ##########################
##################### "make format" support start ##########################
GOIMPORTS := $(GOBIN)/goimports
# Install goimports if not already available
$(GOIMPORTS):
@echo "π¦ Installing goimports..."
@go install golang.org/x/tools/cmd/goimports@latest
@echo "β
'goimports' installed successfully."
# Format Go code using gofmt and goimports
format: $(GOIMPORTS)
@echo "π§Ή Formatting Go code..."
@gofmt -s -w .
@$(GOIMPORTS) -w .
@echo "β
Format complete."
# Check that formatting does not introduce changes
check-format: format
@echo "π Checking if formatting is up to date..."
@git diff --quiet || (echo "β Detected uncommitted changes after format. Run 'make format' and commit the result." && git status && exit 1)
@echo "β
All formatted files are up to date."
##################### "make format" support end ##########################
##################### tests support start ##########################
GINKGO := $(GOBIN)/ginkgo
# Exclude agent-v2 from parent tests (it has its own module and runs separately via test-agent-v2 target)
# Use explicit package paths to avoid agent-v2 submodule
UNIT_TEST_PACKAGES := ./cmd/... ./internal/... ./pkg/... ./api/...
UNIT_TEST_GINKGO_OPTIONS ?= --skip e2e --skip-package=agent-v2
# Install ginkgo if not already available
$(GINKGO):
@echo "π¦ Installing ginkgo..."
@go install -v github.com/onsi/ginkgo/v2/ginkgo@v2.22.0
@echo "β
'ginkgo' installed successfully."
.PHONY: test test-agent-v2
# Run unit tests using ginkgo
test: $(GINKGO)
@echo "π§ͺ Running Unit tests..."
@$(GINKGO) --cover -output-dir=. -coverprofile=cover.out -v --show-node-events $(UNIT_TEST_GINKGO_OPTIONS) $(UNIT_TEST_PACKAGES)
@echo "β
All Unit tests passed successfully."
# Run agent-v2 tests separately in its own module context
test-agent-v2: submodules
@echo "π§ͺ Running agent-v2 Unit tests..."
@cd agent-v2 && $(MAKE) test
@echo "β
All agent-v2 Unit tests passed successfully."
# Full unit test cycle: build, prepare DB, run tests, and clean up
unit-test: build kill-db deploy-db migrate test test-agent-v2 kill-db
# Run integration tests using ginkgo
integration-test: $(GINKGO)
@echo "π§ͺ Running integration tests..."
$(GINKGO) -focus=$(FOCUS) run test/e2e
@echo "β
All Integration tests passed successfully."
##################### tests support end ##########################
validate-all: lint check-generate check-format unit-test
# OPA Policies Setup for Local Development
.PHONY: setup-opa-policies
setup-opa-policies:
@echo "Setting up OPA policies for local development..."
@mkdir -p $(MIGRATION_PLANNER_OPA_POLICIES_FOLDER)
@if [ -z "$$(find $(MIGRATION_PLANNER_OPA_POLICIES_FOLDER) -name '*.rego' 2>/dev/null)" ]; then \
echo "Downloading policies from Forklift GitHub repository..."; \
mkdir -p $(FORKLIFT_POLICIES_TMP_DIR); \
curl -L https://github.com/kubev2v/forklift/archive/main.tar.gz \
| tar -xz -C $(FORKLIFT_POLICIES_TMP_DIR) --strip-components=1; \
if [ -d "$(FORKLIFT_POLICIES_TMP_DIR)/validation/policies/io/konveyor/forklift/vmware" ]; then \
find $(FORKLIFT_POLICIES_TMP_DIR)/validation/policies/io/konveyor/forklift/vmware \
-name "*.rego" ! -name "*_test.rego" -exec cp {} $(MIGRATION_PLANNER_OPA_POLICIES_FOLDER)/ \; ; \
echo "Successfully downloaded VMware policies"; \
else \
echo "Failed to download policies from GitHub"; \
exit 1; \
fi; \
rm -rf $(FORKLIFT_POLICIES_TMP_DIR); \
fi
@echo "OPA policies ready in $(MIGRATION_PLANNER_OPA_POLICIES_FOLDER)"
@echo "Found $$(find $(MIGRATION_PLANNER_OPA_POLICIES_FOLDER) -name '*.rego' | wc -l) .rego files"
.PHONY: clean-opa-policies
clean-opa-policies:
@echo "Cleaning OPA policies..."
@rm -rf $(MIGRATION_PLANNER_OPA_POLICIES_FOLDER)
.PHONY: run-sizer
# include the deployment targets
include deploy/deploy.mk
include deploy/e2e.mk
################################################################################
# Emoji Legend for Makefile Targets
#
# Action Type | Emoji | Description
# -------------------|--------|------------------------------------------------
# Install tool π¦ Installing a dependency or binary
# Running task βοΈ Executing tasks like generate, build, etc.
# Linting/validation π Checking format, lint, static analysis, etc.
# Formatting π§Ή Formatting source code
# Tests π§ͺ Running unit or integration tests
# Warnings/info β οΈ Temporary notice, caution, or pre-check
# Success/complete β
Task completed successfully
# Failure/alert β An error or failure occurred
# Deploy operations π Launching or bringing up environments/services
# Teardown/cleanup ποΈ Stopping, removing, or cleaning up resources
################################################################################