Skip to content

Commit 24e730c

Browse files
committed
Add Makefile
1 parent 437b4aa commit 24e730c

4 files changed

Lines changed: 237 additions & 17 deletions

File tree

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.exe~
4+
*.dll
5+
*.so
6+
*.dylib
7+
8+
# Built binaries
9+
kubectl-oadp
10+
oadp
11+
12+
# Test binary, built with `go test -c`
13+
*.test
14+
15+
# Output of the go coverage tool, specifically when used with LiteIDE
16+
*.out
17+
18+
# Go workspace file
19+
go.work
20+
21+
# IDE files
22+
.vscode/
23+
.idea/
24+
*.swp
25+
*.swo
26+
*~
27+
28+
# OS generated files
29+
.DS_Store
30+
.DS_Store?
31+
._*
32+
.Spotlight-V100
33+
.Trashes
34+
ehthumbs.db
35+
Thumbs.db

Makefile

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# Makefile for OADP CLI
2+
#
3+
# This Makefile provides convenient targets for building, testing, and installing
4+
# the OADP CLI as a kubectl plugin.
5+
6+
# Variables
7+
BINARY_NAME = kubectl-oadp
8+
LOCAL_BINARY = oadp
9+
INSTALL_PATH = /usr/local/bin
10+
GO_FILES = $(shell find . -name '*.go' -not -path './vendor/*')
11+
12+
# Default target
13+
.PHONY: help
14+
help: ## Show this help message
15+
@echo "OADP CLI Makefile"
16+
@echo ""
17+
@echo "Available targets:"
18+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
19+
20+
# Build targets
21+
.PHONY: build
22+
build: ## Build the CLI binary for local development
23+
@echo "Building $(LOCAL_BINARY) for local development..."
24+
go build -o $(LOCAL_BINARY) .
25+
@echo "✅ Built $(LOCAL_BINARY) successfully!"
26+
27+
.PHONY: build-plugin
28+
build-plugin: ## Build the kubectl plugin binary
29+
@echo "Building $(BINARY_NAME) kubectl plugin..."
30+
go build -o $(BINARY_NAME) .
31+
@echo "✅ Built $(BINARY_NAME) successfully!"
32+
33+
# Installation targets
34+
.PHONY: install
35+
install: build-plugin ## Build and install the kubectl plugin (requires sudo)
36+
@echo "Installing $(BINARY_NAME) to $(INSTALL_PATH)..."
37+
sudo mv $(BINARY_NAME) $(INSTALL_PATH)/
38+
@echo "$(BINARY_NAME) plugin installed successfully!"
39+
@echo "You can now use: kubectl oadp --help"
40+
41+
.PHONY: install-local
42+
install-local: build-plugin ## Install the kubectl plugin to ~/bin (no sudo required)
43+
@echo "Installing $(BINARY_NAME) to ~/bin..."
44+
@mkdir -p ~/bin
45+
mv $(BINARY_NAME) ~/bin/
46+
@echo "$(BINARY_NAME) plugin installed to ~/bin!"
47+
@echo "Make sure ~/bin is in your PATH"
48+
@echo "You can now use: kubectl oadp --help"
49+
50+
# Testing targets
51+
.PHONY: test
52+
test: ## Run all tests
53+
@echo "Running tests..."
54+
go test ./...
55+
@echo "✅ All tests passed!"
56+
57+
.PHONY: test-verbose
58+
test-verbose: ## Run tests with verbose output
59+
@echo "Running tests with verbose output..."
60+
go test -v ./...
61+
62+
.PHONY: test-coverage
63+
test-coverage: ## Run tests with coverage report
64+
@echo "Running tests with coverage..."
65+
go test -cover ./...
66+
67+
# Development targets
68+
.PHONY: fmt
69+
fmt: ## Format Go code
70+
@echo "Formatting Go code..."
71+
go fmt ./...
72+
@echo "✅ Code formatted!"
73+
74+
.PHONY: vet
75+
vet: ## Run go vet
76+
@echo "Running go vet..."
77+
go vet ./...
78+
@echo "✅ Vet checks passed!"
79+
80+
.PHONY: mod-tidy
81+
mod-tidy: ## Tidy up go.mod
82+
@echo "Tidying go.mod..."
83+
go mod tidy
84+
@echo "✅ Dependencies tidied!"
85+
86+
.PHONY: check
87+
check: fmt vet test ## Run formatting, vetting, and tests
88+
89+
# Cleanup targets
90+
.PHONY: clean
91+
clean: ## Remove built binaries
92+
@echo "Cleaning up built binaries..."
93+
@rm -f $(BINARY_NAME) $(LOCAL_BINARY)
94+
@echo "✅ Cleanup complete!"
95+
96+
.PHONY: uninstall
97+
uninstall: ## Remove the installed kubectl plugin
98+
@echo "Removing $(BINARY_NAME) from $(INSTALL_PATH)..."
99+
@sudo rm -f $(INSTALL_PATH)/$(BINARY_NAME)
100+
@echo "$(BINARY_NAME) plugin uninstalled!"
101+
102+
.PHONY: uninstall-local
103+
uninstall-local: ## Remove the kubectl plugin from ~/bin
104+
@echo "Removing $(BINARY_NAME) from ~/bin..."
105+
@rm -f ~/bin/$(BINARY_NAME)
106+
@echo "$(BINARY_NAME) plugin uninstalled from ~/bin!"
107+
108+
# Utility targets
109+
.PHONY: verify-install
110+
verify-install: ## Verify the kubectl plugin is installed and working
111+
@echo "Verifying kubectl plugin installation..."
112+
@if command -v kubectl oadp >/dev/null 2>&1; then \
113+
echo "✅ kubectl oadp plugin is installed and accessible!"; \
114+
kubectl oadp --help | head -5; \
115+
else \
116+
echo "❌ kubectl oadp plugin not found in PATH"; \
117+
exit 1; \
118+
fi
119+
120+
.PHONY: dev-setup
121+
dev-setup: mod-tidy fmt vet build ## Set up development environment
122+
@echo "✅ Development environment ready!"
123+
124+
# File watching (requires 'entr' tool)
125+
.PHONY: watch
126+
watch: ## Watch for changes and rebuild (requires 'entr' tool)
127+
@if command -v entr >/dev/null 2>&1; then \
128+
echo "Watching for changes... (press Ctrl+C to stop)"; \
129+
find . -name '*.go' | entr -r make build; \
130+
else \
131+
echo "❌ 'entr' tool not found. Install with: brew install entr (macOS) or apt install entr (Ubuntu)"; \
132+
exit 1; \
133+
fi
134+
135+
# Show current status
136+
.PHONY: status
137+
status: ## Show build status and installed version
138+
@echo "=== OADP CLI Status ==="
139+
@echo ""
140+
@echo "📁 Repository:"
141+
@pwd
142+
@echo ""
143+
@echo "🔧 Local binaries:"
144+
@ls -la $(LOCAL_BINARY) $(BINARY_NAME) 2>/dev/null || echo " No local binaries found"
145+
@echo ""
146+
@echo "📦 Installed plugin:"
147+
@ls -la $(INSTALL_PATH)/$(BINARY_NAME) 2>/dev/null || echo " Plugin not installed in $(INSTALL_PATH)"
148+
@ls -la ~/bin/$(BINARY_NAME) 2>/dev/null || echo " Plugin not installed in ~/bin"
149+
@echo ""
150+
@echo "✅ Plugin accessibility:"
151+
@if command -v kubectl oadp >/dev/null 2>&1; then \
152+
echo " kubectl oadp is accessible"; \
153+
else \
154+
echo " kubectl oadp is NOT accessible"; \
155+
fi

README.md

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,29 @@ oadp
2727

2828
### Quick Installation
2929

30-
Use the provided script for quick build and installation:
30+
Use the Makefile for easy build and installation:
3131

3232
```sh
33-
chmod +x quick-create.sh
34-
./quick-create.sh
33+
# Quick install (equivalent to old quick-create.sh)
34+
make quick-install
35+
36+
# Or step by step:
37+
make build-plugin
38+
sudo make install
3539
```
3640

37-
### Manual Installation
41+
### Alternative Installation Methods
42+
43+
**Install to ~/bin (no sudo required):**
44+
```sh
45+
make install-local
46+
```
3847

48+
**Manual Installation:**
3949
1. **Build the CLI:**
4050
```sh
41-
go build -o kubectl-oadp .
51+
make build-plugin
52+
# or manually: go build -o kubectl-oadp .
4253
```
4354

4455
2. **Install as kubectl plugin:**
@@ -48,9 +59,29 @@ chmod +x quick-create.sh
4859

4960
3. **Verify installation:**
5061
```sh
51-
kubectl oadp --help
62+
make verify-install
63+
# or manually: kubectl oadp --help
5264
```
5365

66+
### Development Workflow
67+
68+
```sh
69+
# Set up development environment
70+
make dev-setup
71+
72+
# Build for local testing
73+
make build
74+
75+
# Run tests
76+
make test
77+
78+
# Format and check code
79+
make check
80+
81+
# View all available commands
82+
make help
83+
```
84+
5485
## Usage Examples
5586

5687
### NonAdminBackup Operations
@@ -99,7 +130,16 @@ This project includes comprehensive CLI integration tests organized by functiona
99130
### Quick Test Commands
100131

101132
```bash
102-
# Run all tests (standard Go pattern)
133+
# Run all tests
134+
make test
135+
136+
# Run tests with verbose output
137+
make test-verbose
138+
139+
# Run tests with coverage
140+
make test-coverage
141+
142+
# Standard Go pattern (also works)
103143
go test ./...
104144
```
105145

quick-create.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)