-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
151 lines (131 loc) · 3.47 KB
/
Copy pathdeploy.sh
File metadata and controls
151 lines (131 loc) · 3.47 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
#!/bin/bash
set -euo pipefail
# Deployment script for Video OCR & Transcription Service
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
log() { echo -e "${GREEN}[INFO]${NC} $1"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Check prerequisites
check_prerequisites() {
log "Checking prerequisites..."
command -v docker >/dev/null 2>&1 || { error "Docker is required but not installed."; exit 1; }
command -v docker-compose >/dev/null 2>&1 || { error "Docker Compose is required but not installed."; exit 1; }
log "✓ Docker: $(docker --version)"
log "✓ Docker Compose: $(docker-compose --version)"
}
# Configure environment
setup_environment() {
log "Setting up environment..."
if [ ! -f ".env" ]; then
cat > .env << 'ENVEOF'
# API Configuration (optional - works without these for basic functionality)
OPENAI_API_KEY=
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4o-mini
# Server Configuration
PORT=8000
TZ=UTC
ENVEOF
log "✓ Created .env file - configure your API keys if needed"
else
log "✓ .env file already exists"
fi
}
# Create necessary directories
setup_directories() {
log "Setting up directories..."
mkdir -p ./data ./ssl
chmod 755 ./data ./ssl
log "✓ Directories created"
}
# Build Docker image
build_image() {
log "Building Docker image..."
docker-compose build --no-cache
log "✓ Docker image built successfully"
}
# Start services
start_services() {
log "Starting services..."
docker-compose up -d
log "✓ Services started"
# Wait for service to be ready
log "Waiting for service to be ready..."
for i in {1..30}; do
if curl -s http://localhost:8000/api/health >/dev/null 2>&1; then
log "✓ Service is ready!"
return 0
fi
sleep 2
echo -n "."
done
warn "Service may still be starting. Check logs with: docker-compose logs -f"
}
# Show status
show_status() {
echo ""
log "Service Status:"
docker-compose ps
echo ""
log "Access points:"
echo " - API: http://localhost:8000"
echo " - Web UI: http://localhost:8000/ask"
echo " - Health: http://localhost:8000/api/health"
echo " - API Docs: http://localhost:8000/docs"
}
# Main deployment
main() {
echo "========================================"
echo " Video OCR API Deployment Script"
echo "========================================"
echo ""
check_prerequisites
setup_environment
setup_directories
build_image
start_services
show_status
echo ""
log "Deployment complete!"
}
# Parse arguments
case "${1:-deploy}" in
deploy)
main
;;
start)
check_prerequisites
start_services
;;
stop)
log "Stopping services..."
docker-compose down
log "✓ Services stopped"
;;
restart)
log "Restarting services..."
docker-compose restart
log "✓ Services restarted"
;;
logs)
docker-compose logs -f
;;
status)
show_status
;;
rebuild)
check_prerequisites
build_image
start_services
;;
*)
echo "Usage: $0 {deploy|start|stop|restart|logs|status|rebuild}"
exit 1
;;
esac