-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
241 lines (192 loc) · 7.53 KB
/
Makefile
File metadata and controls
241 lines (192 loc) · 7.53 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
# dk Makefile
# Multi-module Go workspace build system
# Install destination for `make install`. Override with:
# make install DESTDIR=/usr/local/bin
DESTDIR ?= $(HOME)/go/bin
# Version is derived from the latest git tag; used by install and release targets.
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
LDFLAGS := -ldflags "-X github.com/Infoblox-CTO/platform.data.kit/cli/cmd.Version=$(VERSION)"
.PHONY: all build test lint clean help
.PHONY: build-contracts build-sdk build-cli build-controller
.PHONY: test-contracts test-sdk test-cli test-controller
.PHONY: lint-contracts lint-sdk lint-cli lint-controller
.PHONY: tidy install run-local
.PHONY: helm-deps
# Default target
all: lint test build
##@ Build
build: build-contracts build-sdk build-cli build-controller ## Build all modules
@echo "✓ All modules built successfully"
build-contracts:
@echo "Building contracts..."
@cd contracts && go build ./...
build-sdk:
@echo "Building sdk..."
@cd sdk && go build ./...
build-cli: ## Build CLI binary
@echo "Building cli $(VERSION)..."
@cd cli && go build $(LDFLAGS) -o ../bin/dk .
build-controller: ## Build controller binary
@echo "Building controller..."
@cd platform/controller && go build -o ../../bin/controller ./cmd/
##@ Test
test: test-contracts test-sdk test-cli test-controller ## Run all tests
@echo "✓ All tests passed"
test-unit: test-contracts test-sdk test-cli test-controller ## Run unit tests only
@echo "✓ All unit tests passed"
test-e2e: ## Run E2E tests
@echo "Running E2E tests..."
@cd tests/e2e && go test -v ./...
@echo "✓ E2E tests passed"
test-integration: ## Run integration tests (requires Docker)
@echo "Running integration tests..."
@cd sdk && go test -v -tags integration ./promotion/...
@echo "✓ Integration tests passed"
test-e2e-promote: ## Run promotion E2E tests (requires Docker)
@echo "Running promotion E2E tests..."
@cd tests/e2e && go test -v -run TestPromote ./...
@echo "✓ Promotion E2E tests passed"
test-short: ## Run short tests (skip E2E)
@echo "Running short tests (skipping E2E)..."
@cd contracts && go test -short ./...
@cd sdk && go test -short ./...
@cd cli && go test -short ./...
@cd platform/controller && go test -short ./...
@echo "✓ Short tests passed"
test-race: ## Run tests with race detector
@echo "Running tests with race detector..."
@cd contracts && go test -race ./...
@cd sdk && go test -race ./...
@cd cli && go test -race ./...
@cd platform/controller && go test -race ./...
@echo "✓ Race detection tests passed"
test-contracts:
@echo "Testing contracts..."
@cd contracts && go test -race ./...
test-sdk:
@echo "Testing sdk..."
@cd sdk && go test -race ./...
test-cli:
@echo "Testing cli..."
@cd cli && go test -race ./...
test-controller:
@echo "Testing controller..."
@cd platform/controller && go test -race ./...
coverage: ## Generate coverage reports
@mkdir -p coverage
@cd contracts && go test -coverprofile=../coverage/contracts.out ./...
@cd sdk && go test -coverprofile=../coverage/sdk.out ./...
@cd cli && go test -coverprofile=../coverage/cli.out ./...
@cd platform/controller && go test -coverprofile=../../coverage/controller.out ./...
@echo "Coverage reports generated in coverage/"
test-coverage: coverage ## Display coverage summary
@echo "Coverage summary:"
@go tool cover -func=coverage/contracts.out | grep total || true
@go tool cover -func=coverage/sdk.out | grep total || true
@go tool cover -func=coverage/cli.out | grep total || true
@go tool cover -func=coverage/controller.out | grep total || true
##@ Lint
lint: lint-contracts lint-sdk lint-cli lint-controller ## Run linting on all modules
@echo "✓ All linting passed"
lint-contracts:
@echo "Linting contracts..."
@cd contracts && go vet ./... && go fmt ./...
lint-sdk:
@echo "Linting sdk..."
@cd sdk && go vet ./... && go fmt ./...
lint-cli:
@echo "Linting cli..."
@cd cli && go vet ./... && go fmt ./...
lint-controller:
@echo "Linting controller..."
@cd platform/controller && go vet ./... && go fmt ./...
##@ Development
tidy: ## Tidy all go.mod files
@echo "Tidying modules..."
@cd contracts && go mod tidy
@cd sdk && go mod tidy
@cd cli && go mod tidy
@cd platform/controller && go mod tidy
install: ## Install dk to DESTDIR (default: ~/go/bin)
@echo "Installing dk $(VERSION) to $(DESTDIR)..."
@mkdir -p $(DESTDIR)
@cd cli && go build $(LDFLAGS) -o $(DESTDIR)/dk .
@echo "✓ Installed dk $(VERSION) to $(DESTDIR)/dk"
run-local: ## Start local dev stack
@echo "Starting local development stack..."
@cd cli && go run . dev up
@echo "✓ Local stack running"
stop-local: ## Stop local dev stack
@echo "Stopping local development stack..."
@cd cli && go run . dev down
@echo "✓ Local stack stopped"
##@ Helm
publish-chart: ## Publish shared dk-app chart to OCI registry
@echo "Publishing dk-app chart..."
@helm package gitops/charts/dk-app -d dist/
@helm push dist/dk-app-*.tgz oci://ghcr.io/infoblox-cto/dk/charts
@echo "✓ dk-app chart published"
helm-deps: ## Build Helm chart dependencies
@echo "Building Helm chart dependencies..."
@for chart in sdk/localdev/charts/redpanda sdk/localdev/charts/postgres; do \
if [ -f "$$chart/Chart.yaml" ] && grep -q "dependencies:" "$$chart/Chart.yaml"; then \
echo " Building deps for $$(basename $$chart)..."; \
helm dependency build "$$chart"; \
fi; \
done
@echo "✓ Helm chart dependencies built"
##@ Code Generation
generate: ## Run go generate
@echo "Generating code..."
@cd platform/controller && go generate ./...
manifests: ## Generate CRD manifests
@echo "Generating CRD manifests..."
@cd platform/controller && controller-gen crd paths="./..." output:crd:artifacts:config=config/crd
##@ Release
release-cli: ## Build release CLI binaries
@echo "Building release CLI $(VERSION)..."
@cd cli && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o ../bin/dk-linux-amd64 .
@cd cli && CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(LDFLAGS) -o ../bin/dk-linux-arm64 .
@cd cli && CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o ../bin/dk-darwin-amd64 .
@cd cli && CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o ../bin/dk-darwin-arm64 .
@echo "✓ Release binaries in bin/"
release-controller: ## Build controller Docker image
@echo "Building controller image..."
@docker build -t cdpp-controller:$(VERSION) -f platform/controller/Dockerfile .
@echo "✓ Controller image built"
##@ Cleanup
clean: ## Remove build artifacts and Go build cache
@echo "Cleaning build artifacts..."
@rm -rf bin/
@rm -rf coverage/
@rm -rf dist/
@find . -name "*.test" -delete
@find . -name "*.out" -delete
@go clean -cache
@echo "✓ Clean complete (including Go build cache)"
##@ Help
# ANSI color codes
# Disabled automatically in CI (GitHub Actions, Jenkins, GitLab, Travis, CircleCI)
# or when NO_COLOR=1 is set (see https://no-color.org)
CI_DETECTED := $(or $(NO_COLOR),$(CI),$(GITHUB_ACTIONS),$(JENKINS_URL),$(BUILD_NUMBER),$(GITLAB_CI),$(TRAVIS),$(CIRCLECI))
ifdef CI_DETECTED
C_RESET :=
C_BOLD :=
C_CYAN :=
C_GREEN :=
C_YELLOW :=
C_DIM :=
else
C_RESET := \033[0m
C_BOLD := \033[1m
C_CYAN := \033[36m
C_GREEN := \033[32m
C_YELLOW := \033[33m
C_DIM := \033[2m
endif
help: ## Show this help
@printf "$(C_BOLD)Data Kit Build System$(C_RESET)\n\n"
@printf "$(C_DIM)Usage:$(C_RESET) make $(C_CYAN)<target>$(C_RESET)\n"
@awk 'BEGIN {FS = ":.*## "} \
/^##@/ { printf "\n$(C_YELLOW)%s$(C_RESET)\n", substr($$0, 5); next } \
/^[a-zA-Z_0-9-]+:.*## / { printf " $(C_GREEN)%-20s$(C_RESET) %s\n", $$1, $$2 }' $(MAKEFILE_LIST)