Production Deployment
Production Deployment
Section titled “Production Deployment”Comprehensive guide for deploying Puppeteer MCP in production environments.
Production Checklist
Section titled “Production Checklist”Pre-Deployment
Section titled “Pre-Deployment”- Security audit completed
- Performance testing done
- Backup strategy defined
- Monitoring configured
- Documentation updated
- Rollback plan ready
Infrastructure
Section titled “Infrastructure”- SSL/TLS certificates
- Load balancer configured
- Database backups
- CDN setup (if needed)
- DNS configuration
- Firewall rules
Application
Section titled “Application”- Environment variables set
- Secrets management
- Error tracking
- Logging configured
- Health checks
- Graceful shutdown
Infrastructure Requirements
Section titled “Infrastructure Requirements”Minimum Production Setup
Section titled “Minimum Production Setup”- Servers: 2+ instances for HA
- CPU: 4 cores per instance
- RAM: 8GB per instance
- Storage: 50GB SSD
- Network: 1Gbps
- OS: Ubuntu 22.04 LTS
Recommended Setup
Section titled “Recommended Setup”- Servers: 3+ instances across AZs
- CPU: 8 cores per instance
- RAM: 16GB per instance
- Storage: 100GB SSD with backups
- Network: 10Gbps
- Load Balancer: Application LB
Deployment Architecture
Section titled “Deployment Architecture”High Availability Setup
Section titled “High Availability Setup” ┌─────────────┐ │ Route 53 │ │ DNS │ └──────┬──────┘ │ ┌──────▼──────┐ │ CloudFront│ │ CDN │ └──────┬──────┘ │ ┌──────▼──────┐ │ Application │ │Load Balancer│ └──────┬──────┘ │ ┌────────────────┼────────────────┐ │ │ │ ┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐ │ Server 1 │ │ Server 2 │ │ Server 3 │ │ (AZ-1) │ │ (AZ-2) │ │ (AZ-3) │ └───────────┘ └───────────┘ └───────────┘
Server Configuration
Section titled “Server Configuration”System Preparation
Section titled “System Preparation”# Update systemsudo apt update && sudo apt upgrade -y
# Install dependenciessudo apt install -y \ curl \ git \ build-essential \ nginx \ certbot \ python3-certbot-nginx \ chromium-browser \ chromium-codecs-ffmpeg \ ca-certificates \ fonts-liberation \ libasound2 \ libatk-bridge2.0-0 \ libatk1.0-0 \ libc6 \ libcairo2 \ libcups2 \ libdbus-1-3 \ libexpat1 \ libfontconfig1 \ libgcc1 \ libgconf-2-4 \ libgdk-pixbuf2.0-0 \ libglib2.0-0 \ libgtk-3-0 \ libnspr4 \ libnss3 \ libpango-1.0-0 \ libpangocairo-1.0-0 \ libstdc++6 \ libx11-6 \ libx11-xcb1 \ libxcb1 \ libxcomposite1 \ libxcursor1 \ libxdamage1 \ libxext6 \ libxfixes3 \ libxi6 \ libxrandr2 \ libxrender1 \ libxss1 \ libxtst6 \ lsb-release \ wget \ xdg-utils
# Install Node.js 20curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -sudo apt install -y nodejs
# Create application usersudo useradd -m -s /bin/bash puppeteersudo usermod -aG audio,video puppeteer
Application Setup
Section titled “Application Setup”# Switch to app usersudo su - puppeteer
# Clone repositorygit clone https://github.com/williamzujkowski/puppeteer-mcp.gitcd puppeteer-mcp
# Install dependenciesnpm ci --only=production
# Build applicationnpm run build
# Create systemd servicesudo tee /etc/systemd/system/puppeteer-mcp.service << EOF[Unit]Description=Puppeteer MCP ServerAfter=network.target
[Service]Type=simpleUser=puppeteerWorkingDirectory=/home/puppeteer/puppeteer-mcpExecStart=/usr/bin/node dist/index.jsRestart=alwaysRestartSec=10Environment=NODE_ENV=productionEnvironment=PUPPETEER_MCP_AUTH_TOKEN=your-secure-tokenEnvironment=PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser
# SecurityNoNewPrivileges=truePrivateTmp=trueProtectSystem=strictProtectHome=trueReadWritePaths=/home/puppeteer/puppeteer-mcp/logs
[Install]WantedBy=multi-user.targetEOF
# Enable and start servicesudo systemctl enable puppeteer-mcpsudo systemctl start puppeteer-mcp
SSL/TLS Configuration
Section titled “SSL/TLS Configuration”Using Let’s Encrypt
Section titled “Using Let’s Encrypt”# Install certbotsudo apt install certbot python3-certbot-nginx
# Obtain certificatesudo certbot --nginx -d api.yourdomain.com
# Auto-renewalsudo systemctl enable certbot.timer
Nginx Configuration
Section titled “Nginx Configuration”upstream puppeteer_backend { least_conn; server 127.0.0.1:3000 max_fails=3 fail_timeout=30s; server 127.0.0.1:3001 max_fails=3 fail_timeout=30s backup;}
upstream grpc_backend { least_conn; server 127.0.0.1:50051 max_fails=3 fail_timeout=30s;}
# HTTP to HTTPS redirectserver { listen 80; server_name api.yourdomain.com; return 301 https://$server_name$request_uri;}
# HTTPS serverserver { listen 443 ssl http2; server_name api.yourdomain.com;
# SSL configuration ssl_certificate /etc/letsencrypt/live/api.yourdomain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/api.yourdomain.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256; ssl_prefer_server_ciphers off;
# Security headers add_header Strict-Transport-Security "max-age=63072000" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always;
# REST API and WebSocket location / { proxy_pass http://puppeteer_backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade;
# Timeouts proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; }
# gRPC location /grpc { grpc_pass grpc://grpc_backend; error_page 502 = /grpc_error502; }
# Health check endpoint location /health { access_log off; proxy_pass http://puppeteer_backend/health; }}
Environment Configuration
Section titled “Environment Configuration”Production Environment Variables
Section titled “Production Environment Variables”NODE_ENV=production
# AuthenticationPUPPETEER_MCP_AUTH_TOKEN=your-very-secure-token-hereJWT_SECRET=your-jwt-secret-here
# ServerPORT=3000GRPC_PORT=50051HOST=0.0.0.0
# BrowserPUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browserPUPPETEER_HEADLESS=truePUPPETEER_ARGS=--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage
# SessionsMAX_SESSIONS=50SESSION_TIMEOUT=1800000SESSION_CHECK_INTERVAL=60000
# SecurityCORS_ORIGIN=https://app.yourdomain.comRATE_LIMIT_WINDOW=900000RATE_LIMIT_MAX=1000
# LoggingLOG_LEVEL=errorLOG_FILE=/home/puppeteer/puppeteer-mcp/logs/app.log
# MonitoringMETRICS_ENABLED=trueMETRICS_PORT=9090
Monitoring
Section titled “Monitoring”Prometheus Setup
Section titled “Prometheus Setup”global: scrape_interval: 15s
scrape_configs: - job_name: 'puppeteer-mcp' static_configs: - targets: ['localhost:9090'] relabel_configs: - source_labels: [__address__] target_label: instance replacement: 'server-1'
Grafana Dashboard
Section titled “Grafana Dashboard”{ "dashboard": { "title": "Puppeteer MCP Monitoring", "panels": [ { "title": "Active Sessions", "targets": [ { "expr": "puppeteer_active_sessions" } ] }, { "title": "Request Rate", "targets": [ { "expr": "rate(http_requests_total[5m])" } ] }, { "title": "Error Rate", "targets": [ { "expr": "rate(http_errors_total[5m])" } ] }, { "title": "Response Time", "targets": [ { "expr": "histogram_quantile(0.95, http_request_duration_seconds_bucket)" } ] } ] }}
Health Checks
Section titled “Health Checks”# Basic health checkcurl -f https://api.yourdomain.com/health
# Detailed health checkcurl -H "Authorization: Bearer $TOKEN" \ https://api.yourdomain.com/api/status
# Monitor with uptime services# - Pingdom# - UptimeRobot# - StatusCake
Logging
Section titled “Logging”Centralized Logging
Section titled “Centralized Logging”# Install Fluentdcurl -L https://toolbelt.treasuredata.com/sh/install-ubuntu-focal-td-agent4.sh | sh
# Configure Fluentdsudo tee /etc/td-agent/td-agent.conf << EOF<source> @type tail path /home/puppeteer/puppeteer-mcp/logs/*.log pos_file /var/log/td-agent/puppeteer-mcp.pos tag puppeteer.mcp <parse> @type json </parse></source>
<match puppeteer.**> @type elasticsearch host elasticsearch.yourdomain.com port 9200 logstash_format true logstash_prefix puppeteer include_tag_key true tag_key @log_name</match>EOF
Log Rotation
Section titled “Log Rotation”/home/puppeteer/puppeteer-mcp/logs/*.log { daily rotate 30 compress delaycompress notifempty create 0640 puppeteer puppeteer sharedscripts postrotate systemctl reload puppeteer-mcp >/dev/null 2>&1 endscript}
Backup Strategy
Section titled “Backup Strategy”Application Backup
Section titled “Application Backup”#!/bin/bashBACKUP_DIR="/backup/puppeteer-mcp"DATE=$(date +%Y%m%d_%H%M%S)
# Create backup directorymkdir -p $BACKUP_DIR
# Backup applicationtar -czf $BACKUP_DIR/app_$DATE.tar.gz \ --exclude='node_modules' \ --exclude='logs' \ /home/puppeteer/puppeteer-mcp
# Backup configurationtar -czf $BACKUP_DIR/config_$DATE.tar.gz \ /etc/nginx/sites-available/puppeteer-mcp \ /etc/systemd/system/puppeteer-mcp.service
# Clean old backups (keep 30 days)find $BACKUP_DIR -name "*.tar.gz" -mtime +30 -delete
# Sync to S3 (optional)aws s3 sync $BACKUP_DIR s3://your-backup-bucket/puppeteer-mcp/
Database Backup
Section titled “Database Backup”If using session persistence:
# PostgreSQL backuppg_dump -h localhost -U puppeteer puppeteer_mcp | \ gzip > $BACKUP_DIR/db_$DATE.sql.gz
# Redis backupredis-cli --rdb $BACKUP_DIR/redis_$DATE.rdb
Security Hardening
Section titled “Security Hardening”Firewall Configuration
Section titled “Firewall Configuration”# UFW configurationsudo ufw default deny incomingsudo ufw default allow outgoingsudo ufw allow sshsudo ufw allow 80/tcpsudo ufw allow 443/tcpsudo ufw allow from 10.0.0.0/8 to any port 3000sudo ufw allow from 10.0.0.0/8 to any port 50051sudo ufw --force enable
System Security
Section titled “System Security”# Fail2ban for SSHsudo apt install fail2bansudo systemctl enable fail2ban
# Automatic security updatessudo apt install unattended-upgradessudo dpkg-reconfigure -plow unattended-upgrades
Performance Tuning
Section titled “Performance Tuning”System Limits
Section titled “System Limits”puppeteer soft nofile 65535puppeteer hard nofile 65535puppeteer soft nproc 32768puppeteer hard nproc 32768
Kernel Parameters
Section titled “Kernel Parameters”net.core.somaxconn = 65535net.ipv4.tcp_max_syn_backlog = 65535net.ipv4.ip_local_port_range = 1024 65535net.ipv4.tcp_tw_reuse = 1fs.file-max = 65535
Maintenance
Section titled “Maintenance”Zero-Downtime Deployment
Section titled “Zero-Downtime Deployment”#!/bin/bash# Pull latest codecd /home/puppeteer/puppeteer-mcpgit pull origin main
# Install dependenciesnpm ci --only=production
# Buildnpm run build
# Graceful restartsudo systemctl reload puppeteer-mcp
Health Monitoring Script
Section titled “Health Monitoring Script”#!/bin/bashURL="https://api.yourdomain.com/health"WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
if ! curl -sf $URL > /dev/null; then curl -X POST $WEBHOOK \ -H 'Content-type: application/json' \ --data '{"text":"Puppeteer MCP is down!"}'fi
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”-
High Memory Usage
Terminal window # Check memoryfree -h# Find memory leakssudo -u puppeteer node --inspect dist/index.js -
Chrome Crashes
Terminal window # Check Chromechromium-browser --version# Test Chromechromium-browser --headless --disable-gpu --dump-dom https://example.com -
Performance Issues
Terminal window # Profile applicationsudo -u puppeteer node --prof dist/index.js# Analyze profilenode --prof-process isolate-*.log > profile.txt
Next Steps
Section titled “Next Steps”- Implement Scaling Strategies
- Set up Disaster Recovery
- Configure Advanced Monitoring
- Review Security Best Practices