Skip to content

Commit 4a27b31

Browse files
chitcommitclaude
andcommitted
Add production deployment automation scripts
- Server setup script for Ubuntu/Debian environments - GitHub secrets configuration automation - Deployment verification and testing tools - Complete SSL, nginx, PM2, and PostgreSQL setup - Automated firewall and security configuration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 90c902a commit 4a27b31

3 files changed

Lines changed: 430 additions & 0 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/bin/bash
2+
3+
# GitHub Secrets Configuration Script
4+
# Automates setting up GitHub repository secrets for CI/CD deployment
5+
6+
set -e
7+
8+
echo "🔐 Configuring GitHub Repository Secrets for ChittyPro Streamlink"
9+
echo "Repository: chitcommit/chittypro-streamlink"
10+
echo ""
11+
12+
# Check if GitHub CLI is installed
13+
if ! command -v gh &> /dev/null; then
14+
echo "❌ GitHub CLI not found. Please install it first:"
15+
echo " macOS: brew install gh"
16+
echo " Linux: https://cli.github.com/manual/installation"
17+
exit 1
18+
fi
19+
20+
# Check if user is authenticated
21+
if ! gh auth status &> /dev/null; then
22+
echo "🔑 Please authenticate with GitHub CLI first:"
23+
echo " gh auth login"
24+
exit 1
25+
fi
26+
27+
echo "✅ GitHub CLI is ready"
28+
echo ""
29+
30+
# Function to set a secret
31+
set_secret() {
32+
local name=$1
33+
local description=$2
34+
local default_value=$3
35+
36+
echo "Setting $name - $description"
37+
38+
if [ -n "$default_value" ]; then
39+
read -p "Enter $name [$default_value]: " value
40+
value=${value:-$default_value}
41+
else
42+
read -p "Enter $name: " value
43+
fi
44+
45+
if [ -n "$value" ]; then
46+
echo "$value" | gh secret set "$name"
47+
echo "$name set successfully"
48+
else
49+
echo "⚠️ Skipping $name (empty value)"
50+
fi
51+
echo ""
52+
}
53+
54+
# Set production server secrets
55+
echo "🖥️ Production Server Configuration"
56+
set_secret "PRODUCTION_HOST" "Production server hostname" "derail.me"
57+
set_secret "PRODUCTION_USER" "SSH username for deployment" "deploy"
58+
set_secret "PRODUCTION_PORT" "SSH port" "22"
59+
60+
echo "🔑 SSH Private Key"
61+
echo "For PRODUCTION_SSH_KEY, you need your private SSH key content."
62+
echo "Generate with: ssh-keygen -t ed25519 -C 'deploy@derail.me'"
63+
echo ""
64+
read -p "Path to your private SSH key [~/.ssh/id_ed25519]: " ssh_key_path
65+
ssh_key_path=${ssh_key_path:-~/.ssh/id_ed25519}
66+
67+
if [ -f "$ssh_key_path" ]; then
68+
gh secret set PRODUCTION_SSH_KEY < "$ssh_key_path"
69+
echo "✅ PRODUCTION_SSH_KEY set successfully"
70+
else
71+
echo "⚠️ SSH key file not found at $ssh_key_path"
72+
echo "Please set PRODUCTION_SSH_KEY manually in GitHub"
73+
fi
74+
echo ""
75+
76+
# Generate and set authentication secrets
77+
echo "🔐 Authentication Configuration"
78+
jwt_secret=$(openssl rand -base64 32)
79+
session_secret=$(openssl rand -base64 32)
80+
81+
echo "$jwt_secret" | gh secret set JWT_SECRET
82+
echo "✅ JWT_SECRET generated and set"
83+
84+
echo "$session_secret" | gh secret set SESSION_SECRET
85+
echo "✅ SESSION_SECRET generated and set"
86+
echo ""
87+
88+
# Database configuration
89+
echo "🗄️ Database Configuration"
90+
set_secret "DATABASE_URL" "PostgreSQL connection string" "postgresql://streamlink:streamlink123@localhost:5432/chittypro_streamlink"
91+
92+
# Security configuration
93+
echo "🔒 Security Configuration"
94+
set_secret "ALLOWED_ORIGINS" "Allowed CORS origins" "https://derail.me,https://www.derail.me"
95+
96+
# Optional integrations
97+
echo "🔗 Optional Integrations"
98+
echo "Press Enter to skip optional secrets"
99+
set_secret "SLACK_WEBHOOK_URL" "Slack notifications webhook (optional)" ""
100+
set_secret "HEALTH_CHECK_WEBHOOK" "Health check webhook (optional)" ""
101+
102+
# Google Drive integration
103+
echo "☁️ Google Drive Integration (Optional)"
104+
set_secret "GDRIVE_CLIENT_ID" "Google Drive client ID (optional)" ""
105+
set_secret "GDRIVE_CLIENT_SECRET" "Google Drive client secret (optional)" ""
106+
set_secret "GDRIVE_REFRESH_TOKEN" "Google Drive refresh token (optional)" ""
107+
set_secret "GDRIVE_FOLDER_ID" "Google Drive folder ID (optional)" ""
108+
109+
echo "✅ GitHub secrets configuration complete!"
110+
echo ""
111+
echo "🚀 Next steps:"
112+
echo "1. Run the server setup script on your production server:"
113+
echo " scp scripts/setup-server.sh deploy@derail.me:~/"
114+
echo " ssh deploy@derail.me"
115+
echo " chmod +x setup-server.sh && ./setup-server.sh"
116+
echo ""
117+
echo "2. Add your SSH public key to the server:"
118+
echo " ssh-copy-id deploy@derail.me"
119+
echo ""
120+
echo "3. Test deployment by pushing to main branch:"
121+
echo " git push origin main"
122+
echo ""
123+
echo "4. Monitor deployment at:"
124+
echo " https://github.com/chitcommit/chittypro-streamlink/actions"
125+
echo ""
126+
echo "🌍 Your CI/CD pipeline is ready!"

scripts/setup-server.sh

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
#!/bin/bash
2+
3+
# ChittyPro Streamlink Server Setup Script
4+
# For Ubuntu/Debian servers (including derail.me)
5+
# Run this script on your production server to prepare for CI/CD deployment
6+
7+
set -e
8+
9+
echo "🚀 Setting up ChittyPro Streamlink production server..."
10+
11+
# Update system packages
12+
echo "📦 Updating system packages..."
13+
sudo apt update && sudo apt upgrade -y
14+
15+
# Install Node.js 20.x
16+
echo "🟢 Installing Node.js 20.x..."
17+
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
18+
sudo apt-get install -y nodejs
19+
20+
# Install PostgreSQL
21+
echo "🐘 Installing PostgreSQL..."
22+
sudo apt install -y postgresql postgresql-contrib
23+
24+
# Install Nginx
25+
echo "🌐 Installing Nginx..."
26+
sudo apt install -y nginx
27+
28+
# Install PM2 globally
29+
echo "⚡ Installing PM2..."
30+
sudo npm install -g pm2
31+
32+
# Install FFmpeg for streaming
33+
echo "🎥 Installing FFmpeg..."
34+
sudo apt install -y ffmpeg
35+
36+
# Install additional tools
37+
echo "🔧 Installing additional tools..."
38+
sudo apt install -y git curl wget htop ufw
39+
40+
# Create deploy user if it doesn't exist
41+
if ! id "deploy" &>/dev/null; then
42+
echo "👤 Creating deploy user..."
43+
sudo adduser --disabled-password --gecos "" deploy
44+
sudo usermod -aG sudo deploy
45+
46+
# Set up SSH directory for deploy user
47+
sudo -u deploy mkdir -p /home/deploy/.ssh
48+
sudo -u deploy chmod 700 /home/deploy/.ssh
49+
sudo -u deploy touch /home/deploy/.ssh/authorized_keys
50+
sudo -u deploy chmod 600 /home/deploy/.ssh/authorized_keys
51+
52+
echo "✅ Deploy user created. Add your public SSH key to /home/deploy/.ssh/authorized_keys"
53+
else
54+
echo "✅ Deploy user already exists"
55+
fi
56+
57+
# Create application directory
58+
echo "📁 Setting up application directory..."
59+
sudo mkdir -p /var/www/chittypro-streamlink
60+
sudo chown deploy:deploy /var/www/chittypro-streamlink
61+
62+
# Set up PostgreSQL database
63+
echo "🗄️ Setting up PostgreSQL database..."
64+
sudo -u postgres psql -c "CREATE DATABASE chittypro_streamlink;" || echo "Database may already exist"
65+
sudo -u postgres psql -c "CREATE USER streamlink WITH PASSWORD 'streamlink123';" || echo "User may already exist"
66+
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE chittypro_streamlink TO streamlink;"
67+
68+
# Configure Nginx
69+
echo "🌍 Configuring Nginx..."
70+
sudo tee /etc/nginx/sites-available/chittypro-streamlink > /dev/null <<EOF
71+
server {
72+
listen 80;
73+
server_name derail.me www.derail.me;
74+
75+
# Redirect HTTP to HTTPS
76+
return 301 https://\$server_name\$request_uri;
77+
}
78+
79+
server {
80+
listen 443 ssl http2;
81+
server_name derail.me www.derail.me;
82+
83+
# SSL configuration (Let's Encrypt certificates)
84+
ssl_certificate /etc/letsencrypt/live/derail.me/fullchain.pem;
85+
ssl_certificate_key /etc/letsencrypt/live/derail.me/privkey.pem;
86+
ssl_protocols TLSv1.2 TLSv1.3;
87+
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
88+
ssl_prefer_server_ciphers off;
89+
90+
# Security headers
91+
add_header X-Frame-Options DENY;
92+
add_header X-Content-Type-Options nosniff;
93+
add_header X-XSS-Protection "1; mode=block";
94+
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload";
95+
96+
# Serve static files
97+
location /assets/ {
98+
alias /var/www/chittypro-streamlink/dist/client/assets/;
99+
expires 1y;
100+
add_header Cache-Control "public, immutable";
101+
}
102+
103+
# WebSocket proxy for streaming
104+
location /ws {
105+
proxy_pass http://localhost:3000;
106+
proxy_http_version 1.1;
107+
proxy_set_header Upgrade \$http_upgrade;
108+
proxy_set_header Connection 'upgrade';
109+
proxy_set_header Host \$host;
110+
proxy_set_header X-Real-IP \$remote_addr;
111+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
112+
proxy_set_header X-Forwarded-Proto \$scheme;
113+
proxy_cache_bypass \$http_upgrade;
114+
}
115+
116+
# API routes
117+
location /api/ {
118+
proxy_pass http://localhost:3000;
119+
proxy_set_header Host \$host;
120+
proxy_set_header X-Real-IP \$remote_addr;
121+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
122+
proxy_set_header X-Forwarded-Proto \$scheme;
123+
}
124+
125+
# Frontend app
126+
location / {
127+
proxy_pass http://localhost:3000;
128+
proxy_set_header Host \$host;
129+
proxy_set_header X-Real-IP \$remote_addr;
130+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
131+
proxy_set_header X-Forwarded-Proto \$scheme;
132+
}
133+
}
134+
EOF
135+
136+
# Enable the site
137+
sudo ln -sf /etc/nginx/sites-available/chittypro-streamlink /etc/nginx/sites-enabled/
138+
sudo nginx -t
139+
140+
# Install Certbot for Let's Encrypt SSL
141+
echo "🔒 Installing Certbot for SSL certificates..."
142+
sudo apt install -y certbot python3-certbot-nginx
143+
144+
# Configure firewall
145+
echo "🔥 Configuring UFW firewall..."
146+
sudo ufw allow ssh
147+
sudo ufw allow 'Nginx Full'
148+
sudo ufw --force enable
149+
150+
# Set up PM2 startup
151+
echo "🔄 Configuring PM2 startup..."
152+
sudo pm2 startup systemd -u deploy --hp /home/deploy
153+
sudo systemctl enable pm2-deploy
154+
155+
# Create environment file template
156+
echo "📝 Creating environment file template..."
157+
sudo -u deploy tee /var/www/chittypro-streamlink/.env.example > /dev/null <<EOF
158+
# Production Environment Variables
159+
NODE_ENV=production
160+
PORT=3000
161+
162+
# Database
163+
DATABASE_URL=postgresql://streamlink:streamlink123@localhost:5432/chittypro_streamlink
164+
165+
# Authentication
166+
JWT_SECRET=your-jwt-secret-here
167+
SESSION_SECRET=your-session-secret-here
168+
169+
# Security
170+
ALLOWED_ORIGINS=https://derail.me,https://www.derail.me
171+
172+
# Optional: Google Drive Integration
173+
GDRIVE_CLIENT_ID=
174+
GDRIVE_CLIENT_SECRET=
175+
GDRIVE_REFRESH_TOKEN=
176+
GDRIVE_FOLDER_ID=
177+
EOF
178+
179+
# Create log directories
180+
echo "📋 Setting up log directories..."
181+
sudo mkdir -p /var/log/chittypro-streamlink
182+
sudo chown deploy:deploy /var/log/chittypro-streamlink
183+
184+
echo "✅ Server setup complete!"
185+
echo ""
186+
echo "🔑 Next steps:"
187+
echo "1. Add your SSH public key to /home/deploy/.ssh/authorized_keys"
188+
echo "2. Configure environment variables in /var/www/chittypro-streamlink/.env"
189+
echo "3. Obtain SSL certificate: sudo certbot --nginx -d derail.me -d www.derail.me"
190+
echo "4. Test SSH access: ssh deploy@derail.me"
191+
echo "5. Configure GitHub secrets and push to deploy"
192+
echo ""
193+
echo "🌍 Your server is ready for ChittyPro Streamlink deployment!"

0 commit comments

Comments
 (0)