All checks were successful
Deploy FluentGerman.ai / deploy (push) Successful in 50s
76 lines
2.4 KiB
Bash
76 lines
2.4 KiB
Bash
#!/bin/bash
|
|
# FluentGerman.ai — Debian deployment setup script
|
|
# Run as root or with sudo
|
|
|
|
set -e
|
|
|
|
APP_NAME="fluentgerman"
|
|
APP_DIR="/opt/$APP_NAME"
|
|
APP_USER="fluentgerman"
|
|
DB_NAME="fluentgerman"
|
|
DB_USER="fluentgerman"
|
|
|
|
echo "=== FluentGerman.ai — Deployment Setup ==="
|
|
|
|
# 1. System user
|
|
if ! id "$APP_USER" &>/dev/null; then
|
|
useradd --system --no-create-home --shell /bin/false "$APP_USER"
|
|
echo "✓ Created system user: $APP_USER"
|
|
fi
|
|
|
|
# 2. Install Python if needed
|
|
apt-get update -qq
|
|
apt-get install -y -qq python3 python3-venv python3-pip > /dev/null
|
|
echo "✓ Python installed"
|
|
|
|
# 3. MySQL database setup
|
|
echo "Setting up MySQL database..."
|
|
mysql -u root -e "CREATE DATABASE IF NOT EXISTS $DB_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
|
|
mysql -u root -e "CREATE USER IF NOT EXISTS '$DB_USER'@'localhost' IDENTIFIED BY 'CHANGE_ME';"
|
|
mysql -u root -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO '$DB_USER'@'localhost';"
|
|
mysql -u root -e "FLUSH PRIVILEGES;"
|
|
echo "✓ MySQL database ready"
|
|
|
|
# 4. Application directory
|
|
mkdir -p "$APP_DIR"
|
|
cp -r backend/* "$APP_DIR/backend/"
|
|
cp -r frontend/* "$APP_DIR/frontend/"
|
|
chown -R "$APP_USER:$APP_USER" "$APP_DIR"
|
|
echo "✓ Files deployed to $APP_DIR"
|
|
|
|
# 5. Python virtual environment
|
|
cd "$APP_DIR/backend"
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install --quiet -r requirements.txt
|
|
deactivate
|
|
echo "✓ Python venv created"
|
|
|
|
# 6. Environment file
|
|
if [ ! -f "$APP_DIR/backend/.env" ]; then
|
|
cp "$APP_DIR/backend/.env.example" "$APP_DIR/backend/.env"
|
|
# Generate random secret key
|
|
SECRET=$(python3 -c "import secrets; print(secrets.token_urlsafe(48))")
|
|
sed -i "s/generate-a-strong-random-key-here/$SECRET/" "$APP_DIR/backend/.env"
|
|
echo "⚠ Created .env from template — EDIT $APP_DIR/backend/.env with your API keys and passwords!"
|
|
fi
|
|
|
|
# 7. Systemd service
|
|
cp deploy/fluentgerman.service /etc/systemd/system/
|
|
systemctl daemon-reload
|
|
systemctl enable "$APP_NAME"
|
|
systemctl start "$APP_NAME"
|
|
echo "✓ Systemd service active"
|
|
|
|
# 8. Nginx config
|
|
cp deploy/nginx.conf.example /etc/nginx/sites-available/$APP_NAME
|
|
ln -sf /etc/nginx/sites-available/$APP_NAME /etc/nginx/sites-enabled/
|
|
nginx -t && systemctl reload nginx
|
|
echo "✓ Nginx configured"
|
|
|
|
echo ""
|
|
echo "=== Deployment complete! ==="
|
|
echo "1. Edit /opt/$APP_NAME/backend/.env with your settings"
|
|
echo "2. Restart: systemctl restart $APP_NAME"
|
|
echo "3. Access: http://your-server-domain"
|