-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (94 loc) · 3.66 KB
/
Copy pathMakefile
File metadata and controls
110 lines (94 loc) · 3.66 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
.PHONY: build clean deps check-deps check-services init-db start-api start-worker stop help
# Go build settings
GOFLAGS := -v
LDFLAGS := -w -s
# Binaries
WORKER_BIN := bin/worker
API_BIN := bin/api-gateway
# Build all binaries
build: deps $(WORKER_BIN) $(API_BIN)
# Check dependencies
check-deps:
@echo "🔍 Checking dependencies..."
@command -v go >/dev/null 2>&1 || { echo "❌ Go is not installed"; exit 1; }
@command -v psql >/dev/null 2>&1 || { echo "❌ PostgreSQL client is not installed"; exit 1; }
@command -v redis-cli >/dev/null 2>&1 || { echo "❌ Redis client is not installed"; exit 1; }
@echo "✅ All dependencies found"
# Download Go dependencies
deps: check-deps
@echo "📦 Downloading Go dependencies..."
@go mod download
@go mod tidy
# Build worker
$(WORKER_BIN): cmd/worker/main.go
@echo "🔨 Building worker..."
@mkdir -p bin
@go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(WORKER_BIN) ./cmd/worker
# Build API gateway
$(API_BIN): cmd/api-gateway/main.go
@echo "🔨 Building API gateway..."
@mkdir -p bin
@go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(API_BIN) ./cmd/api-gateway
# Clean build artifacts
clean:
@echo "🧹 Cleaning build artifacts..."
@rm -rf bin/
# Check if services are running
check-services:
@echo "🔍 Checking required services..."
@pg_isready -h localhost -p 5432 >/dev/null 2>&1 || { echo "❌ PostgreSQL is not running on localhost:5432"; exit 1; }
@redis-cli -h localhost -p 6379 ping >/dev/null 2>&1 || { echo "❌ Redis is not running on localhost:6379"; exit 1; }
@echo "✅ PostgreSQL and Redis are running"
# Initialize database
init-db: check-services
@echo "🗄️ Initializing database..."
@psql -h localhost -p 5432 -U postgres -c "CREATE DATABASE IF NOT EXISTS distributed_tasks;" 2>/dev/null || true
@echo "✅ Database initialized"
# Start worker (blocking)
start-worker: build check-services
@echo "🚀 Starting worker..."
@./$(WORKER_BIN)
# Start API gateway (blocking)
start-api: build check-services
@echo "🚀 Starting API gateway..."
@./$(API_BIN)
# Start all services in background
start-all: build check-services
@echo "🚀 Starting all services in background..."
@./$(WORKER_BIN) & echo $$! > worker.pid
@./$(API_BIN) & echo $$! > api.pid
@echo "✅ Services started"
@echo " Worker PID: `cat worker.pid`"
@echo " API Gateway PID: `cat api.pid`"
@echo "🛑 Run 'make stop' to stop all services"
# Stop background services
stop:
@echo "🛑 Stopping services..."
@kill `cat worker.pid` 2>/dev/null && echo " ✅ Worker stopped" || echo " ⚠️ Worker not running"
@kill `cat api.pid` 2>/dev/null && echo " ✅ API Gateway stopped" || echo " ⚠️ API Gateway not running"
@rm -f worker.pid api.pid
# Show help
help:
@echo "📖 Distributed Task Processing System"
@echo "===================================="
@echo ""
@echo "Available commands:"
@echo " make build - Build all binaries"
@echo " make clean - Clean build artifacts"
@echo " make deps - Download Go dependencies"
@echo " make check-deps - Check if required tools are installed"
@echo " make check-services - Check if PostgreSQL and Redis are running"
@echo " make init-db - Initialize PostgreSQL database"
@echo ""
@echo "Running services:"
@echo " make start-worker - Start worker (blocking)"
@echo " make start-api - Start API gateway (blocking)"
@echo " make start-all - Start all services in background"
@echo " make stop - Stop background services"
@echo ""
@echo "Prerequisites:"
@echo " - PostgreSQL running on localhost:5432"
@echo " - Redis running on localhost:6379"
@echo " - Go 1.19+ installed"
# Default target
.DEFAULT_GOAL := help