-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall-ghcr.sh
More file actions
executable file
·204 lines (179 loc) · 5.49 KB
/
install-ghcr.sh
File metadata and controls
executable file
·204 lines (179 loc) · 5.49 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
#!/bin/bash
# ShortsCreator - Maintenance-Simple Install with GHCR
# Usage: curl -fsSL https://raw.githubusercontent.com/jdportugal/VideoEditorAPI/main/install-ghcr.sh | sudo bash
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
print_status() { echo -e "${BLUE}[INFO]${NC} $1"; }
print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Check if running as root
if [[ $EUID -ne 0 ]]; then
print_error "This script must be run as root (use sudo)"
exit 1
fi
echo
echo "🎬 ShortsCreator - Simple Install (GHCR)"
echo "======================================"
echo "✅ Pre-built images for faster deployment"
echo "✅ Automatic updates available"
echo "✅ Minimal maintenance required"
echo
# Quick system check
TOTAL_MEM=$(free -g | awk '/^Mem:/{print $2}')
if [ "$TOTAL_MEM" -lt 3 ]; then
print_warning "System has only ${TOTAL_MEM}GB RAM. 4GB+ recommended for video processing."
fi
# Install Docker if needed (minimal)
if ! command -v docker &> /dev/null; then
print_status "Installing Docker..."
curl -fsSL https://get.docker.com | sh > /dev/null 2>&1
systemctl enable docker && systemctl start docker
print_success "Docker installed"
else
print_success "Docker already available"
fi
# Install Docker Compose if needed
if ! command -v docker-compose &> /dev/null; then
print_status "Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
print_success "Docker Compose installed"
fi
# Setup application directory
APP_DIR="/opt/shortscreator"
print_status "Setting up application in $APP_DIR"
mkdir -p $APP_DIR && cd $APP_DIR
# Create simple docker-compose.yml using GHCR image
print_status "Creating deployment configuration..."
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
shortscreator:
image: ghcr.io/jdportugal/videoeditorapi:latest
container_name: shortscreator
ports:
- "8080:8080"
environment:
- FLASK_ENV=production
volumes:
- ./data:/app/temp
- ./uploads:/app/uploads
- ./jobs:/app/jobs
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
EOF
# Create data directories
mkdir -p data uploads jobs logs
chmod 755 data uploads jobs logs
# Create simple environment file
cat > .env << 'EOF'
# ShortsCreator Configuration
FLASK_ENV=production
COMPOSE_PROJECT_NAME=shortscreator
EOF
# Create update script for easy maintenance
cat > update.sh << 'EOF'
#!/bin/bash
echo "🔄 Updating ShortsCreator..."
docker-compose pull
docker-compose up -d
echo "✅ Update complete!"
EOF
chmod +x update.sh
# Create systemd service (simple)
print_status "Setting up auto-start service..."
cat > /etc/systemd/system/shortscreator.service << EOF
[Unit]
Description=ShortsCreator API
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=$APP_DIR
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=120
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable shortscreator.service
# Configure minimal firewall
print_status "Configuring firewall..."
if command -v ufw &> /dev/null; then
ufw --force enable > /dev/null 2>&1
ufw allow ssh > /dev/null 2>&1
ufw allow 5000/tcp > /dev/null 2>&1
fi
# Start the service
print_status "Starting ShortsCreator..."
print_status "Pulling pre-built image (this may take a moment)..."
# Try GHCR first, fallback if needed
if docker pull ghcr.io/jdportugal/videoeditorapi:latest > /dev/null 2>&1; then
print_success "Using pre-built image from GitHub"
else
print_warning "Pre-built image not available, falling back to build"
# Fallback to build approach
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
shortscreator:
build:
context: https://github.com/jdportugal/VideoEditorAPI.git
container_name: shortscreator
ports:
- "8080:8080"
environment:
- FLASK_ENV=production
volumes:
- ./data:/app/temp
- ./uploads:/app/uploads
- ./jobs:/app/jobs
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
EOF
fi
# Start the service
systemctl start shortscreator.service
# Wait and verify
print_status "Waiting for service to start..."
sleep 45
# Get server IP
SERVER_IP=$(curl -s http://checkip.amazonaws.com 2>/dev/null || echo "YOUR_SERVER_IP")
# Verify health
if curl -f -s "http://localhost:8080/health" > /dev/null; then
print_success "🎉 ShortsCreator is running successfully!"
else
print_warning "Service may still be starting up..."
fi
echo
echo "📋 Installation Complete!"
echo "========================"
echo "🌐 API URL: http://$SERVER_IP:8080"
echo "🔍 Health: http://$SERVER_IP:8080/health"
echo
echo "🛠️ Simple Management:"
echo " Update: cd $APP_DIR && ./update.sh"
echo " Stop: systemctl stop shortscreator"
echo " Start: systemctl start shortscreator"
echo " Logs: docker-compose logs -f"
echo
echo "🎬 Ready for video processing!"
echo "✨ Zero maintenance - just use it!"