move folder and add supavisor
This commit is contained in:
464
02-supabase/README-SETUP2.md
Normal file
464
02-supabase/README-SETUP2.md
Normal file
@@ -0,0 +1,464 @@
|
||||
# Supabase Setup - Official Method (setup2.sh)
|
||||
|
||||
## 📖 Overview
|
||||
|
||||
`setup2.sh` เป็น setup script ที่ทำตามขั้นตอนจาก [Official Supabase Self-Hosting Guide](https://supabase.com/docs/guides/self-hosting/docker) อย่างเคร่งครัด
|
||||
|
||||
## 🔄 ความแตกต่างระหว่าง setup.sh และ setup2.sh
|
||||
|
||||
| Feature | setup.sh (Custom) | setup2.sh (Official) |
|
||||
|---------|-------------------|----------------------|
|
||||
| **แหล่งที่มา** | ดาวน์โหลด config files แยก | Clone official Supabase repo |
|
||||
| **docker-compose.yml** | Custom version | Official version (latest) |
|
||||
| **การ generate secrets** | Manual instructions | ใช้ official `generate-keys.sh` |
|
||||
| **การอัปเดต** | Manual | ตาม official releases |
|
||||
| **Port configuration** | Pre-configured | Auto-adjusted |
|
||||
| **แนะนำสำหรับ** | Quick setup, custom config | Production, official support |
|
||||
|
||||
## ✅ Prerequisites
|
||||
|
||||
ต้องติดตั้งก่อนรัน script:
|
||||
|
||||
1. **Git** - สำหรับ clone repository
|
||||
```bash
|
||||
git --version
|
||||
```
|
||||
|
||||
2. **Docker & Docker Compose**
|
||||
```bash
|
||||
docker --version
|
||||
docker compose version
|
||||
```
|
||||
|
||||
3. **OpenSSL** - สำหรับ generate secrets (มักติดตั้งมาแล้ว)
|
||||
```bash
|
||||
openssl version
|
||||
```
|
||||
|
||||
## 🚀 วิธีใช้งาน
|
||||
|
||||
### 1. รัน Setup Script
|
||||
|
||||
```bash
|
||||
cd 02-supabase
|
||||
bash setup2.sh
|
||||
```
|
||||
|
||||
Script จะทำสิ่งต่อไปนี้อัตโนมัติ:
|
||||
|
||||
1. ✅ ตรวจสอบ prerequisites (git, docker)
|
||||
2. 📥 Clone Supabase repository (depth=1 เพื่อความเร็ว)
|
||||
3. 📁 Copy official docker-compose.yml และ config files
|
||||
4. 🔧 ปรับ ports ให้ไม่ชนกับ services อื่น:
|
||||
- Kong HTTP: `8100` (แทน 8000)
|
||||
- PostgreSQL: `5434` (แทน 5432)
|
||||
- Pooler: `6544` (แทน 6543)
|
||||
5. 🌐 เพิ่ม `shared_data_network` configuration
|
||||
6. 🔐 รัน official `generate-keys.sh` เพื่อสร้าง JWT secrets และ API keys
|
||||
7. 📦 Pull Docker images ทั้งหมด
|
||||
8. 🧹 ลบ temporary files
|
||||
|
||||
### 2. Review และแก้ไข .env
|
||||
|
||||
หลังจากรัน script แล้ว ต้องแก้ไข `.env`:
|
||||
|
||||
```bash
|
||||
nano .env
|
||||
```
|
||||
|
||||
**สิ่งที่ต้องแก้ไข:**
|
||||
|
||||
```bash
|
||||
# 1. Database Password (REQUIRED)
|
||||
POSTGRES_PASSWORD=your-super-secret-postgres-password
|
||||
|
||||
# 2. Dashboard Credentials (REQUIRED)
|
||||
DASHBOARD_USERNAME=admin
|
||||
DASHBOARD_PASSWORD=your-secure-password-with-letters
|
||||
# ⚠️ Password ต้องมีตัวอักษรอย่างน้อย 1 ตัว (ห้ามใช้แต่ตัวเลข)
|
||||
|
||||
# 3. Public URLs (ถ้าใช้ domain name)
|
||||
SUPABASE_PUBLIC_URL=http://your-domain:8100
|
||||
API_EXTERNAL_URL=http://your-domain:8100
|
||||
SITE_URL=http://your-domain:3000
|
||||
|
||||
# หรือใช้ localhost สำหรับ development
|
||||
SUPABASE_PUBLIC_URL=http://localhost:8100
|
||||
API_EXTERNAL_URL=http://localhost:8100
|
||||
SITE_URL=http://localhost:3000
|
||||
```
|
||||
|
||||
**ไม่ต้องแก้ (auto-generated แล้ว):**
|
||||
- `JWT_SECRET` ✅
|
||||
- `ANON_KEY` ✅
|
||||
- `SERVICE_ROLE_KEY` ✅
|
||||
- `SECRET_KEY_BASE` ✅
|
||||
- `VAULT_ENC_KEY` ✅
|
||||
- `PG_META_CRYPTO_KEY` ✅
|
||||
- `LOGFLARE_PUBLIC_ACCESS_TOKEN` ✅
|
||||
- `LOGFLARE_PRIVATE_ACCESS_TOKEN` ✅
|
||||
- `S3_PROTOCOL_ACCESS_KEY_ID` ✅
|
||||
- `S3_PROTOCOL_ACCESS_KEY_SECRET` ✅
|
||||
|
||||
### 3. สร้าง Network (ถ้ายังไม่มี)
|
||||
|
||||
```bash
|
||||
cd ../00-network
|
||||
bash create-network.sh
|
||||
```
|
||||
|
||||
### 4. Start Supabase
|
||||
|
||||
```bash
|
||||
cd ../02-supabase
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### 5. ตรวจสอบ Services
|
||||
|
||||
```bash
|
||||
# ดู status ทั้งหมด
|
||||
docker compose ps
|
||||
|
||||
# ดู logs
|
||||
docker compose logs -f
|
||||
|
||||
# ดู logs ของ service เฉพาะ
|
||||
docker compose logs -f studio
|
||||
docker compose logs -f auth
|
||||
docker compose logs -f db
|
||||
```
|
||||
|
||||
รอประมาณ 1-2 นาที จนทุก service มี status `Up (healthy)`
|
||||
|
||||
## 🌐 Access Points
|
||||
|
||||
หลังจาก services ทั้งหมดรันแล้ว:
|
||||
|
||||
| Service | URL | Credentials |
|
||||
|---------|-----|-------------|
|
||||
| **Studio Dashboard** | http://localhost:8100 | DASHBOARD_USERNAME / DASHBOARD_PASSWORD |
|
||||
| **REST API** | http://localhost:8100/rest/v1/ | ANON_KEY or SERVICE_ROLE_KEY |
|
||||
| **Auth API** | http://localhost:8100/auth/v1/ | ANON_KEY or SERVICE_ROLE_KEY |
|
||||
| **Storage API** | http://localhost:8100/storage/v1/ | ANON_KEY or SERVICE_ROLE_KEY |
|
||||
| **Realtime** | http://localhost:8100/realtime/v1/ | ANON_KEY |
|
||||
| **PostgreSQL** | localhost:5434 | postgres / POSTGRES_PASSWORD |
|
||||
| **Pooler (Session)** | localhost:5434 | postgres.your-tenant-id / POSTGRES_PASSWORD |
|
||||
| **Pooler (Transaction)** | localhost:6544 | postgres.your-tenant-id / POSTGRES_PASSWORD |
|
||||
|
||||
## 📝 ไฟล์และ Directories ที่สร้างขึ้น
|
||||
|
||||
หลังจากรัน `setup2.sh`:
|
||||
|
||||
```
|
||||
02-supabase/
|
||||
├── docker-compose.yml # Official Supabase compose file
|
||||
├── .env # Environment variables (with generated secrets)
|
||||
├── .env.example.new # Backup of official .env.example
|
||||
├── volumes/ # Configuration and data
|
||||
│ ├── api/
|
||||
│ │ └── kong.yml # Kong API Gateway config
|
||||
│ ├── db/ # Database init scripts
|
||||
│ │ ├── realtime.sql
|
||||
│ │ ├── webhooks.sql
|
||||
│ │ ├── roles.sql
|
||||
│ │ ├── jwt.sql
|
||||
│ │ ├── _supabase.sql
|
||||
│ │ ├── logs.sql
|
||||
│ │ ├── pooler.sql
|
||||
│ │ └── data/ # PostgreSQL data (created on first run)
|
||||
│ ├── functions/ # Edge Functions
|
||||
│ │ └── main/
|
||||
│ ├── logs/
|
||||
│ │ └── vector.yml # Log collection config
|
||||
│ ├── pooler/
|
||||
│ │ └── pooler.exs # Connection pooler config
|
||||
│ ├── storage/ # File storage (created on first run)
|
||||
│ └── snippets/ # SQL snippets
|
||||
└── utils/
|
||||
└── generate-keys.sh # Official key generation script
|
||||
```
|
||||
|
||||
## 🔐 API Keys และ Secrets
|
||||
|
||||
### JWT Secret และ API Keys
|
||||
|
||||
Script จะ auto-generate ให้:
|
||||
|
||||
- **JWT_SECRET**: ใช้สำหรับ sign และ verify JWT tokens
|
||||
- **ANON_KEY**: Public API key (ใช้ใน client-side)
|
||||
- Role: `anon`
|
||||
- Expires: 5 years
|
||||
- **SERVICE_ROLE_KEY**: Private API key (ใช้ใน server-side)
|
||||
- Role: `service_role`
|
||||
- Bypass Row Level Security (RLS)
|
||||
- **ห้ามเปิดเผยใน client code!**
|
||||
|
||||
### ดู API Keys
|
||||
|
||||
```bash
|
||||
# ดู ANON_KEY
|
||||
grep ANON_KEY .env
|
||||
|
||||
# ดู SERVICE_ROLE_KEY
|
||||
grep SERVICE_ROLE_KEY .env
|
||||
```
|
||||
|
||||
### Verify JWT Tokens
|
||||
|
||||
ไปที่ [jwt.io](https://jwt.io) แล้ว:
|
||||
1. Paste `ANON_KEY` หรือ `SERVICE_ROLE_KEY`
|
||||
2. ใส่ `JWT_SECRET` ใน "Verify Signature" section
|
||||
3. ตรวจสอบ payload และ expiration
|
||||
|
||||
## 🔄 การอัปเดต Supabase
|
||||
|
||||
### วิธีที่ 1: รัน setup2.sh ใหม่
|
||||
|
||||
```bash
|
||||
cd 02-supabase
|
||||
|
||||
# Backup .env ปัจจุบัน
|
||||
cp .env .env.backup
|
||||
|
||||
# รัน setup2.sh ใหม่
|
||||
bash setup2.sh
|
||||
|
||||
# Restore .env settings ที่คุณแก้ไขไว้
|
||||
# (JWT secrets จะถูก generate ใหม่)
|
||||
|
||||
# Restart services
|
||||
docker compose down
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### วิธีที่ 2: Update แบบ Manual
|
||||
|
||||
```bash
|
||||
# Pull latest images
|
||||
docker compose pull
|
||||
|
||||
# Restart services
|
||||
docker compose down
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### วิธีที่ 3: Update Service เฉพาะ
|
||||
|
||||
```bash
|
||||
# 1. ดู version ล่าสุดที่ Docker Hub
|
||||
# https://hub.docker.com/u/supabase
|
||||
|
||||
# 2. แก้ไข docker-compose.yml
|
||||
# เช่น: image: supabase/studio:2026.02.16-sha-26c615c
|
||||
|
||||
# 3. Pull และ restart
|
||||
docker compose pull studio
|
||||
docker compose up -d studio
|
||||
```
|
||||
|
||||
## 🛠️ Maintenance
|
||||
|
||||
### Backup Database
|
||||
|
||||
```bash
|
||||
# Backup
|
||||
docker exec supabase-db pg_dump -U postgres postgres > backup_$(date +%Y%m%d).sql
|
||||
|
||||
# Restore
|
||||
docker exec -i supabase-db psql -U postgres postgres < backup_20260218.sql
|
||||
```
|
||||
|
||||
### Backup Storage
|
||||
|
||||
```bash
|
||||
# Backup storage files
|
||||
tar -czf storage_backup_$(date +%Y%m%d).tar.gz volumes/storage/
|
||||
|
||||
# Restore
|
||||
tar -xzf storage_backup_20260218.tar.gz
|
||||
```
|
||||
|
||||
### View Logs
|
||||
|
||||
```bash
|
||||
# All services
|
||||
docker compose logs -f
|
||||
|
||||
# Specific service
|
||||
docker compose logs -f studio
|
||||
docker compose logs -f auth
|
||||
docker compose logs -f db
|
||||
docker compose logs -f kong
|
||||
```
|
||||
|
||||
### Restart Services
|
||||
|
||||
```bash
|
||||
# Restart all
|
||||
docker compose restart
|
||||
|
||||
# Restart specific service
|
||||
docker compose restart studio
|
||||
docker compose restart auth
|
||||
```
|
||||
|
||||
## 🐛 Troubleshooting
|
||||
|
||||
### Services ไม่ start
|
||||
|
||||
```bash
|
||||
# ดู logs
|
||||
docker compose logs
|
||||
|
||||
# ตรวจสอบ network
|
||||
docker network inspect shared_data_network
|
||||
|
||||
# ตรวจสอบ .env
|
||||
cat .env | grep -v '^#' | grep -v '^$'
|
||||
```
|
||||
|
||||
### Database connection error
|
||||
|
||||
```bash
|
||||
# ตรวจสอบ database พร้อมหรือยัง
|
||||
docker exec supabase-db pg_isready -U postgres
|
||||
|
||||
# ดู database logs
|
||||
docker compose logs db
|
||||
```
|
||||
|
||||
### Port conflicts
|
||||
|
||||
ถ้า port ชน แก้ไขใน `.env`:
|
||||
|
||||
```bash
|
||||
KONG_HTTP_PORT=8101
|
||||
POSTGRES_PORT=5435
|
||||
POOLER_PROXY_PORT_TRANSACTION=6545
|
||||
```
|
||||
|
||||
แล้วแก้ใน `docker-compose.yml` ตรง ports mapping ด้วย
|
||||
|
||||
### "container supabase-vector exited (0)"
|
||||
|
||||
ถ้าใช้ rootless Docker ให้แก้ไข `.env`:
|
||||
|
||||
```bash
|
||||
DOCKER_SOCKET_LOCATION=/run/user/1000/docker.sock
|
||||
```
|
||||
|
||||
## 🔒 Security Best Practices
|
||||
|
||||
1. **เปลี่ยน default passwords ทั้งหมด**
|
||||
- `POSTGRES_PASSWORD`
|
||||
- `DASHBOARD_PASSWORD`
|
||||
|
||||
2. **ใช้ HTTPS ใน production**
|
||||
- Setup Nginx Proxy Manager
|
||||
- ติดตั้ง SSL certificate
|
||||
|
||||
3. **Enable Row Level Security (RLS)**
|
||||
- สำหรับทุก table ที่มี sensitive data
|
||||
|
||||
4. **เก็บ SERVICE_ROLE_KEY ปลอดภัย**
|
||||
- ใช้เฉพาะ server-side
|
||||
- ห้ามเปิดเผยใน client code
|
||||
|
||||
5. **Backup เป็นประจำ**
|
||||
- Database
|
||||
- Storage files
|
||||
- .env file
|
||||
|
||||
6. **Monitor logs**
|
||||
- ตรวจสอบ suspicious activities
|
||||
- ใช้ Logflare analytics
|
||||
|
||||
7. **Update เป็นประจำ**
|
||||
- ติดตาม [Supabase Changelog](https://github.com/supabase/supabase/blob/master/docker/CHANGELOG.md)
|
||||
- Update images สำหรับ security patches
|
||||
|
||||
## 🗑️ Uninstall
|
||||
|
||||
**⚠️ คำเตือน: จะลบข้อมูลทั้งหมด!**
|
||||
|
||||
```bash
|
||||
# Stop และลบ containers + volumes
|
||||
docker compose down -v
|
||||
|
||||
# ลบ database data
|
||||
rm -rf volumes/db/data
|
||||
|
||||
# ลบ storage data
|
||||
rm -rf volumes/storage
|
||||
|
||||
# ลบทุกอย่าง (optional)
|
||||
cd ..
|
||||
rm -rf 02-supabase
|
||||
```
|
||||
|
||||
## 📚 เอกสารเพิ่มเติม
|
||||
|
||||
- [Official Self-Hosting Guide](https://supabase.com/docs/guides/self-hosting/docker)
|
||||
- [Supabase Docker Changelog](https://github.com/supabase/supabase/blob/master/docker/CHANGELOG.md)
|
||||
- [Supabase GitHub](https://github.com/supabase/supabase)
|
||||
- [Docker Hub - Supabase Images](https://hub.docker.com/u/supabase)
|
||||
- [PostgREST Documentation](https://postgrest.org/)
|
||||
- [GoTrue (Auth) Documentation](https://github.com/supabase/gotrue)
|
||||
|
||||
## 💡 Tips
|
||||
|
||||
1. **ใช้ generate-keys.sh ใหม่เมื่อต้องการ**
|
||||
```bash
|
||||
bash utils/generate-keys.sh
|
||||
```
|
||||
|
||||
2. **Test API ด้วย curl**
|
||||
```bash
|
||||
# Get ANON_KEY from .env
|
||||
ANON_KEY=$(grep ANON_KEY .env | cut -d '=' -f2)
|
||||
|
||||
# Test REST API
|
||||
curl http://localhost:8100/rest/v1/ \
|
||||
-H "apikey: $ANON_KEY" \
|
||||
-H "Authorization: Bearer $ANON_KEY"
|
||||
```
|
||||
|
||||
3. **Connect จาก client application**
|
||||
```javascript
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
|
||||
const supabase = createClient(
|
||||
'http://localhost:8100',
|
||||
'YOUR_ANON_KEY'
|
||||
)
|
||||
```
|
||||
|
||||
4. **ใช้ Supabase CLI สำหรับ development**
|
||||
```bash
|
||||
npm install -g supabase
|
||||
supabase link --project-ref your-project
|
||||
```
|
||||
|
||||
## 🆚 เมื่อไหร่ควรใช้ setup2.sh
|
||||
|
||||
ใช้ **setup2.sh** เมื่อ:
|
||||
- ✅ ต้องการ official configuration ล่าสุด
|
||||
- ✅ ต้องการ update ง่ายตาม official releases
|
||||
- ✅ ต้องการใช้ official tools (generate-keys.sh)
|
||||
- ✅ Production deployment
|
||||
- ✅ ต้องการ official support
|
||||
|
||||
ใช้ **setup.sh** เมื่อ:
|
||||
- ✅ ต้องการ quick setup
|
||||
- ✅ ต้องการ custom configuration
|
||||
- ✅ ต้องการ minimal setup
|
||||
- ✅ Development/testing เท่านั้น
|
||||
|
||||
## 📞 Support
|
||||
|
||||
หากมีปัญหา:
|
||||
1. ตรวจสอบ logs: `docker compose logs`
|
||||
2. อ่าน [Troubleshooting Guide](https://supabase.com/docs/guides/self-hosting/docker#troubleshooting)
|
||||
3. ดู [GitHub Discussions](https://github.com/supabase/supabase/discussions)
|
||||
4. ตรวจสอบ [GitHub Issues](https://github.com/supabase/supabase/issues)
|
||||
Reference in New Issue
Block a user