-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
219 lines (189 loc) · 6.39 KB
/
Makefile
File metadata and controls
219 lines (189 loc) · 6.39 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# DebVisor Makefile - Build, test, and deployment automation
# Usage: make [target]
.PHONY: help build test deploy clean install-deps setup-db protoc lint format run-rpc run-panel
# Configuration
PYTHON := python3
PIP := pip3
PYTEST := pytest
BLACK := black
FLAKE8 := flake8
PROTOC := protoc
# Paths
RPC_DIR := opt/services/rpc
PANEL_DIR := opt/web/panel
PROTO_DIR := opt/services/rpc/proto
BUILD_DIR := build
DIST_DIR := dist
.PHONY: help
help:
@echo "DebVisor Makefile - Build and deployment automation"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " help Show this help message"
@echo " build Build all components"
@echo " install-deps Install Python dependencies"
@echo " setup-db Setup database (PostgreSQL)"
@echo " protoc Compile Protocol Buffer files"
@echo " lint Run code linting"
@echo " format Format code with Black"
@echo " type-check Run static type checking with MyPy"
@echo " test Run unit tests"
@echo " test-coverage Run tests with coverage"
@echo " test-integration Run integration tests"
@echo " run-rpc Run RPC service locally"
@echo " run-panel Run web panel locally"
@echo " deploy-rpc Deploy RPC service to systemd"
@echo " deploy-panel Deploy web panel to systemd"
@echo " deploy-all Deploy all services"
@echo " clean Remove build artifacts"
@echo " docker-build Build Docker images"
@echo " docker-up Start Docker containers"
@echo " docker-down Stop Docker containers"
.PHONY: install-deps
install-deps:
@echo "Installing Python dependencies..."
$(PIP) install -r $(RPC_DIR)/requirements.txt
$(PIP) install -r $(PANEL_DIR)/requirements.txt
@echo "Dependencies installed successfully"
.PHONY: protoc
protoc:
@echo "Compiling Protocol Buffer files..."
cd $(RPC_DIR) && $(PROTOC) --python_out=. --grpc_python_out=. proto/*.proto
@echo "Protocol buffers compiled successfully"
.PHONY: lint
lint:
@echo "Running code linting..."
$(FLAKE8) $(RPC_DIR) --max-line-length=120 --ignore=W503
$(FLAKE8) $(PANEL_DIR) --max-line-length=120 --ignore=W503
@echo "Linting complete"
.PHONY: format
format:
@echo "Formatting code with Black..."
$(BLACK) $(RPC_DIR) --line-length=120
$(BLACK) $(PANEL_DIR) --line-length=120
@echo "Code formatting complete"
.PHONY: type-check
type-check:
@echo "Running static type checking..."
mypy opt/ tests/ --config-file mypy.ini
@echo "Type checking complete"
.PHONY: test
test:
@echo "Running unit tests..."
$(PYTEST) tests/ -v --tb=short
@echo "Tests complete"
.PHONY: test-coverage
test-coverage:
@echo "Running tests with coverage..."
$(PYTEST) tests/ -v --cov=$(RPC_DIR) --cov=$(PANEL_DIR) --cov-report=html
@echo "Coverage report generated in htmlcov/"
.PHONY: test-integration
test-integration:
@echo "Running integration tests..."
$(PYTEST) tests/integration/ -v --tb=short
@echo "Integration tests complete"
.PHONY: run-rpc
run-rpc:
@echo "Starting RPC service..."
cd $(RPC_DIR) && $(PYTHON) server.py --config config.json --debug
.PHONY: run-panel
run-panel:
@echo "Starting web panel..."
cd $(PANEL_DIR) && $(PYTHON) -m flask run --host=0.0.0.0 --port=5000 --reload
.PHONY: setup-db
setup-db:
@echo "Setting up database..."
cd $(PANEL_DIR) && $(PYTHON) -c "from app import create_app, db; app = create_app('development'); app.app_context().push(); db.create_all(); print('Database setup complete')"
.PHONY: build
build: install-deps protoc lint
@echo "Build complete"
.PHONY: deploy-rpc
deploy-rpc:
@echo "Deploying RPC service..."
sudo cp $(RPC_DIR)/systemd/rpc.service /etc/systemd/system/debvisor-rpc.service
sudo systemctl daemon-reload
sudo systemctl enable debvisor-rpc.service
sudo systemctl restart debvisor-rpc.service
@echo "RPC service deployed"
.PHONY: deploy-panel
deploy-panel:
@echo "Deploying web panel..."
sudo cp $(PANEL_DIR)/systemd/panel.service /etc/systemd/system/debvisor-panel.service
sudo cp $(PANEL_DIR)/nginx/panel.conf /etc/nginx/sites-available/debvisor-panel
sudo ln -sf /etc/nginx/sites-available/debvisor-panel /etc/nginx/sites-enabled/debvisor-panel
sudo systemctl daemon-reload
sudo systemctl enable debvisor-panel.service
sudo systemctl restart debvisor-panel.service
sudo nginx -t && sudo systemctl restart nginx
@echo "Web panel deployed"
.PHONY: deploy-all
deploy-all: deploy-rpc deploy-panel
@echo "All services deployed successfully"
.PHONY: clean
clean:
@echo "Cleaning build artifacts..."
find . -type d -name __pycache__ -exec rm -rf {} +
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
find . -type f -name "*.egg-info" -delete
rm -rf build dist htmlcov .pytest_cache .coverage
@echo "Clean complete"
.PHONY: docker-build
docker-build:
@echo "Building Docker images..."
docker build -t debvisor-rpc:latest -f $(RPC_DIR)/Dockerfile $(RPC_DIR)
docker build -t debvisor-panel:latest -f $(PANEL_DIR)/Dockerfile $(PANEL_DIR)
@echo "Docker build complete"
.PHONY: docker-up
docker-up:
@echo "Starting Docker containers..."
docker-compose -f docker-compose.yml up -d
@echo "Containers started"
.PHONY: docker-down
docker-down:
@echo "Stopping Docker containers..."
docker-compose -f docker-compose.yml down
@echo "Containers stopped"
.PHONY: docker-logs
docker-logs:
docker-compose -f docker-compose.yml logs -f
.PHONY: status
status:
@echo "=== DebVisor Services Status ==="
@echo ""
@echo "RPC Service:"
@sudo systemctl status debvisor-rpc.service || echo "Not running"
@echo ""
@echo "Web Panel:"
@sudo systemctl status debvisor-panel.service || echo "Not running"
@echo ""
@echo "Nginx:"
@sudo systemctl status nginx || echo "Not running"
.PHONY: logs
logs:
@echo "RPC Service Logs:"
sudo journalctl -u debvisor-rpc.service -f &
@echo "Web Panel Logs:"
sudo journalctl -u debvisor-panel.service -f
.PHONY: restart
restart:
@echo "Restarting all services..."
sudo systemctl restart debvisor-rpc.service
sudo systemctl restart debvisor-panel.service
sudo systemctl restart nginx
@echo "Services restarted"
.PHONY: stop
stop:
@echo "Stopping all services..."
sudo systemctl stop debvisor-rpc.service
sudo systemctl stop debvisor-panel.service
@echo "Services stopped"
.PHONY: start
start:
@echo "Starting all services..."
sudo systemctl start debvisor-rpc.service
sudo systemctl start debvisor-panel.service
@echo "Services started"
.DEFAULT_GOAL := help