build and create deploy production
This commit is contained in:
61
server-setup.sh
Executable file
61
server-setup.sh
Executable file
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Server setup untuk optimasi memory dan build
|
||||
# Jalankan dengan sudo di server production
|
||||
|
||||
echo "🔧 Setting up server for optimized building..."
|
||||
|
||||
# 1. Check current memory
|
||||
echo "📊 Current memory status:"
|
||||
free -h
|
||||
|
||||
# 2. Setup swap file (temporary solution for low memory)
|
||||
echo "💾 Setting up swap file (1GB)..."
|
||||
if [ ! -f /swapfile ]; then
|
||||
fallocate -l 1G /swapfile
|
||||
chmod 600 /swapfile
|
||||
mkswap /swapfile
|
||||
sysctl vm.swappiness=10
|
||||
echo '/swapfile none swap sw 0 0' >> /etc/fstab
|
||||
echo 'vm.swappiness=10' >> /etc/sysctl.conf
|
||||
swapon /swapfile
|
||||
echo "✅ Swap file created and activated"
|
||||
else
|
||||
echo "ℹ️ Swap file already exists"
|
||||
fi
|
||||
|
||||
# 3. Optimize Node.js for production
|
||||
echo "⚙️ Optimizing Node.js..."
|
||||
npm config set fund false
|
||||
npm config set audit false
|
||||
|
||||
# 4. Install PM2 untuk process management
|
||||
echo "📦 Installing PM2..."
|
||||
npm install -g pm2
|
||||
|
||||
# 5. Create PM2 ecosystem file for build process
|
||||
cat > ecosystem.config.js << 'EOF'
|
||||
module.exports = {
|
||||
apps: [{
|
||||
name: 'build-app',
|
||||
script: 'npm',
|
||||
args: 'run build:prod',
|
||||
instances: 1,
|
||||
autorestart: false,
|
||||
watch: false,
|
||||
max_memory_restart: '1G',
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
NODE_OPTIONS: '--max-old-space-size=1024'
|
||||
}
|
||||
}]
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "✅ Server setup completed!"
|
||||
echo ""
|
||||
echo "📝 Now you can:"
|
||||
echo " 1. Build with memory limit: npm run build:prod"
|
||||
echo " 2. Build with PM2: pm2 start ecosystem.config.js"
|
||||
echo " 3. Monitor: pm2 monit"
|
||||
echo " 4. Check memory: free -h"
|
||||
Reference in New Issue
Block a user