-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
175 lines (148 loc) · 6.88 KB
/
Makefile
File metadata and controls
175 lines (148 loc) · 6.88 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
.PHONY: help build test test-unit test-integration test-coverage test-race clean fmt vet lint install pre-commit release-snapshot localkind-up localkind-down
# Variables
BINARY_NAME=nic
CMD_DIR=./cmd/nic
PKG_DIRS=$(shell go list ./... | grep -v /vendor/)
GO_FILES=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
# Build information
VERSION?=$(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)"
help: ## Display this help message
@echo "Nebari Infrastructure Core - Makefile commands:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## Build the binary
@echo "Building $(BINARY_NAME)..."
CGO_ENABLED=0 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME) $(CMD_DIR)
@echo "Built $(BINARY_NAME) successfully"
build-all: ## Build binaries for all platforms
@echo "Building for all platforms..."
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME)-linux-amd64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME)-darwin-amd64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME)-darwin-arm64 $(CMD_DIR)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME)-windows-amd64.exe $(CMD_DIR)
CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -trimpath $(LDFLAGS) -o $(BINARY_NAME)-windows-arm64.exe $(CMD_DIR)
@echo "Built all platform binaries successfully"
install: ## Install the binary to $GOPATH/bin
@echo "Installing $(BINARY_NAME)..."
CGO_ENABLED=0 go install -trimpath $(LDFLAGS) $(CMD_DIR)
@echo "Installed $(BINARY_NAME) to $(shell go env GOPATH)/bin/$(BINARY_NAME)"
clean: ## Remove build artifacts
@echo "Cleaning..."
rm -f $(BINARY_NAME)
rm -f $(BINARY_NAME)-*
rm -f coverage.out
rm -f *.test
@echo "Cleaned successfully"
fmt: ## Format Go code
@echo "Running go fmt..."
gofmt -s -w $(GO_FILES)
@echo "Formatted successfully"
vet: ## Run go vet
@echo "Running go vet..."
go vet $(PKG_DIRS)
@echo "Vet passed successfully"
lint: ## Run golangci-lint
@echo "Running golangci-lint..."
@which golangci-lint > /dev/null || (echo "Error: golangci-lint is not installed. See https://golangci-lint.run/welcome/install/" && exit 1)
golangci-lint run
@echo "Lint passed successfully"
test: test-unit ## Run unit tests (default)
test-unit: ## Run unit tests only
@echo "Running unit tests..."
go test -v -short $(PKG_DIRS)
@echo "Unit tests passed successfully"
test-integration: ## Run integration tests (uses testcontainers, requires Docker)
@echo "Running integration tests with testcontainers..."
@which docker > /dev/null || (echo "Error: Docker is not installed or not running" && exit 1)
go test -v -tags=integration ./pkg/provider/aws -timeout 30m
@echo "Integration tests passed successfully"
test-all: ## Run all tests (unit + integration)
@echo "Running all tests..."
$(MAKE) test-unit
$(MAKE) test-integration
@echo "All tests passed successfully"
LOCAL_CONFIG?=./examples/local-config.yaml
REGEN_APPS?=
localkind-up: build ## Create local kind cluster and deploy Nebari (mounts file:// gitops repos automatically)
@echo "Setting up local kind cluster..."
@which kind > /dev/null || (echo "Error: kind is not installed" && exit 1)
@which yq > /dev/null || (echo "Error: yq is not installed. Please install and try again" && exit 1)
@which docker > /dev/null || (echo "Error: Docker is not installed or not running" && exit 1)
-docker network create --subnet=192.168.1.0/24 --gateway=192.168.1.1 kind
@GITOPS_URL=$$(yq '.git_repository.url // ""' $(LOCAL_CONFIG)); \
PROJECT_NAME=$$(yq '.project_name // ""' $(LOCAL_CONFIG)); \
if echo "$$GITOPS_URL" | grep -q '^file:///'; then \
LOCAL_PATH=$$(echo "$$GITOPS_URL" | sed 's|^file://||'); \
echo "Mounting explicit gitops repo: $$LOCAL_PATH"; \
elif [ -z "$$GITOPS_URL" ]; then \
LOCAL_PATH="/tmp/nebari-gitops-$$PROJECT_NAME"; \
echo "No git_repository configured, mounting auto-generated dir: $$LOCAL_PATH"; \
else \
LOCAL_PATH=""; \
echo "Remote git repo detected ($$GITOPS_URL), no mount needed"; \
fi; \
if [ -n "$$LOCAL_PATH" ]; then \
mkdir -p "$$LOCAL_PATH"; \
KIND_CONFIG=$$(mktemp); \
printf '%s\n' \
'kind: Cluster' \
'apiVersion: kind.x-k8s.io/v1alpha4' \
'name: nebari-local' \
'nodes:' \
'- role: control-plane' \
' extraMounts:' \
" - hostPath: \"$$LOCAL_PATH\"" \
" containerPath: \"$$LOCAL_PATH\"" \
' readOnly: true' \
> "$$KIND_CONFIG"; \
kind create cluster --config "$$KIND_CONFIG" || true; \
rm -f "$$KIND_CONFIG"; \
else \
kind create cluster --name nebari-local || true; \
fi
@echo "Deploying Nebari to local cluster..."
time ./$(BINARY_NAME) deploy -f $(LOCAL_CONFIG) $(REGEN_APPS)
@echo "Local kind cluster is ready!"
localkind-rebuild: build localkind-down localkind-up ## Rebuild local kind cluster
localkind-down: ## Delete local kind cluster
-kind delete cluster -n nebari-local
-docker network rm kind 2>/dev/null
@echo "Local kind cluster deleted"
test-coverage: ## Run unit tests with coverage
@echo "Running unit tests with coverage..."
go test -v -short -coverprofile=coverage.out -covermode=atomic $(PKG_DIRS)
go tool cover -func=coverage.out
@echo "Coverage report generated: coverage.out"
test-race: ## Run unit tests with race detection
@echo "Running unit tests with race detection..."
go test -v -short -race $(PKG_DIRS)
@echo "Race tests passed successfully"
check: fmt vet lint test ## Run all checks (fmt, vet, lint, test)
@echo "All checks passed successfully"
pre-commit: ## Install pre-commit hooks
@echo "Installing pre-commit hooks..."
@which pre-commit > /dev/null || (echo "Error: pre-commit is not installed. Install with: pip install pre-commit" && exit 1)
pre-commit install
@echo "Pre-commit hooks installed successfully"
pre-commit-run: ## Run pre-commit hooks on all files
@echo "Running pre-commit hooks..."
pre-commit run --all-files
release-snapshot: ## Create a snapshot release (local testing)
@echo "Creating snapshot release..."
@which goreleaser > /dev/null || (echo "Error: goreleaser is not installed. See https://goreleaser.com/install/" && exit 1)
goreleaser release --snapshot --clean
@echo "Snapshot release created successfully"
deps: ## Download Go dependencies
@echo "Downloading dependencies..."
go mod download
go mod verify
@echo "Dependencies downloaded successfully"
deps-update: ## Update Go dependencies
@echo "Updating dependencies..."
go get -u ./...
go mod tidy
@echo "Dependencies updated successfully"
.DEFAULT_GOAL := help