Initial commit for homaroma
This commit is contained in:
commit
f2179cfe57
269 files changed
+22635
No files matched your search
@@ -0,0 +1,2 @@
|
||||
DATABASE_URL="postgresql://postgres:password@localhost:5132/homaroma_db?schema=public"
|
||||
PORT=3051
|
||||
@@ -0,0 +1,17 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name admin.homaroma.shop;
|
||||
location /.well-known/acme-challenge/ { root /var/www/certbot; }
|
||||
location / { return 301 https://$host$request_uri; }
|
||||
}
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name admin.homaroma.shop;
|
||||
ssl_certificate /etc/letsencrypt/live/admin.homaroma.shop/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/admin.homaroma.shop/privkey.pem;
|
||||
location / {
|
||||
root /usr/share/nginx/html/homaroma.shop/admin;
|
||||
index index.html index.htm;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name api.homaroma.shop;
|
||||
location /.well-known/acme-challenge/ { root /var/www/certbot; }
|
||||
location / { return 301 https://$host$request_uri; }
|
||||
}
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name api.homaroma.shop;
|
||||
client_max_body_size 20m;
|
||||
ssl_certificate /etc/letsencrypt/live/api.homaroma.shop/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/api.homaroma.shop/privkey.pem;
|
||||
location / {
|
||||
proxy_pass http://192.168.1.167:3051;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name homaroma.shop www.homaroma.shop;
|
||||
location /.well-known/acme-challenge/ { root /var/www/certbot; }
|
||||
location / { return 301 https://$host$request_uri; }
|
||||
}
|
||||
server {
|
||||
listen 443 ssl;
|
||||
server_name homaroma.shop www.homaroma.shop;
|
||||
ssl_certificate /etc/letsencrypt/live/homaroma.shop/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/homaroma.shop/privkey.pem;
|
||||
location / {
|
||||
proxy_pass http://192.168.1.167:3002;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection 'upgrade';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ==============================================================================
|
||||
# iRelax Project - Integrated Deployment Script (post-receive hook)
|
||||
# ==============================================================================
|
||||
|
||||
# 1. TARGET PATHS (Nginx & PM2)
|
||||
TARGET_WEBSITE="/home/ti/projects/MyNginxMain/nginx/html/homaroma.shop/website"
|
||||
TARGET_ADMIN="/home/ti/projects/MyNginxMain/nginx/html/homaroma.shop/admin"
|
||||
TARGET_BACKEND="/home/ti/projects/homaroma-api"
|
||||
TARGET_SSR="/home/ti/projects/homaroma-ssr" # <-- Next.js SSR App
|
||||
|
||||
# 2. REPOSITORY CONFIG
|
||||
REPO="/home/ti/git/homaroma.git"
|
||||
BRANCH="master"
|
||||
TEMP_DIR="/tmp/homaroma_build_$(date +%s)"
|
||||
|
||||
# 3. BINARY PATHS & PM2
|
||||
BUN="/home/ti/.bun/bin/bun"
|
||||
PM2="/home/ti/.nvm/versions/node/v22.17.1/bin/pm2"
|
||||
PM2_NAME_BACKEND="homaroma-backend"
|
||||
PM2_NAME_SSR="homaroma-ssr" # <-- PM2 process name สำหรับ SSR
|
||||
export PATH="$PATH:/home/ti/.bun/bin:/home/ti/.nvm/versions/node/v22.17.1/bin"
|
||||
|
||||
# 4. BUILD ENVIRONMENT
|
||||
export VITE_API_URL="https://api.homaroma.shop/api"
|
||||
export VITE_LIFF_ID="2009944751-5IYZT5kH" # <-- สำหรับ LINE LIFF
|
||||
export NEXT_PUBLIC_API_URL="https://api.homaroma.shop/api" # <-- สำหรับ SSR (Client-side fetch)
|
||||
|
||||
# Port ของ Next.js SSR (Nginx จะ proxy_pass มาที่นี่)
|
||||
SSR_PORT=3002
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# START DEPLOYMENT
|
||||
# ------------------------------------------------------------------------------
|
||||
set -e
|
||||
echo "------- 🚀 Starting Full Deployment: iRelax Platform -------"
|
||||
|
||||
# A. Prepare Temp Source from Checkout
|
||||
echo "Cloning branch $BRANCH to temporary directory: $TEMP_DIR"
|
||||
mkdir -p $TEMP_DIR
|
||||
git --work-tree=$TEMP_DIR --git-dir=$REPO checkout -f $BRANCH
|
||||
|
||||
cd $TEMP_DIR
|
||||
echo "Installing monorepo dependencies..."
|
||||
$BUN install
|
||||
|
||||
# B. Build & Deploy WEBSITE (Frontend SPA)
|
||||
echo ">>> Building Website..."
|
||||
cd apps/website
|
||||
$BUN run build
|
||||
echo "Deploying Website to $TARGET_WEBSITE..."
|
||||
mkdir -p $TARGET_WEBSITE
|
||||
rm -rf $TARGET_WEBSITE/*
|
||||
cp -rv dist/* $TARGET_WEBSITE/
|
||||
cd ../..
|
||||
|
||||
# C. Build & Deploy ADMIN PANEL
|
||||
echo ">>> Building Admin Panel..."
|
||||
cd apps/admin
|
||||
$BUN run build
|
||||
echo "Deploying Admin Panel to $TARGET_ADMIN..."
|
||||
mkdir -p $TARGET_ADMIN
|
||||
rm -rf $TARGET_ADMIN/*
|
||||
cp -rv dist/* $TARGET_ADMIN/
|
||||
cd ../..
|
||||
|
||||
# D. Deploy & Manage BACKEND (API)
|
||||
echo ">>> Updating Backend at $TARGET_BACKEND..."
|
||||
mkdir -p $TARGET_BACKEND
|
||||
|
||||
# Sync Backend Source (--exclude .env เพื่อป้องกันการลบ .env บน server!)
|
||||
rsync -av --delete \
|
||||
--exclude='.env' \
|
||||
--exclude='public/' \
|
||||
--exclude='node_modules/' \
|
||||
apps/backend/ $TARGET_BACKEND/
|
||||
|
||||
# Sync Shared Packages
|
||||
mkdir -p $TARGET_BACKEND/packages
|
||||
rsync -av packages/ $TARGET_BACKEND/packages/
|
||||
|
||||
cd $TARGET_BACKEND
|
||||
echo "Installing backend dependencies..."
|
||||
$BUN install
|
||||
|
||||
# สร้าง public/ folder สำหรับ static files (upload images)
|
||||
mkdir -p $TARGET_BACKEND/public
|
||||
|
||||
# Generate Prisma Client (สำคัญมาก! ต้องรันทุกครั้งหลัง install)
|
||||
echo ">>> Generating Prisma Client..."
|
||||
$BUN x prisma generate
|
||||
|
||||
# E. Database Migration (Safe Method)
|
||||
if [ -f ".env" ]; then
|
||||
echo ">>> Running Prisma Migrate Deploy..."
|
||||
$BUN x prisma migrate deploy
|
||||
else
|
||||
echo "⚠️ Warning: .env not found at $TARGET_BACKEND/.env"
|
||||
echo " Please create it manually once: see serverinfo/text.txt for template"
|
||||
echo " Skipping migrations this time."
|
||||
fi
|
||||
|
||||
# F. PM2 Management - BACKEND
|
||||
echo ">>> Managing PM2 Process: $PM2_NAME_BACKEND..."
|
||||
$PM2 restart $PM2_NAME_BACKEND 2>/dev/null || \
|
||||
$PM2 start src/index.ts --name $PM2_NAME_BACKEND --interpreter $BUN
|
||||
echo "✅ PM2 process '$PM2_NAME_BACKEND' is running."
|
||||
|
||||
# G. Build & Deploy SSR (Next.js)
|
||||
echo ">>> Building Next.js SSR App inside monorepo temp dir..."
|
||||
cd $TEMP_DIR/apps/ssr
|
||||
$BUN run build # build จาก monorepo (workspace:* resolve ได้)
|
||||
|
||||
echo ">>> Syncing built SSR App to $TARGET_SSR..."
|
||||
mkdir -p $TARGET_SSR
|
||||
|
||||
# Sync ทั้ง source + .next/ ไปยัง TARGET_SSR
|
||||
rsync -av --delete \
|
||||
--exclude='.env' \
|
||||
--exclude='.env.local' \
|
||||
--exclude='node_modules/' \
|
||||
$TEMP_DIR/apps/ssr/ $TARGET_SSR/
|
||||
|
||||
# Sync packages ไปด้วย
|
||||
mkdir -p $TARGET_SSR/packages
|
||||
rsync -av $TEMP_DIR/packages/ $TARGET_SSR/packages/
|
||||
|
||||
# Sync root node_modules ไปยัง TARGET_SSR
|
||||
# (bun workspace ติดตั้ง next ไว้ที่ root node_modules ไม่ใช่ apps/ssr/node_modules)
|
||||
echo ">>> Syncing root node_modules to $TARGET_SSR..."
|
||||
rsync -a --delete $TEMP_DIR/node_modules/ $TARGET_SSR/node_modules/
|
||||
|
||||
# H. PM2 Management - SSR Next.js
|
||||
cd $TARGET_SSR
|
||||
echo ">>> Managing PM2 Process: $PM2_NAME_SSR..."
|
||||
$PM2 restart $PM2_NAME_SSR 2>/dev/null || \
|
||||
$PM2 start $TARGET_SSR/node_modules/.bin/next --name $PM2_NAME_SSR \
|
||||
-- start -p $SSR_PORT
|
||||
echo "✅ PM2 process '$PM2_NAME_SSR' is running on port $SSR_PORT."
|
||||
|
||||
# I. Cleanup
|
||||
echo "Cleaning up build artifacts..."
|
||||
rm -rf $TEMP_DIR
|
||||
|
||||
echo "------- ✅ ALL DEPLOYMENTS COMPLETED SUCCESSFULLY -------"
|
||||
echo ""
|
||||
echo "📋 Service Summary:"
|
||||
echo " 🌐 Website (SPA) → https://homaroma.shop"
|
||||
echo " 🔧 Admin Panel → https://admin.homaroma.shop"
|
||||
echo " 🔌 API Backend → https://api.homaroma.shop (PM2: $PM2_NAME_BACKEND)"
|
||||
echo " 🚀 SSR Next.js → https://ssr.homaroma.shop (PM2: $PM2_NAME_SSR, Port: $SSR_PORT)"
|
||||
@@ -0,0 +1,6 @@
|
||||
ti@pc-server:~/projects/MyNginxMain/nginx/html/irelaxaroma.shop$ ls -la
|
||||
total 16
|
||||
drwxrwxr-x 4 ti ti 4096 Apr 5 04:30 .
|
||||
drwxrwxr-x 24 ti ti 4096 Apr 5 04:29 ..
|
||||
drwxrwxr-x 2 ti ti 4096 Apr 5 04:30 admin
|
||||
drwxrwxr-x 2 ti ti 4096 Apr 5 04:29 website
|
||||
Reference in new issue
Block a user