-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·338 lines (286 loc) · 9.95 KB
/
setup.sh
File metadata and controls
executable file
·338 lines (286 loc) · 9.95 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
#!/bin/bash
# Rendiff - Simple Setup Script
# A REST API layer powered by FFmpeg for media processing
set -e
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$PROJECT_DIR"
echo "🚀 Rendiff Setup (Powered by FFmpeg)"
echo "======================================"
# Function to show usage
show_usage() {
echo "Usage: $0 [OPTION]"
echo ""
echo "🚀 Rendiff - Production-Ready Setup Script (Powered by FFmpeg)"
echo ""
echo "Deployment Options:"
echo " --development 🛠️ Fast local development (SQLite, debug mode, no auth)"
echo " --standard 🏭 Production CPU setup (PostgreSQL, Redis, monitoring)"
echo " --gpu 🎮 GPU-accelerated setup (NVIDIA hardware acceleration)"
echo ""
echo "Management Options:"
echo " --status 📊 Show current deployment status"
echo " --stop 🛑 Stop all running services"
echo " --clean 🧹 Complete cleanup (stops services, removes volumes)"
echo " --help 📖 Show this help message"
echo ""
echo "Examples:"
echo " $0 --development # Quick 60-second setup for local development"
echo " $0 --standard # Production setup with PostgreSQL and monitoring"
echo " $0 --gpu # GPU setup with NVIDIA acceleration"
echo " $0 --status # Check what's currently running"
echo ""
echo "🌐 Access URLs (when running):"
echo " • API: http://localhost:8000"
echo " • Docs: http://localhost:8000/docs"
echo " • Health: http://localhost:8000/api/v1/health"
echo " • Prometheus: http://localhost:9090 (standard/gpu only)"
echo " • Grafana: http://localhost:3000 (standard/gpu only)"
echo ""
exit 1
}
# Function to check requirements
check_requirements() {
echo "Checking requirements..."
if ! command -v docker &> /dev/null; then
echo "❌ Docker is not installed. Please install Docker first."
exit 1
fi
if ! command -v docker &> /dev/null || ! docker compose version &> /dev/null; then
echo "❌ Docker Compose is not available. Please install Docker Compose."
exit 1
fi
echo "✅ Docker and Docker Compose are available"
}
# Function for development setup
setup_development() {
echo "🛠️ Setting up Development Environment..."
# Create development environment file
cat > .env.dev << EOF
# Development Configuration - Fast Local Setup
DEBUG=true
TESTING=false
# API Configuration
API_HOST=0.0.0.0
API_PORT=8000
API_LOG_LEVEL=debug
API_WORKERS=1
# Database (SQLite for simplicity)
DATABASE_URL=sqlite+aiosqlite:///data/rendiff.db
# Queue (Redis)
REDIS_URL=redis://redis:6379/0
# Storage
STORAGE_PATH=./storage
TEMP_PATH=/tmp/rendiff
# Security (Disabled for development)
ENABLE_API_KEYS=false
ENABLE_RATE_LIMITING=false
API_CORS_ORIGINS=http://localhost:8000,http://127.0.0.1:8000,http://localhost:3000
# FFmpeg
FFMPEG_HARDWARE_ACCELERATION=auto
FFMPEG_THREADS=2
# Worker
WORKER_CONCURRENCY=2
# Development passwords
POSTGRES_PASSWORD=dev_password_123
GRAFANA_PASSWORD=admin
EOF
ln -sf .env.dev .env
echo "📁 Creating directories..."
mkdir -p storage data logs config
echo "🐳 Starting development services..."
docker compose up -d redis api
echo ""
echo "✅ Development setup complete!"
echo ""
echo "🌐 API available at: http://localhost:8000"
echo "📚 API docs at: http://localhost:8000/docs"
echo "🔍 Health check: http://localhost:8000/api/v1/health"
echo ""
echo "📝 To stop: ./setup.sh --stop"
}
# Function for standard production setup
setup_standard() {
echo "🏭 Setting up Standard Production Environment..."
# Check if .env.example exists
if [ ! -f ".env.example" ]; then
echo "❌ .env.example not found! Please ensure it exists."
exit 1
fi
# Create production environment file
if [ ! -f ".env" ]; then
echo "📋 Creating production .env file from template..."
cp .env.example .env
echo ""
echo "⚠️ IMPORTANT: Edit .env file with your production values:"
echo " - Set secure passwords for POSTGRES_PASSWORD and GRAFANA_PASSWORD"
echo " - Configure API_CORS_ORIGINS for your domain"
echo " - Set ADMIN_API_KEYS for API access"
echo ""
read -p "Press Enter after editing .env file..."
fi
echo "📁 Creating directories..."
mkdir -p storage data/postgres data/redis data/prometheus data/grafana logs config
echo "🐳 Starting production services..."
COMPOSE_PROFILES=standard docker compose up -d
echo ""
echo "✅ Standard production setup complete!"
echo ""
echo "🌐 API available at: http://localhost:8000"
echo "📚 API docs at: http://localhost:8000/docs"
echo "📊 Prometheus at: http://localhost:9090"
echo "📈 Grafana at: http://localhost:3000"
echo ""
echo "📝 To stop: ./setup.sh --stop"
}
# Function for GPU-accelerated setup
setup_gpu() {
echo "🎮 Setting up GPU-Accelerated Environment..."
# Check for NVIDIA Docker runtime
if ! docker info 2>/dev/null | grep -q nvidia; then
echo "⚠️ NVIDIA Docker runtime not detected."
echo "📖 For GPU acceleration, install:"
echo " 1. NVIDIA drivers"
echo " 2. NVIDIA Container Toolkit"
echo " 3. Configure Docker to use nvidia runtime"
echo ""
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Check if .env.example exists
if [ ! -f ".env.example" ]; then
echo "❌ .env.example not found! Please ensure it exists."
exit 1
fi
# Create GPU environment file
if [ ! -f ".env" ]; then
echo "📋 Creating GPU .env file from template..."
cp .env.example .env
echo ""
echo "⚠️ IMPORTANT: Edit .env file with your production values and GPU settings:"
echo " - Set secure passwords"
echo " - Configure API_CORS_ORIGINS for your domain"
echo " - Set ADMIN_API_KEYS for API access"
echo " - Verify GPU worker settings"
echo ""
read -p "Press Enter after editing .env file..."
fi
echo "📁 Creating directories..."
mkdir -p storage data/postgres data/redis data/prometheus data/grafana logs config
echo "🐳 Starting GPU-accelerated services..."
COMPOSE_PROFILES=gpu,monitoring docker compose up -d
echo ""
echo "✅ GPU-accelerated setup complete!"
echo ""
echo "🌐 API available at: http://localhost:8000"
echo "📚 API docs at: http://localhost:8000/docs"
echo "📊 Prometheus at: http://localhost:9090"
echo "📈 Grafana at: http://localhost:3000"
echo "🎮 GPU workers enabled for hardware acceleration"
echo ""
echo "📝 To stop: ./setup.sh --stop"
}
# Function to show status
show_status() {
echo "📊 Current Status:"
echo "=================="
# Check which environment is running
if docker compose ps 2>/dev/null | grep -q "Up"; then
echo "🟢 FFmpeg API is running"
echo ""
docker compose ps
echo ""
echo "🌐 Access URLs:"
echo " API: http://localhost:8000"
echo " Docs: http://localhost:8000/docs"
echo " Health: http://localhost:8000/api/v1/health"
# Check if monitoring is enabled
if docker compose ps prometheus 2>/dev/null | grep -q "Up"; then
echo " Prometheus: http://localhost:9090"
fi
if docker compose ps grafana 2>/dev/null | grep -q "Up"; then
echo " Grafana: http://localhost:3000"
fi
# Check active profiles
if [ -f ".env" ]; then
echo ""
echo "📋 Current Configuration:"
if grep -q "DEBUG=true" .env 2>/dev/null; then
echo " Mode: Development"
else
echo " Mode: Production"
fi
if docker compose ps worker-gpu 2>/dev/null | grep -q "Up"; then
echo " GPU: Enabled"
else
echo " GPU: Disabled"
fi
fi
else
echo "🔴 FFmpeg API is not running"
echo ""
echo "🚀 To start:"
echo " Development: ./setup.sh --development"
echo " Production: ./setup.sh --standard"
echo " GPU: ./setup.sh --gpu"
fi
}
# Function to stop services
stop_services() {
echo "🛑 Stopping services..."
# Stop all possible configurations
docker compose down --remove-orphans 2>/dev/null || true
# Clean up development files
if [ -f "compose.dev.yml" ]; then
docker compose -f compose.dev.yml down 2>/dev/null || true
rm -f compose.dev.yml
fi
# Clean up environment symlinks
if [ -L ".env" ]; then
rm -f .env
fi
echo "✅ Services stopped and cleaned up"
}
# Function to clean up everything
cleanup_all() {
echo "🧹 Cleaning up everything..."
stop_services
echo "🗑️ Removing volumes..."
docker volume prune -f 2>/dev/null || true
echo "🗑️ Removing temporary files..."
rm -rf data/ logs/ .env.dev compose.dev.yml 2>/dev/null || true
echo "✅ Complete cleanup finished"
}
# Parse command line arguments
case "${1:-}" in
--development|--dev)
check_requirements
setup_development
;;
--standard|--prod)
check_requirements
setup_standard
;;
--gpu|--hardware)
check_requirements
setup_gpu
;;
--status)
show_status
;;
--stop)
stop_services
;;
--clean|--cleanup)
cleanup_all
;;
--help|-h)
show_usage
;;
*)
echo "❌ Unknown option: ${1:-}"
show_usage
;;
esac