-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsvb
More file actions
364 lines (329 loc) · 9.66 KB
/
Copy pathsvb
File metadata and controls
364 lines (329 loc) · 9.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/bin/bash
# SaveVideoBot Quick Launcher
# Simplified command-line interface for SaveVideoBot
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Project root
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}=== $1 ===${NC}"
}
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Function to check prerequisites
check_prerequisites() {
local missing=()
if ! command_exists docker; then
missing+=("docker")
fi
if ! command_exists docker-compose; then
missing+=("docker-compose")
fi
if ! command_exists python3; then
missing+=("python3")
fi
if [ ${#missing[@]} -ne 0 ]; then
print_error "Missing required commands: ${missing[*]}"
print_error "Please install the missing dependencies"
exit 1
fi
}
# Function to show help
show_help() {
cat << EOF
SaveVideoBot Quick Launcher
Usage: $0 <command> [options]
Development Commands:
dev Start development environment
dev-build Start development environment with build
test Run tests
lint Run linting
lint-fix Fix linting issues
Production Commands:
prod Start production environment
prod-build Start production environment with build
stop Stop all services
restart Restart all services
Service Commands:
bot Start Telegram bot (polling mode)
bot-webhook Start Telegram bot (webhook mode)
api Start FastAPI server
worker Start Celery worker
beat Start Celery beat scheduler
flower Start Flower monitoring
Database Commands:
migrate Run database migrations
migrate-create Create new migration
db-reset Reset database
db-shell Open database shell
Docker Commands:
build Build Docker images
build-dev Build development Docker images
clean Clean Docker resources
logs [service] Show Docker logs
logs-f [service] Follow Docker logs
Kubernetes Commands:
k8s-deploy Deploy to Kubernetes
k8s-delete Delete from Kubernetes
k8s-status Show Kubernetes status
k8s-logs Show Kubernetes logs
k8s-port-forward Port forward services
Helm Commands:
helm-install Install Helm chart
helm-upgrade Upgrade Helm chart
helm-uninstall Uninstall Helm chart
helm-status Show Helm status
Utility Commands:
status Show system status
config Show configuration
config-validate Validate configuration
config-init Initialize configuration
admin-stats Show admin statistics
admin-cleanup Trigger file cleanup
Examples:
$0 dev # Start development environment
$0 bot # Start bot in polling mode
$0 logs app # Show app logs
$0 k8s-deploy # Deploy to Kubernetes
$0 status # Show system status
EOF
}
# Function to run Python CLI
run_python_cli() {
cd "$PROJECT_ROOT"
python3 savevideobot.py "$@"
}
# Main command dispatcher
case "${1:-help}" in
# Development commands
"dev")
print_header "Starting Development Environment"
check_prerequisites
run_python_cli dev
;;
"dev-build")
print_header "Starting Development Environment (with build)"
check_prerequisites
run_python_cli dev --build
;;
"test")
print_header "Running Tests"
run_python_cli test
;;
"lint")
print_header "Running Linting"
run_python_cli lint
;;
"lint-fix")
print_header "Fixing Linting Issues"
run_python_cli lint --fix
;;
# Production commands
"prod")
print_header "Starting Production Environment"
check_prerequisites
run_python_cli prod
;;
"prod-build")
print_header "Starting Production Environment (with build)"
check_prerequisites
run_python_cli prod --build
;;
"stop")
print_header "Stopping All Services"
run_python_cli stop
;;
"restart")
print_header "Restarting All Services"
run_python_cli restart
;;
# Service commands
"bot")
print_header "Starting Telegram Bot (Polling)"
run_python_cli bot --mode polling
;;
"bot-webhook")
print_header "Starting Telegram Bot (Webhook)"
run_python_cli bot --mode webhook
;;
"api")
print_header "Starting FastAPI Server"
run_python_cli api
;;
"worker")
print_header "Starting Celery Worker"
run_python_cli worker
;;
"beat")
print_header "Starting Celery Beat Scheduler"
run_python_cli beat
;;
"flower")
print_header "Starting Flower Monitoring"
run_python_cli flower
;;
# Database commands
"migrate")
print_header "Running Database Migrations"
run_python_cli migrate
;;
"migrate-create")
print_header "Creating New Migration"
run_python_cli migrate-create
;;
"db-reset")
print_header "Resetting Database"
print_warning "This will delete all data!"
read -p "Are you sure? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run_python_cli db-reset
else
print_status "Operation cancelled"
fi
;;
"db-shell")
print_header "Opening Database Shell"
run_python_cli db-shell
;;
# Docker commands
"build")
print_header "Building Docker Images"
run_python_cli build
;;
"build-dev")
print_header "Building Development Docker Images"
run_python_cli build --target dev
;;
"clean")
print_header "Cleaning Docker Resources"
print_warning "This will remove all containers, images, and volumes!"
read -p "Are you sure? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run_python_cli clean
else
print_status "Operation cancelled"
fi
;;
"logs")
print_header "Showing Docker Logs"
if [ -n "$2" ]; then
run_python_cli logs --service "$2"
else
run_python_cli logs
fi
;;
"logs-f")
print_header "Following Docker Logs"
if [ -n "$2" ]; then
run_python_cli logs --service "$2" --follow
else
run_python_cli logs --follow
fi
;;
# Kubernetes commands
"k8s-deploy")
print_header "Deploying to Kubernetes"
run_python_cli k8s deploy
;;
"k8s-delete")
print_header "Deleting from Kubernetes"
print_warning "This will delete all Kubernetes resources!"
read -p "Are you sure? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run_python_cli k8s delete
else
print_status "Operation cancelled"
fi
;;
"k8s-status")
print_header "Kubernetes Status"
run_python_cli k8s status
;;
"k8s-logs")
print_header "Kubernetes Logs"
run_python_cli k8s logs
;;
"k8s-port-forward")
print_header "Port Forwarding Services"
run_python_cli k8s port-forward
;;
# Helm commands
"helm-install")
print_header "Installing Helm Chart"
run_python_cli helm install
;;
"helm-upgrade")
print_header "Upgrading Helm Chart"
run_python_cli helm upgrade
;;
"helm-uninstall")
print_header "Uninstalling Helm Chart"
print_warning "This will uninstall the Helm chart!"
read -p "Are you sure? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
run_python_cli helm uninstall
else
print_status "Operation cancelled"
fi
;;
"helm-status")
print_header "Helm Status"
run_python_cli helm status
;;
# Utility commands
"status")
print_header "System Status"
run_python_cli status
;;
"config")
print_header "Configuration"
run_python_cli config show
;;
"config-validate")
print_header "Validating Configuration"
run_python_cli config validate
;;
"config-init")
print_header "Initializing Configuration"
run_python_cli config init
;;
"admin-stats")
print_header "Admin Statistics"
run_python_cli admin stats
;;
"admin-cleanup")
print_header "Triggering File Cleanup"
run_python_cli admin cleanup
;;
# Help and unknown commands
"help"|"-h"|"--help")
show_help
;;
*)
print_error "Unknown command: $1"
echo
show_help
exit 1
;;
esac