-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (126 loc) · 4.77 KB
/
Makefile
File metadata and controls
158 lines (126 loc) · 4.77 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
.PHONY: help build test clean install run docker-build docker-push
# Variables
BINARY_NAME=pgcp
AGENT_BINARY_NAME=pgcp-agent
VERSION?=0.1.0
BUILD_DIR=build
DOCKER_REGISTRY?=pgelephant
DOCKER_IMAGE=$(DOCKER_REGISTRY)/pgcontrolplane
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
GOVET=$(GOCMD) vet
GOFMT=$(GOCMD) fmt
# Build flags
LDFLAGS=-ldflags "-X main.Version=$(VERSION)"
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
deps: ## Download dependencies
@echo "Downloading dependencies..."
$(GOMOD) download
$(GOMOD) tidy
build: deps ## Build the control plane server
@echo "Building pgControlPlane server..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/server
@echo "Build complete: $(BUILD_DIR)/$(BINARY_NAME)"
build-agent: deps ## Build the agent
@echo "Building pgControlPlane agent..."
@mkdir -p $(BUILD_DIR)
$(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(AGENT_BINARY_NAME) ./cmd/agent
@echo "Build complete: $(BUILD_DIR)/$(AGENT_BINARY_NAME)"
build-all: build build-agent ## Build both server and agent
install: build build-agent ## Install binaries to /usr/local/bin
@echo "Installing binaries..."
install -d /usr/local/bin
install -m 755 $(BUILD_DIR)/$(BINARY_NAME) /usr/local/bin/
install -m 755 $(BUILD_DIR)/$(AGENT_BINARY_NAME) /usr/local/bin/
@echo "Installation complete"
test: ## Run tests
@echo "Running tests..."
$(GOTEST) -v -race -coverprofile=coverage.out ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
@echo "Coverage report: coverage.html"
test-integration: ## Run integration tests
@echo "Running integration tests..."
$(GOTEST) -v -tags=integration ./test/integration/...
test-e2e: ## Run end-to-end tests
@echo "Running e2e tests..."
$(GOTEST) -v -tags=e2e ./test/e2e/...
bench: ## Run benchmarks
@echo "Running benchmarks..."
$(GOTEST) -bench=. -benchmem ./...
lint: ## Run linters
@echo "Running linters..."
@command -v golangci-lint >/dev/null 2>&1 || { echo "golangci-lint not installed. Installing..."; go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; }
golangci-lint run
fmt: ## Format code
@echo "Formatting code..."
$(GOFMT) ./...
vet: ## Run go vet
@echo "Running go vet..."
$(GOVET) ./...
clean: ## Clean build artifacts
@echo "Cleaning..."
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
$(GOCMD) clean
run: build ## Run the control plane server
@echo "Starting pgControlPlane server..."
./$(BUILD_DIR)/$(BINARY_NAME)
run-agent: build-agent ## Run the agent
@echo "Starting pgControlPlane agent..."
./$(BUILD_DIR)/$(AGENT_BINARY_NAME)
migrate: ## Run database migrations
@echo "Running migrations..."
@command -v migrate >/dev/null 2>&1 || { echo "golang-migrate not installed. Install from: https://github.com/golang-migrate/migrate"; exit 1; }
migrate -path migrations -database "$(DATABASE_URL)" up
migrate-down: ## Rollback database migrations
@echo "Rolling back migrations..."
migrate -path migrations -database "$(DATABASE_URL)" down
migrate-create: ## Create a new migration (usage: make migrate-create NAME=migration_name)
@echo "Creating migration: $(NAME)..."
migrate create -ext sql -dir migrations -seq $(NAME)
docker-build: ## Build Docker image
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE):$(VERSION) -t $(DOCKER_IMAGE):latest .
@echo "Docker image built: $(DOCKER_IMAGE):$(VERSION)"
docker-push: docker-build ## Push Docker image to registry
@echo "Pushing Docker image..."
docker push $(DOCKER_IMAGE):$(VERSION)
docker push $(DOCKER_IMAGE):latest
@echo "Docker image pushed"
docker-run: docker-build ## Run Docker container
@echo "Starting Docker container..."
docker run -d \
--name pgcontrolplane \
-p 8080:8080 \
-p 9090:9090 \
-p 2112:2112 \
-e PGCP_DATABASE_URL=$(DATABASE_URL) \
$(DOCKER_IMAGE):latest
docker-stop: ## Stop Docker container
@echo "Stopping Docker container..."
docker stop pgcontrolplane
docker rm pgcontrolplane
proto: ## Generate protobuf code
@echo "Generating protobuf code..."
@command -v protoc >/dev/null 2>&1 || { echo "protoc not installed"; exit 1; }
protoc --go_out=. --go-grpc_out=. api/proto/*.proto
dev: ## Run development environment with docker-compose
@echo "Starting development environment..."
docker-compose up -d
dev-down: ## Stop development environment
@echo "Stopping development environment..."
docker-compose down
logs: ## View logs from development environment
docker-compose logs -f
release: ## Create a new release
@echo "Creating release $(VERSION)..."
git tag -a v$(VERSION) -m "Release v$(VERSION)"
git push origin v$(VERSION)
@echo "Release v$(VERSION) created"
.DEFAULT_GOAL := help