-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·131 lines (103 loc) · 3.4 KB
/
deploy.sh
File metadata and controls
executable file
·131 lines (103 loc) · 3.4 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
#!/bin/bash
# OMR Scraper Deployment Script for Digital Ocean
# Run this script on your Digital Ocean droplet
set -e
echo "🚀 Starting OMR Scraper deployment..."
# Configuration
APP_NAME="omr-scraper"
APP_DIR="/var/www/$APP_NAME"
SERVICE_NAME="omr-scraper"
NGINX_SITE="omr-scraper"
DOMAIN="omr.yourdomain.com" # Change this to your actual domain
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
print_status() {
echo -e "${GREEN}[INFO]${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 "Please run as root (use sudo)"
exit 1
fi
# Update system packages
print_status "Updating system packages..."
apt update && apt upgrade -y
# Install required packages
print_status "Installing required packages..."
apt install -y python3 python3-pip python3-venv nginx ufw fail2ban
# Create application directory
print_status "Creating application directory..."
mkdir -p $APP_DIR
cd $APP_DIR
# Copy application files (assuming you've uploaded them)
print_status "Setting up application files..."
# Note: You need to upload your project files to this directory first
# Create virtual environment
print_status "Creating Python virtual environment..."
python3 -m venv venv
source venv/bin/activate
# Install dependencies
print_status "Installing Python dependencies..."
pip install --upgrade pip
pip install opencv-python numpy Flask schedule gunicorn
# Set proper permissions
print_status "Setting up permissions..."
chown -R www-data:www-data $APP_DIR
chmod -R 755 $APP_DIR
# Create necessary directories
mkdir -p $APP_DIR/marked_images
mkdir -p $APP_DIR/logs
mkdir -p /tmp/omr_uploads
chown -R www-data:www-data $APP_DIR/marked_images
chown -R www-data:www-data $APP_DIR/logs
chown -R www-data:www-data /tmp/omr_uploads
# Setup systemd service
print_status "Setting up systemd service..."
cp $APP_DIR/omr-scraper.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable $SERVICE_NAME
# Setup nginx
print_status "Configuring nginx..."
cp $APP_DIR/nginx-omr-scraper.conf /etc/nginx/sites-available/$NGINX_SITE
# Replace domain placeholder
sed -i "s/omr.yourdomain.com/$DOMAIN/g" /etc/nginx/sites-available/$NGINX_SITE
# Enable site
ln -sf /etc/nginx/sites-available/$NGINX_SITE /etc/nginx/sites-enabled/
# Test nginx configuration
nginx -t
# Setup firewall
print_status "Configuring firewall..."
ufw allow ssh
ufw allow 'Nginx Full'
ufw --force enable
# Start services
print_status "Starting services..."
systemctl start $SERVICE_NAME
systemctl restart nginx
# Check service status
print_status "Checking service status..."
systemctl status $SERVICE_NAME --no-pager
print_status "🎉 Deployment completed successfully!"
print_status "Your OMR Scraper is now running at: http://$DOMAIN"
print_status "API endpoint: http://$DOMAIN/analyze-omr"
# Optional: Setup SSL with Let's Encrypt
read -p "Do you want to setup SSL with Let's Encrypt? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
print_status "Setting up SSL with Let's Encrypt..."
apt install -y certbot python3-certbot-nginx
certbot --nginx -d $DOMAIN
print_status "SSL setup completed!"
fi
print_status "Deployment finished! 🚀"
print_status "Service logs: journalctl -u $SERVICE_NAME -f"
print_status "Nginx logs: tail -f /var/log/nginx/omr-scraper.access.log"