From ed25a43d4a227c1b4033e14a078e9021a4114607 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 16 Feb 2026 14:31:10 +0700 Subject: [PATCH] 260216:1431 4rd Deploy (Prepare CI/CD: Revise .gitea/workflow/deploy.yaml) --- .gitea/workflows/deploy.yaml | 4 +-- specs/08-infrastructure/09_app_deployment.md | 35 ++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 8ed5dc4..0f4ff73 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -8,7 +8,7 @@ on: jobs: deploy: - runs-on: ubuntu-latest + runs-on: ubuntu-latest # ⚠️ ต้องตรงกับ Label ของ Runner ใน Gitea Settings (เช่น self-hosted) steps: - name: Deploy to QNAP via SSH uses: appleboy/ssh-action@v1.0.3 @@ -23,7 +23,7 @@ jobs: # 1. Update Code echo "📂 Pulling latest code..." - cd /share/np-dms/app/source + cd /share/np-dms/app/source/lcbp3 git pull origin main # 2. Build Backend diff --git a/specs/08-infrastructure/09_app_deployment.md b/specs/08-infrastructure/09_app_deployment.md index 6b0a129..05ace22 100644 --- a/specs/08-infrastructure/09_app_deployment.md +++ b/specs/08-infrastructure/09_app_deployment.md @@ -217,28 +217,29 @@ graph TD ### 7.3 วิธีการรันแบบ Manual (Manual Trigger) หากต้องการ Re-deploy โดยไม่ต้องแก้โค้ด: -1. ไปที่เมนู **Actions** ใน Gitea -2. เลือก Workflow **"Build and Deploy"** ทางซ้ายมือ -3. กดปุ่ม **Run workflow** -> เลือก Branch `main` -> กด **Run workflow** +1. ไปที่แถบเมนู **Actions** (อยู่ข้างๆ Pull Requests ที่เมนูด้านบนสุด **ไม่ใช่ในเมนู Settings**) +2. ทางซ้ายมือจะเห็นรายการ Workflow ให้เลือก **"Build and Deploy"** +3. หากมีไฟล์ `.yaml` ถูกต้อง จะมีปุ่ม **Run workflow** ปรากฏขึ้นมา (สีฟ้า/น้ำเงิน) +4. เลือก Branch `main` -> กด **Run workflow** เพื่อเริ่มทำงาน -### 7.4 การตรวจสอบและแก้ไขปัญหา (Troubleshooting) -* **ตรวจสอบ Runner:** หาก Action ค้างที่สถานะ "Waiting" ให้ตรวจสอบว่า Gitea Runner ใน ASUSTOR (หรือเครื่องที่ติดตั้ง) ทำงานอยู่หรือไม่ +### 7.4 ตัวอย่างข้อความแจ้งเตือนและการแก้ไขปัญหา (Troubleshooting) +* **❌ No matching online runner with label: ubuntu-latest:** + * **สาเหตุ:** แปลว่าในหน้า Settings -> Actions -> Runners **ไม่มี Runner ที่มีสถานะ Online และมีป้ายกำกับ (Label) ว่า `ubuntu-latest`** ครับ + * **วิธีแก้ 1:** ไปที่เมนู Settings -> Actions -> Runners กดแก้ไข Runner แล้วเพิ่ม Label `ubuntu-latest` เข้าไป (ถ้ามี Runner อยู่แล้ว) + * **วิธีแก้ 2:** แก้ไขไฟล์ `.gitea/workflows/deploy.yaml` ในบรรทัดที่ 11 จาก `runs-on: ubuntu-latest` ให้ตรงกับ **Label** ของ Runner ที่คุณมีจริง (เช่น `self-hosted` หรือชื่อที่คุณตั้งไว้) +* **📂 Paths:** ตรวจสอบว่า Code อยู่ในพาธที่ถูกต้อง (ปัจจุบันใช้ `/share/np-dms/app/source/lcbp3`) * **SSH Timeout:** ตรวจสอบว่า QNAP เปิด SSH Service และ Firewall (ACL) อนุญาตให้เครื่องที่เป็น Runner เชื่อมต่อมายัง Port 22 ได้ -* **Disk Full:** หาก Build ไม่ผ่านบ่อยๆ อาจเกิดจาก Disk เต็ม ให้รัน `docker image prune -a` บน QNAP เพื่อล้าง Image ทั้งหมดที่ไม่ถูกใช้งาน -* **Build Failure:** หากติด Error ตอน Build Frontend ให้ตรวจสอบว่า `NEXT_PUBLIC_API_URL` ใน `deploy.yaml` ถูกต้องตาม DNS ล่าสุดหรือไม่ +* **Disk Full:** หาก Build ไม่ผ่านบ่อยๆ ให้รัน `docker image prune -a` บน QNAP เพื่อล้าง Image เก่าออก ---- -### 7.5 การตรวจสอบ Gitea Runner (Critical Component) -Pipeline จะรันได้ต้องมี **act_runner** รันอยู่ในระบบ (ปกติจะติดตั้งบน ASUSTOR หรือ QNAP): -1. เข้าไปที่เมนู **Site Administration** (ต้องใช้สิทธิ์ Admin) -> **Actions** -> **Runners** -2. ตรวจสอบว่ามี Runner ที่มีสถานะเป็น **"Idle" (สีเขียว)** หรือไม่ -3. หากไม่มี Runner ให้ติดต่อ Admin เพื่อติดตั้งและ Register Runner ด้วย Token ที่ได้จากหน้าแอดมิน +### 7.5 การตรวจสอบ Gitea Runner (สำคัญมาก ⚠️) +จากรูปที่คุณส่งมา **Runners Management (Total: 0)** หมายความว่ายังไม่มีเครื่องที่จะมารันคำสั่ง Deploy ให้ครับ +* **ปัญหา:** แม้จะกด Run workflow ได้ แต่สถานะจะค้างที่ "Waiting" ตลอดไป +* **วิธีแก้:** ต้องทำการติดตั้งและ Register **Gitea Runner** (หรือ `act_runner`) ลงในเซิร์ฟเวอร์ (แนะนำ ASUSTOR) ให้เรียบร้อย จนกว่าสถานะในหน้า Settings จะขึ้น **Total: 1** หรือมากกว่า และเป็นสีเขียวครับ ### 7.6 ขั้นตอนการตรวจสอบผลการ Deploy -เมื่อมีการ Push โค้ดหรือรัน Manual แล้ว สามารถดูสถานะการ Deploy ได้ที่: -1. แท็บ **Actions** ในหน้าโปรเจกต์ Gitea -2. คลิกที่หัวข้อ Commit หรือ Workflow ล่าสุด -3. จะเห็นรายละเอียดของแต่ละขั้นตอน (Build Backend, Build Frontend, etc.) หากผ่านจะเป็นสีเขียว หากติดปัญหาจะเป็นสีแดงพร้อม Log รายละเอียด +เมื่อมีการรันแล้ว สามารถดูสถานะได้ที่: +1. คลิกที่รายการในหน้า **Actions** (หน้าหลักของ Actions) +2. จะเห็น Log รายละเอียดแต่ละ Step (Build Backend, Build Frontend, etc.) หากผ่านจะเป็นสีเขียวทั้งหมด ---