Gunakan skill ini untuk semua operasi deployment QuantLab — backend ke AWS EC2 (systemd), frontend ke Cloudflare Pages, setup SSL/HTTPS, Supabase database, GitHub Actions CI/CD, dan monitoring. Mencakup troubleshooting deployment failures.
Skill ini memandu agent dalam semua aspek deployment QuantLab ke production dan pengelolaan infrastruktur.
Aktifkan OTOMATIS jika:
┌─────────────────────────────────────────────────────────────┐
│ FRONTEND: Cloudflare Pages │
│ URL: https://quantlab.bamsbung.com │
│ Deploy: git push → GitHub Actions → wrangler pages deploy │
│ Build: npm run build → dist/ → CF Pages │
└─────────────────┬───────────────────────────────────────────┘
│ HTTPS API calls
┌─────────────────▼───────────────────────────────────────────┐
│ BACKEND: AWS EC2 │
│ IP: 54.251.201.70 │
│ Port: 8080 (HTTP) → TODO: 443 (HTTPS via nginx) │
│ Server: Ubuntu 24.04, 2 vCPU, 914MB RAM │
│ Binary: /opt/quantlab/quantlab-api (4.8MB) │
│ Service: systemd quantlab-api.service │
│ Runtime: 9.5 MB RSS (sangat efisien) │
└─────────────────────────────────────────────────────────────┘
Prerequisites:
main branch# .github/workflows/backend.yml akan otomatis:
# 1. cargo test → cargo clippy → cargo audit
# 2. cargo build --release → strip binary
# 3. SCP binary ke EC2
# 4. systemctl restart quantlab-api
# 5. curl /v1/health → verify
# 1. Build lokal (jika environment Linux/WSL)
cd .Production/backend/rust-api
cargo build --release
strip target/release/quantlab-api
# 2. SCP ke server
scp -i ~/.ssh/ec2.pem target/release/quantlab-api [email protected]:/tmp/
# 3. SSH ke server
ssh -i ~/.ssh/ec2.pem [email protected]
# 4. Di server:
sudo systemctl stop quantlab-api
sudo cp /tmp/quantlab-api /opt/quantlab/quantlab-api
sudo chmod +x /opt/quantlab/quantlab-api
sudo systemctl start quantlab-api
sudo systemctl status quantlab-api
# 5. Verify
curl http://localhost:8080/v1/health
# SSH ke server
ssh -i ~/.ssh/ec2.pem [email protected]
# Setup swap jika belum ada (diperlukan untuk cargo build --release)
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
# Clone/pull kode terbaru
cd /opt/quantlab/src
git pull origin main
# Build (⚠️ akan butuh ~5-10 menit dengan 2GB swap)
cargo build --release
# Deploy
sudo systemctl stop quantlab-api
sudo cp target/release/quantlab-api /opt/quantlab/quantlab-api
sudo systemctl start quantlab-api
# Push ke main → CI otomatis deploy
git push origin main
cd .Production/frontend
# Build
npm run build
# Deploy
npx wrangler pages deploy dist \
--project-name=quantlab \
--commit-message="Manual deploy $(date +%Y-%m-%d)"
Dashboard: https://dash.cloudflare.com
→ Pages → quantlab → Settings → Environment Variables
→ Add untuk Production DAN Preview:
PUBLIC_SUPABASE_URL = https://supabase.bamsbung.com
PUBLIC_SUPABASE_ANON_KEY = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.[200+ chars]
PUBLIC_API_BASE = https://[ec2-ip]/v1
⚠️ PENTING: Set untuk Production DAN Preview environment! ⚠️ Setelah set env vars, klik Save lalu trigger redeploy!
Settings → Secrets and variables → Actions → New repository secret
EC2_HOST = 54.251.201.70
EC2_USER = ubuntu
EC2_SSH_KEY = [isi konten file .pem LENGKAP termasuk header]
BINANCE_API_KEY = [Binance API key]
BINANCE_API_SECRET = [Binance API secret]
Settings → Secrets and variables → Actions → New repository secret
CLOUDFLARE_API_TOKEN = [Token CF dengan Pages:Edit permission]
CLOUDFLARE_ACCOUNT_ID = [Account ID dari CF dashboard]
Cloudflare Dashboard → My Profile → API Tokens → Create Token
→ Use template: "Edit Cloudflare Pages"
→ Permissions: Zone: Pages: Edit
→ Account: [your account]
→ Save → Copy token
# Test token:
curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
-H "Authorization: Bearer [TOKEN]" \
-H "Content-Type: application/json"
# Expected: {"result":{"status":"active"}}
Backend saat ini hanya HTTP (port 8080). Frontend (HTTPS) tidak bisa call HTTP backend di production.
# SSH ke EC2
ssh -i ~/.ssh/ec2.pem [email protected]
# Install nginx
sudo apt-get update
sudo apt-get install -y nginx certbot python3-certbot-nginx
# Buat domain dulu: api.quantlab.bamsbung.com → 54.251.201.70
# (Set A record di DNS: api.quantlab.bamsbung.com → 54.251.201.70)
# Konfigurasi nginx
sudo nano /etc/nginx/sites-available/quantlab-api
# Isi:
server {
listen 80;
server_name api.quantlab.bamsbung.com;
location / {
proxy_pass http://127.0.0.1:8080;
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;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
# Aktifkan site
sudo ln -s /etc/nginx/sites-available/quantlab-api /etc/nginx/sites-enabled/
sudo nginx -t # test config
sudo systemctl restart nginx
# Get SSL cert
sudo certbot --nginx -d api.quantlab.bamsbung.com
# Verify
curl https://api.quantlab.bamsbung.com/v1/health
# Install cloudflared
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb
# Login dan create tunnel
cloudflared tunnel login
cloudflared tunnel create quantlab-api
# Config file
nano ~/.cloudflared/config.yml
# isi: