forked from migtools/oadp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
567 lines (539 loc) Β· 22.7 KB
/
Makefile
File metadata and controls
567 lines (539 loc) Β· 22.7 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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
# Makefile for OADP CLI
#
# Simple Makefile for building, testing, and installing the OADP CLI
# Variables
BINARY_NAME = kubectl-oadp
INSTALL_PATH ?= $(HOME)/.local/bin
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
VELERO_NAMESPACE ?= openshift-adp
ASSUME_DEFAULT ?= false
# Build information for version command
GIT_SHA := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
GIT_TREE_STATE := $(shell if [ -z "`git status --porcelain 2>/dev/null`" ]; then echo "clean"; else echo "dirty"; fi)
LDFLAGS := -X github.com/vmware-tanzu/velero/pkg/buildinfo.Version=$(VERSION) \
-X github.com/vmware-tanzu/velero/pkg/buildinfo.GitSHA=$(GIT_SHA) \
-X github.com/vmware-tanzu/velero/pkg/buildinfo.GitTreeState=$(GIT_TREE_STATE)
# Centralized platform definitions to avoid duplication
# Matches architectures supported by Kubernetes: https://kubernetes.io/releases/download/#binaries
PLATFORMS = linux/amd64 linux/arm64 linux/ppc64le linux/s390x darwin/amd64 darwin/arm64 windows/amd64 windows/arm64
# Platform variables for multi-arch builds
# Usage: make build PLATFORM=linux/amd64
PLATFORM ?=
GOOS = $(word 1,$(subst /, ,$(PLATFORM)))
GOARCH = $(word 2,$(subst /, ,$(PLATFORM)))
# Default target
.PHONY: help
help: ## Show this help message
@echo "OADP CLI Makefile"
@echo ""
@echo "Available targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "Installation options:"
@echo " \033[36mmake install\033[0m # Install with auto-detection & interactive prompt"
@echo " \033[36mmake install ASSUME_DEFAULT=true\033[0m # Install with default namespace (no detection/prompt)"
@echo " \033[36mmake install VELERO_NAMESPACE=velero\033[0m # Install with custom namespace (no detection/prompt)"
@echo " \033[36mmake install-user\033[0m # Same as install (legacy alias)"
@echo " \033[36mmake install-bin\033[0m # Install to ~/bin (alternative, no sudo)"
@echo " \033[36mmake install-system\033[0m # Install to /usr/local/bin (requires sudo)"
@echo ""
@echo "Uninstall options:"
@echo " \033[36mmake uninstall\033[0m # Remove from user locations (no sudo)"
@echo " \033[36mmake uninstall-system\033[0m # Remove from system locations (requires sudo)"
@echo " \033[36mmake uninstall-all\033[0m # Remove from all locations (user + system)"
@echo ""
@echo "Build with different platforms:"
@echo " make build PLATFORM=linux/amd64"
@echo " make build PLATFORM=linux/arm64"
@echo " make build PLATFORM=linux/ppc64le"
@echo " make build PLATFORM=linux/s390x"
@echo " make build PLATFORM=darwin/amd64"
@echo " make build PLATFORM=darwin/arm64"
@echo " make build PLATFORM=windows/amd64"
@echo " make build PLATFORM=windows/arm64"
@echo ""
@echo "Testing and linting commands:"
@echo " make test # Run all tests (unit + integration)"
@echo " make test-unit # Run unit tests only"
@echo " make test-integration # Run integration tests only"
@echo " make lint # Run golangci-lint checks"
@echo " make lint-fix # Run golangci-lint auto-fix and format code"
@echo ""
@echo "Release commands:"
@echo " make release-build # Build binaries for all platforms"
@echo " make release-archives # Create tar.gz archives for all platforms"
# Build targets
.PHONY: build
build: ## Build the kubectl plugin binary (use PLATFORM=os/arch for cross-compilation)
@if [ -n "$(PLATFORM)" ]; then \
if [ "$(GOOS)" = "windows" ]; then \
binary_suffix=".exe"; \
else \
binary_suffix=""; \
fi; \
echo "Building $(BINARY_NAME) for $(PLATFORM)..."; \
GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags "$(LDFLAGS)" -o $(BINARY_NAME)-$(GOOS)-$(GOARCH)$$binary_suffix .; \
echo "β
Built $(BINARY_NAME)-$(GOOS)-$(GOARCH)$$binary_suffix successfully!"; \
else \
GOOS=$$(go env GOOS); \
if [ "$$GOOS" = "windows" ]; then \
binary_name="$(BINARY_NAME).exe"; \
else \
binary_name="$(BINARY_NAME)"; \
fi; \
echo "Building $$binary_name for current platform ($$GOOS/$$(go env GOARCH))..."; \
go build -ldflags "$(LDFLAGS)" -o $$binary_name .; \
echo "β
Built $$binary_name successfully!"; \
fi
# Installation targets
.PHONY: install
install: build ## Build and install the kubectl plugin to ~/.local/bin (no sudo required)
@GOOS=$$(go env GOOS); \
if [ "$$GOOS" = "" ]; then \
echo "Error: GOOS is not set"; \
exit 1; \
fi; \
if [ "$$GOOS" = "windows" ]; then \
binary_name="$(BINARY_NAME).exe"; \
else \
binary_name="$(BINARY_NAME)"; \
fi; \
echo "Installing $$binary_name to $(INSTALL_PATH)..."; \
mkdir -p $(INSTALL_PATH); \
cp $$binary_name $(INSTALL_PATH)/
@echo "β
Installed to $(INSTALL_PATH)"
@echo ""
@echo "π Checking PATH configuration..."
@PATH_NEEDS_UPDATE=false; \
PATH_UPDATED=false; \
PATH_IN_CONFIG=false; \
CURRENT_SESSION_NEEDS_UPDATE=false; \
\
if [[ ":$$PATH:" != *":$(INSTALL_PATH):"* ]]; then \
PATH_NEEDS_UPDATE=true; \
CURRENT_SESSION_NEEDS_UPDATE=true; \
echo " ββ β οΈ $(INSTALL_PATH) is not in your current PATH"; \
\
if [[ "$$SHELL" == */zsh* ]] && [[ -f "$$HOME/.zshrc" ]]; then \
if ! grep -q '^[[:space:]]*export[[:space:]]*PATH.*\.local/bin' "$$HOME/.zshrc" 2>/dev/null; then \
echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> "$$HOME/.zshrc"; \
echo " ββ β
Added PATH export to ~/.zshrc"; \
PATH_UPDATED=true; \
else \
echo " ββ βΉοΈ PATH export already exists in ~/.zshrc"; \
PATH_IN_CONFIG=true; \
fi; \
elif [[ "$$SHELL" == */bash* ]] && [[ -f "$$HOME/.bashrc" ]]; then \
if ! grep -q '^[[:space:]]*export[[:space:]]*PATH.*\.local/bin' "$$HOME/.bashrc" 2>/dev/null; then \
echo 'export PATH="$$HOME/.local/bin:$$PATH"' >> "$$HOME/.bashrc"; \
echo " ββ β
Added PATH export to ~/.bashrc"; \
PATH_UPDATED=true; \
else \
echo " ββ βΉοΈ PATH export already exists in ~/.bashrc"; \
PATH_IN_CONFIG=true; \
fi; \
else \
echo " ββ β οΈ Unsupported shell or config file not found"; \
echo " β ββ Manually add to your shell config: export PATH=\"$(INSTALL_PATH):$$PATH\""; \
PATH_UPDATED=true; \
fi; \
else \
echo " ββ β
$(INSTALL_PATH) is already in PATH"; \
fi; \
\
echo ""; \
if [[ "$$CURRENT_SESSION_NEEDS_UPDATE" == "true" ]]; then \
echo "π§ To use kubectl oadp in this terminal session:"; \
echo " ββ export PATH=\"$(INSTALL_PATH):$$PATH\""; \
echo ""; \
echo "π For future sessions:"; \
if [[ "$$PATH_UPDATED" == "true" ]]; then \
echo " ββ Restart your terminal or run: source ~/.zshrc"; \
elif [[ "$$PATH_IN_CONFIG" == "true" ]]; then \
echo " ββ Restart your terminal or run: source ~/.zshrc"; \
echo " ββ (PATH export exists but may need shell restart)"; \
else \
echo " ββ Add the PATH export to your shell configuration file"; \
fi; \
fi; \
echo ""; \
echo "π Configuration:"; \
NAMESPACE=$(VELERO_NAMESPACE); \
DETECTED=false; \
if [[ "$(ASSUME_DEFAULT)" != "true" && "$(VELERO_NAMESPACE)" == "openshift-adp" ]]; then \
echo ""; \
echo " π Detecting OADP deployment in cluster..."; \
DETECTED_NS=$$(kubectl get deployments --all-namespaces -o jsonpath='{.items[?(@.metadata.name=="openshift-adp-controller-manager")].metadata.namespace}' 2>/dev/null | head -1); \
if [[ -n "$$DETECTED_NS" ]]; then \
echo " ββ β
Found OADP controller in namespace: $$DETECTED_NS"; \
NAMESPACE=$$DETECTED_NS; \
DETECTED=true; \
else \
echo " ββ β οΈ Could not find openshift-adp-controller-manager deployment"; \
fi; \
echo ""; \
echo " π Looking for DataProtectionApplication (DPA) resources..."; \
DETECTED_NS=$$(kubectl get dataprotectionapplication --all-namespaces -o jsonpath='{.items[0].metadata.namespace}' 2>/dev/null | head -1); \
if [[ -n "$$DETECTED_NS" ]]; then \
echo " ββ β
Found DPA resource in namespace: $$DETECTED_NS"; \
NAMESPACE=$$DETECTED_NS; \
DETECTED=true; \
else \
echo " ββ β οΈ Could not find DataProtectionApplication resources"; \
fi; \
if [[ "$$DETECTED" == "false" ]]; then \
echo ""; \
echo " β οΈ β οΈ β οΈ"; \
echo " ββ β OADP Operator is not detected in the cluster"; \
echo " ββ Fallback will check for Velero deployment as fallback"; \
echo " ββ Consider using the velero cli instead"; \
echo " β οΈ β οΈ β οΈ"; \
echo ""; \
echo " π Looking for Velero deployment as fallback..."; \
DETECTED_NS=$$(kubectl get deployments --all-namespaces -o jsonpath='{.items[?(@.metadata.name=="velero")].metadata.namespace}' 2>/dev/null | head -1); \
if [[ -n "$$DETECTED_NS" ]]; then \
echo " ββ β
Found Velero deployment in namespace: $$DETECTED_NS"; \
NAMESPACE=$$DETECTED_NS; \
DETECTED=true; \
else \
echo " ββ β οΈ Could not detect OADP or Velero deployment in cluster"; \
fi; \
fi; \
if [[ "$$DETECTED" == "false" ]]; then \
echo " π€ Which namespace should admin commands use for Velero resources?"; \
echo " β ββ (Common options: openshift-adp, velero, oadp)"; \
echo ""; \
printf " Enter namespace [default: $(VELERO_NAMESPACE)]: "; \
read -r user_input; \
if [[ -n "$$user_input" ]]; then \
NAMESPACE=$$user_input; \
fi; \
fi; \
echo ""; \
fi; \
echo " ββ Setting Velero namespace to: $$NAMESPACE"; \
GOOS=$$(go env GOOS); \
if [ "$$GOOS" = "windows" ]; then \
binary_name="$(BINARY_NAME).exe"; \
else \
binary_name="$(BINARY_NAME)"; \
fi; \
$(INSTALL_PATH)/$$binary_name client config set namespace=$$NAMESPACE 2>/dev/null || true; \
echo " ββ β
Client config initialized"; \
echo ""; \
echo "π§ͺ Verifying installation..."; \
if [[ "$$CURRENT_SESSION_NEEDS_UPDATE" == "true" ]]; then \
echo " ββ Temporarily updating PATH for verification"; \
if PATH="$(INSTALL_PATH):$$PATH" command -v kubectl >/dev/null 2>&1; then \
if PATH="$(INSTALL_PATH):$$PATH" kubectl plugin list 2>/dev/null | grep -q "kubectl-oadp"; then \
echo " ββ β
Installation verified: kubectl oadp plugin is accessible"; \
echo ""; \
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"; \
echo "π Installation complete!"; \
echo ""; \
echo " β οΈ To use in this terminal session, run:"; \
echo " export PATH=\"$(INSTALL_PATH):$$PATH\""; \
echo ""; \
echo " Quick start:"; \
echo " β’ oc oadp --help # Show available commands"; \
echo " β’ oc oadp backup get # List backups"; \
else \
echo " ββ β Installation verification failed: kubectl oadp plugin not found"; \
echo " β ββ Try running: export PATH=\"$(INSTALL_PATH):$$PATH\""; \
fi; \
else \
echo " ββ β οΈ kubectl not found - cannot verify plugin accessibility"; \
echo " ββ Plugin installed to: $(INSTALL_PATH)/$$binary_name"; \
fi; \
else \
if command -v kubectl >/dev/null 2>&1; then \
if kubectl plugin list 2>/dev/null | grep -q "kubectl-oadp"; then \
echo " ββ β
Installation verified: kubectl oadp plugin is accessible"; \
echo " ββ Running version command..."; \
echo ""; \
version_output=$$(kubectl oadp version 2>&1 | grep -v "WARNING: the client version does not match"); \
if [ $$? -eq 0 ] && [ -n "$$version_output" ]; then \
echo "$$version_output" | sed 's/^/ /'; \
else \
echo " (Note: version command requires cluster access)"; \
fi; \
echo ""; \
echo "βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ"; \
echo "π Installation complete!"; \
echo ""; \
echo " Quick start:"; \
echo " β’ oc oadp --help # Show available commands"; \
echo " β’ oc oadp backup get # List backups"; \
echo " β’ oc oadp version # Show version info"; \
else \
echo " ββ β Installation verification failed: kubectl oadp plugin not found"; \
fi; \
else \
echo " ββ β οΈ kubectl not found - cannot verify plugin accessibility"; \
echo " ββ Plugin installed to: $(INSTALL_PATH)/$$binary_name"; \
fi; \
fi; \
.PHONY: install-user
install-user: build ## Build and install the kubectl plugin to ~/.local/bin (no sudo required)
@echo "Installing $(BINARY_NAME) to ~/.local/bin..."
@mkdir -p ~/.local/bin
cp $(BINARY_NAME) ~/.local/bin/
@echo "β
Installed to ~/.local/bin"
@echo "Add to PATH: export PATH=\"\$$HOME/.local/bin:\$$PATH\""
@echo "Test: oc oadp --help"
.PHONY: install-bin
install-bin: build ## Build and install the kubectl plugin to ~/bin (no sudo required)
@echo "Installing $(BINARY_NAME) to ~/bin..."
@mkdir -p ~/bin
cp $(BINARY_NAME) ~/bin/
@echo "β
Installed to ~/bin"
@echo "Add to PATH: export PATH=\"\$$HOME/bin:\$$PATH\""
@echo "Test: oc oadp --help"
.PHONY: install-system
install-system: build ## Build and install the kubectl plugin to /usr/local/bin (requires sudo)
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
@sudo mv $(BINARY_NAME) /usr/local/bin/
@echo "β
Installed to /usr/local/bin"
@echo "Test: oc oadp --help"
.PHONY: uninstall
uninstall: ## Uninstall the kubectl plugin from user locations
@echo "Removing $(BINARY_NAME) from user locations..."
@removed=false; \
if [ -f "$(INSTALL_PATH)/$(BINARY_NAME)" ]; then \
rm -f "$(INSTALL_PATH)/$(BINARY_NAME)"; \
echo "β
Removed from $(INSTALL_PATH)"; \
removed=true; \
fi; \
if [ -f "$$HOME/.local/bin/$(BINARY_NAME)" ] && [ "$(INSTALL_PATH)" != "$$HOME/.local/bin" ]; then \
rm -f "$$HOME/.local/bin/$(BINARY_NAME)"; \
echo "β
Removed from ~/.local/bin"; \
removed=true; \
fi; \
if [ -f "$$HOME/bin/$(BINARY_NAME)" ] && [ "$(INSTALL_PATH)" != "$$HOME/bin" ]; then \
rm -f "$$HOME/bin/$(BINARY_NAME)"; \
echo "β
Removed from ~/bin"; \
removed=true; \
fi; \
if [ "$$removed" = "false" ]; then \
echo "β οΈ Not found in user locations"; \
fi
.PHONY: uninstall-system
uninstall-system: ## Uninstall the kubectl plugin from system locations (requires sudo)
@echo "Removing $(BINARY_NAME) from system locations..."
@removed=false; \
if [ -f "/usr/local/bin/$(BINARY_NAME)" ]; then \
sudo rm -f "/usr/local/bin/$(BINARY_NAME)"; \
echo "β
Removed from /usr/local/bin"; \
removed=true; \
fi; \
if [ -f "/usr/bin/$(BINARY_NAME)" ]; then \
sudo rm -f "/usr/bin/$(BINARY_NAME)"; \
echo "β
Removed from /usr/bin"; \
removed=true; \
fi; \
if [ "$$removed" = "false" ]; then \
echo "β οΈ Not found in system locations"; \
fi
.PHONY: uninstall-all
uninstall-all: ## Uninstall the kubectl plugin from all locations (user + system)
@make --no-print-directory uninstall
@make --no-print-directory uninstall-system
# Local binary directory for development tools
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
# Tool versions
GOLANGCI_LINT_VERSION ?= v2.11.0
# Tool binaries
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
# golangci-lint installation
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary
$(GOLANGCI_LINT): $(LOCALBIN)
@if [ -f $(GOLANGCI_LINT) ] && $(GOLANGCI_LINT) version 2>&1 | grep -q $(GOLANGCI_LINT_VERSION); then \
echo "golangci-lint $(GOLANGCI_LINT_VERSION) is already installed"; \
else \
echo "Installing golangci-lint $(GOLANGCI_LINT_VERSION)"; \
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) $(GOLANGCI_LINT_VERSION); \
fi
# Testing targets
.PHONY: test
test: ## Run all tests
@echo "Running tests..."
@echo "π§ͺ Running unit tests..."
go test ./cmd/... ./internal/...
@echo "π Running integration tests..."
go test . -v
@echo "β
Tests completed!"
.PHONY: test-unit
test-unit: ## Run unit tests only
@echo "Running unit tests..."
go test ./cmd/... ./internal/...
@echo "β
Unit tests completed!"
.PHONY: test-integration
test-integration: ## Run integration tests only
@echo "Running integration tests..."
go test . -v
@echo "β
Integration tests completed!"
.PHONY: lint
lint: golangci-lint ## Run golangci-lint checks against all project's Go files
$(GOLANGCI_LINT) run ./...
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint auto-fix and format code
@echo "Running golangci-lint with auto-fix..."
$(GOLANGCI_LINT) run --fix ./...
@echo "Running go fmt..."
go fmt ./...
@echo "β
Linting and formatting complete!"
# Cleanup targets
.PHONY: clean
clean: ## Remove built binaries and downloaded tools
@echo "Cleaning up..."
@rm -f $(BINARY_NAME) $(BINARY_NAME).exe $(BINARY_NAME)-linux-* $(BINARY_NAME)-darwin-* $(BINARY_NAME)-windows-*
@rm -f *.tar.gz *.sha256
@rm -f oadp-*.yaml oadp-*.yaml.tmp
@rm -rf $(LOCALBIN)
@echo "β
Cleanup complete!"
# Status and utility targets
.PHONY: status
status: ## Show build status and installation info
@echo "=== OADP CLI Status ==="
@echo ""
@echo "π Repository:"
@pwd
@echo ""
@echo "π§ Local binary:"
@ls -la $(BINARY_NAME) 2>/dev/null || echo " No local binary found"
@echo ""
@echo "π¦ Installed plugin:"
@ls -la $(INSTALL_PATH)/$(BINARY_NAME) 2>/dev/null || echo " Plugin not installed"
@echo ""
@echo "β
Plugin accessibility:"
@if kubectl plugin list 2>/dev/null | grep -q "kubectl-oadp"; then \
echo " β
kubectl-oadp plugin is installed and accessible"; \
echo " Version check:"; \
kubectl oadp version 2>/dev/null || echo " (version command not available)"; \
else \
echo " β kubectl-oadp plugin is NOT accessible"; \
echo " Available plugins:"; \
kubectl plugin list 2>/dev/null | head -5 || echo " (no plugins found or kubectl not available)"; \
fi
# Optimized release targets with centralized platform logic
.PHONY: release-build
release-build: ## Build binaries for all platforms
@echo "Building release binaries for all platforms..."
@for platform in $(PLATFORMS); do \
GOOS=$$(echo $$platform | cut -d'/' -f1); \
GOARCH=$$(echo $$platform | cut -d'/' -f2); \
if [ -n "$(VERSION)" ]; then \
version_suffix="_$(VERSION)"; \
else \
version_suffix=""; \
fi; \
if [ "$$GOOS" = "windows" ]; then \
output_name="$(BINARY_NAME)$${version_suffix}_$${GOOS}_$${GOARCH}.exe"; \
else \
output_name="$(BINARY_NAME)$${version_suffix}_$${GOOS}_$${GOARCH}"; \
fi; \
echo "Building $$output_name..."; \
GOOS=$$GOOS GOARCH=$$GOARCH go build -ldflags "$(LDFLAGS)" -o $$output_name .; \
echo "β
Built $$output_name"; \
done
@echo "β
All release binaries created successfully!"
.PHONY: release-archives
release-archives: release-build ## Create tar.gz archives with SHA256 checksums for all platforms
@echo "Creating tar.gz archives with simple binary names..."
@if [ ! -f LICENSE ]; then \
echo "β LICENSE file not found! Please ensure LICENSE file exists."; \
exit 1; \
fi
@for platform in $(PLATFORMS); do \
GOOS=$$(echo $$platform | cut -d'/' -f1); \
GOARCH=$$(echo $$platform | cut -d'/' -f2); \
if [ -n "$(VERSION)" ]; then \
version_suffix="_$(VERSION)"; \
else \
version_suffix=""; \
fi; \
if [ "$$GOOS" = "windows" ]; then \
platform_binary="$(BINARY_NAME)$${version_suffix}_$${GOOS}_$${GOARCH}.exe"; \
simple_binary="$(BINARY_NAME).exe"; \
else \
platform_binary="$(BINARY_NAME)$${version_suffix}_$${GOOS}_$${GOARCH}"; \
simple_binary="$(BINARY_NAME)"; \
fi; \
archive_name="$(BINARY_NAME)_$(VERSION)_$${GOOS}_$${GOARCH}.tar.gz"; \
echo "Creating $$archive_name..."; \
cp $$platform_binary $$simple_binary; \
tar czf $$archive_name LICENSE $$simple_binary; \
rm $$simple_binary; \
echo "β
Created $$archive_name"; \
done
@echo ""
@echo "Generating SHA256 checksums..."
@for platform in $(PLATFORMS); do \
GOOS=$$(echo $$platform | cut -d'/' -f1); \
GOARCH=$$(echo $$platform | cut -d'/' -f2); \
archive_name="$(BINARY_NAME)_$(VERSION)_$${GOOS}_$${GOARCH}.tar.gz"; \
sha256sum $$archive_name > $$archive_name.sha256; \
echo "β
Generated checksum for $$archive_name"; \
done
@echo "β
All SHA256 checksums generated!"
@echo "π¦ Archives created:"
@ls -la *.tar.gz
@echo "π SHA256 checksums:"
@ls -la *.sha256
.PHONY: release
release: release-archives ## Build and create release archives for all platforms
@echo "π Release build complete! Archives ready for distribution."
# Optimized krew-manifest generation using Python script for better reliability
.PHONY: krew-manifest
krew-manifest: release-archives ## Generate Krew plugin manifest with SHA256 checksums
@echo "Generating Krew plugin manifest with SHA256 checksums..."
@if [ ! -f oadp.yaml ]; then \
echo "β oadp.yaml manifest template not found!"; \
exit 1; \
fi
@python3 -c " \
import sys, re, os; \
version = '$(VERSION)'; \
platforms = [p.split('/') for p in '$(PLATFORMS)'.split()]; \
\
with open('oadp.yaml', 'r') as f: \
content = f.read(); \
\
content = re.sub(r'version: v1\.0\.0', f'version: {version}', content); \
content = re.sub(r'download/v1\.0\.0/', f'download/{version}/', content); \
\
for goos, goarch in platforms: \
binary_suffix = '.exe' if goos == 'windows' else ''; \
sha_file = f'kubectl-oadp_${VERSION}_{goos}_{goarch}.tar.gz.sha256'; \
if os.path.exists(sha_file): \
with open(sha_file, 'r') as sf: \
sha256 = sf.read().split()[0]; \
pattern = rf'(os: {goos}.*?arch: {goarch}.*?sha256: \")\"'; \
replacement = rf'\g<1>{sha256}\"'; \
content = re.sub(pattern, replacement, content, flags=re.DOTALL); \
print(f' β
{goos}/{goarch}: {sha256}'); \
\
with open(f'oadp-{version}.yaml', 'w') as f: \
f.write(content); \
print(f'β
Krew manifest generated: oadp-{version}.yaml'); \
" 2>/dev/null || { \
echo "β οΈ Python3 not available, using fallback sed approach..."; \
cp oadp.yaml oadp-$(VERSION).yaml; \
# Use portable sed approach (works on both BSD/macOS and GNU/Linux) \
sed "s/version: v1.0.0/version: $(VERSION)/" oadp-$(VERSION).yaml > oadp-$(VERSION).yaml.tmp && mv oadp-$(VERSION).yaml.tmp oadp-$(VERSION).yaml; \
sed "s|download/v1.0.0/|download/$(VERSION)/|g" oadp-$(VERSION).yaml > oadp-$(VERSION).yaml.tmp && mv oadp-$(VERSION).yaml.tmp oadp-$(VERSION).yaml; \
for platform in $(PLATFORMS); do \
GOOS=$$(echo $$platform | cut -d'/' -f1); \
GOARCH=$$(echo $$platform | cut -d'/' -f2); \
sha_file="kubectl-oadp_${VERSION}_$$GOOS_$$GOARCH.tar.gz.sha256"; \
if [ -f "$$sha_file" ]; then \
sha256=$$(cat $$sha_file | cut -d' ' -f1); \
echo " β
$$GOOS/$$GOARCH: $$sha256"; \
fi; \
done; \
echo "β οΈ SHA256 checksums need manual update in oadp-$(VERSION).yaml"; \
}
@echo "π Review the manifest and update the GitHub release URLs as needed."