Files
homaroma/DDC_DEPLOYMENT_RUNBOOK.md
T
2026-10-01 05:49:58 +07:00

187 lines
4.6 KiB
Markdown

# DDC Deployment Runbook
> **Tenant operational runbook:** This document records DDC deployment configuration. Preserve its hostnames, paths, and process identifiers as operational facts; they are not DBK Platform branding.
เอกสารนี้เป็น runbook เฉพาะลูกค้า `ddc` โดยอิงจาก `DEPLOYMENT_GUIDE.md` และไฟล์ตัวอย่างใน `serverinfo/pkh-*`
## Target
- Project name: `ddc`
- Website: `https://ddc.kittisak.com`
- SPA: `https://spa.ddc.kittisak.com`
- Admin: `https://admin.ddc.kittisak.com`
- API: `https://api.ddc.kittisak.com`
- Database: `ddcdb`
- Website SSR port: `3004`
- Backend API port: `3053`
- Bare repo: `/home/ti/git/ddc-website.git`
- Backend path: `/home/ti/projects/ddc-api`
- Website path: `/home/ti/projects/ddc-website`
- SPA static path: `/home/ti/projects/MyNginxMain/nginx/html/ddc/spa`
- Admin static path: `/home/ti/projects/MyNginxMain/nginx/html/ddc/admin`
## Files Prepared In This Repo
- `serverinfo/ddc-post-receive`
- `serverinfo/ddc-backend.env.example`
- `serverinfo/ddc-nginx/ddc.kittisak.com.conf`
- `serverinfo/ddc-nginx/spa.ddc.kittisak.com.conf`
- `serverinfo/ddc-nginx/admin.ddc.kittisak.com.conf`
- `serverinfo/ddc-nginx/api.ddc.kittisak.com.conf`
## Preflight On Server
Run on `kitizone.com` before changing live services:
```bash
ss -ltnp | grep -E ':3004|:3053' || true
pm2 list
```
If ports `3004` or `3053` are already used, stop and choose new ports before applying these files.
## 1. Create Bare Git Repository
```bash
mkdir -p /home/ti/git/ddc-website.git
cd /home/ti/git/ddc-website.git
git init --bare
```
## 2. Create Project Directories
```bash
mkdir -p /home/ti/projects/ddc-api
mkdir -p /home/ti/projects/ddc-website
mkdir -p /home/ti/projects/MyNginxMain/nginx/html/ddc/spa
mkdir -p /home/ti/projects/MyNginxMain/nginx/html/ddc/admin
```
## 3. Create Database
```bash
docker exec -it arokro_postgres bash
psql -U postgres -c "CREATE DATABASE ddcdb;"
exit
```
## 4. Open Firewall Ports
```bash
sudo ufw allow 3004/tcp
sudo ufw allow 3053/tcp
sudo ufw reload
```
## 5. Request SSL Certificates
```bash
cd /home/ti/projects/MyNginxMain
docker compose stop nginx
docker compose run --rm certbot certonly --standalone \
-d ddc.kittisak.com \
-d spa.ddc.kittisak.com \
-d admin.ddc.kittisak.com \
-d api.ddc.kittisak.com
```
## 6. Install Nginx Configs
Copy files from `serverinfo/ddc-nginx/` to:
```text
/home/ti/projects/MyNginxMain/nginx/conf.d/
```
Then validate and restart nginx:
```bash
cd /home/ti/projects/MyNginxMain
docker compose run --rm nginx nginx -t
docker compose up -d nginx
```
## 7. Install Backend Environment File
Create this server file:
```text
/home/ti/projects/ddc-api/.env
```
Use `serverinfo/ddc-backend.env.example` as the base and replace placeholders before production use:
- `postgres:password` must match the real Postgres password.
- `JWT_SECRET` must be a new project-specific secret.
- `OMISE_SECRET_KEY` must be set if payments are enabled.
The deploy hook copies this file into `/home/ti/projects/ddc-api/apps/backend/.env` before Prisma commands.
## 8. Install Git Hook
Copy:
```text
serverinfo/ddc-post-receive
```
To:
```text
/home/ti/git/ddc-website.git/hooks/post-receive
```
Then run:
```bash
chmod +x /home/ti/git/ddc-website.git/hooks/post-receive
```
## 9. Deploy From Developer Machine
```bash
git remote add ddc-website ti@kitizone.com:/home/ti/git/ddc-website.git
git push ddc-website master
```
## 10. Seed Database
Run after the first successful deployment:
```bash
ssh ti@kitizone.com
cd /home/ti/projects/ddc-api/apps/backend
export PATH=$PATH:/home/ti/.bun/bin:/home/ti/.nvm/versions/node/v22.17.1/bin
bun run prisma/seed.cjs
```
Default seeded admin account is currently `admin / homaroma123`. Change it before handing production access to the customer.
## Verification
```bash
pm2 list
curl -I https://ddc.kittisak.com
curl -I https://spa.ddc.kittisak.com
curl -I https://admin.ddc.kittisak.com
curl -I https://api.ddc.kittisak.com
```
Expected PM2 processes:
- `ddc-backend`
- `ddc-website`
Check browser console for:
- CORS errors on admin and SPA
- missing static assets
- API 504 from website SSR build or runtime fetches
## Known Risks
- `serverinfo/ddc-post-receive` rewrites `ecosystem.config.js` at deploy time from the base `homaroma` config. This follows the existing `pkh` pattern.
- The codebase still contains some hardcoded HomAroma URLs and storage keys in app code. This runbook only prepares infrastructure deployment, not full white-label branding cleanup.
- Payments and LINE LIFF need customer-specific production keys before launch.