-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
170 lines (144 loc) · 4.7 KB
/
Makefile
File metadata and controls
170 lines (144 loc) · 4.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
# Makefile for FlexGate with Podman
.PHONY: help install build start stop restart logs stats clean test
# Default target
help:
@echo "FlexGate Podman Commands:"
@echo ""
@echo " make install - Install Podman and dependencies"
@echo " make build - Build FlexGate container image"
@echo " make start - Start all services"
@echo " make stop - Stop all services"
@echo " make restart - Restart all services"
@echo " make logs - View logs"
@echo " make stats - View HAProxy stats page"
@echo " make test - Run load test"
@echo " make clean - Remove all containers and volumes"
@echo ""
# Install Podman (macOS)
install:
@echo "Installing Podman..."
@if command -v brew &> /dev/null; then \
brew install podman podman-compose; \
podman machine init --cpus 4 --memory 8192 --disk-size 50; \
podman machine start; \
else \
echo "Homebrew not found. Install from https://brew.sh"; \
exit 1; \
fi
@pip3 install podman-compose
@echo "✅ Podman installed successfully"
# Build FlexGate image
build:
@echo "Building FlexGate image..."
@podman build -t localhost/flexgate-proxy:latest .
@podman tag localhost/flexgate-proxy:latest localhost/flexgate-proxy:0.1.0-beta.1
@echo "✅ Image built: localhost/flexgate-proxy:latest"
# Start all services
start:
@echo "Starting FlexGate services..."
@podman-compose -f podman-compose.yml up -d
@echo "✅ Services started"
@echo ""
@echo "Access points:"
@echo " - API Gateway: http://localhost:8080"
@echo " - HAProxy Stats: http://localhost:8404/stats (admin/changeme)"
@echo " - Prometheus: http://localhost:9090"
# Stop all services
stop:
@echo "Stopping FlexGate services..."
@podman-compose -f podman-compose.yml down
@echo "✅ Services stopped"
# Restart all services
restart: stop start
# View logs
logs:
@podman-compose -f podman-compose.yml logs -f
# View logs for specific service
logs-haproxy:
@podman logs -f flexgate-haproxy
logs-app:
@podman logs -f flexgate-app-1
logs-postgres:
@podman logs -f flexgate-postgres
# Open HAProxy stats page
stats:
@open http://localhost:8404/stats || xdg-open http://localhost:8404/stats
# View container stats
podman-stats:
@podman stats
# Run load test
test:
@echo "Running load test (10K requests)..."
@podman run --rm \
--network=host \
docker.io/curlimages/curl:latest \
sh -c 'for i in $$(seq 1 10000); do curl -s http://localhost:8080/api/health > /dev/null & done; wait'
@echo "✅ Load test complete"
# Health check
health:
@echo "Checking service health..."
@curl -f http://localhost:8080/health && echo "✅ API healthy" || echo "❌ API unhealthy"
@curl -f http://localhost:8404/stats && echo "✅ HAProxy healthy" || echo "❌ HAProxy unhealthy"
# Clean up everything
clean:
@echo "Cleaning up..."
@podman-compose -f podman-compose.yml down -v
@podman system prune -a -f
@echo "✅ Cleaned up all containers and volumes"
# Reload HAProxy config
reload-haproxy:
@echo "Reloading HAProxy configuration..."
@podman kill -s HUP flexgate-haproxy
@echo "✅ HAProxy config reloaded"
# Validate HAProxy config
validate-haproxy:
@echo "Validating HAProxy configuration..."
@podman run --rm \
-v ./haproxy/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro \
docker.io/haproxy:2.8-alpine \
haproxy -c -f /usr/local/etc/haproxy/haproxy.cfg
@echo "✅ HAProxy config is valid"
# Exec into HAProxy container
shell-haproxy:
@podman exec -it flexgate-haproxy sh
# Exec into app container
shell-app:
@podman exec -it flexgate-app-1 sh
# Generate systemd service files
systemd:
@echo "Generating systemd service files..."
@podman pod create --name flexgate-pod \
-p 8080:8080 -p 8443:8443 -p 8404:8404 -p 9090:9090
@podman generate systemd --new --files --name flexgate-pod
@mkdir -p ~/.config/systemd/user/
@mv pod-*.service container-*.service ~/.config/systemd/user/
@systemctl --user daemon-reload
@echo "✅ Systemd service files generated"
@echo ""
@echo "To enable on boot:"
@echo " systemctl --user enable pod-flexgate-pod.service"
@echo " systemctl --user start pod-flexgate-pod.service"
# Show running containers
ps:
@podman ps --pod
# Show pod status
pod:
@podman pod ps
@echo ""
@podman pod inspect flexgate-pod 2>/dev/null || echo "No pod found"
# Backup configuration
backup:
@echo "Backing up configuration..."
@mkdir -p backups
@podman cp flexgate-haproxy:/usr/local/etc/haproxy/haproxy.cfg backups/haproxy-$$(date +%Y%m%d-%H%M%S).cfg
@echo "✅ Configuration backed up to backups/"
# Deploy to production
deploy:
@echo "Deploying to production..."
@$(MAKE) validate-haproxy
@$(MAKE) build
@$(MAKE) restart
@echo "✅ Deployed successfully"
# Monitor metrics
metrics:
@open http://localhost:9090 || xdg-open http://localhost:9090