diff --git a/.gitea/workflows/deploy.yaml b/.gitea/workflows/deploy.yaml index 0f4ff73..a8415e9 100644 --- a/.gitea/workflows/deploy.yaml +++ b/.gitea/workflows/deploy.yaml @@ -19,6 +19,9 @@ jobs: port: ${{ secrets.PORT }} script_stop_signal: true # Stop script on error script: | + # ⚠️ QNAP SSH ไม่มี PATH เต็ม ต้อง export เอง + export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:$PATH" + echo "🚀 Starting Deployment..." # 1. Update Code @@ -35,11 +38,11 @@ jobs: docker build -f frontend/Dockerfile \ --build-arg NEXT_PUBLIC_API_URL=https://backend.np-dms.work/api \ -t lcbp3-frontend:latest . - + # 4. Update Containers echo "🔄 Updating Containers..." cd /share/np-dms/app - docker-compose up -d + docker compose -f docker-compose-app.yml up -d # 5. Cleanup echo "🧹 Cleaning up unused images..." diff --git a/specs/08-infrastructure/09_app_deployment.md b/specs/08-infrastructure/09_app_deployment.md index 05ace22..45f9d0d 100644 --- a/specs/08-infrastructure/09_app_deployment.md +++ b/specs/08-infrastructure/09_app_deployment.md @@ -234,7 +234,8 @@ graph TD ### 7.5 การตรวจสอบ Gitea Runner (สำคัญมาก ⚠️) จากรูปที่คุณส่งมา **Runners Management (Total: 0)** หมายความว่ายังไม่มีเครื่องที่จะมารันคำสั่ง Deploy ให้ครับ * **ปัญหา:** แม้จะกด Run workflow ได้ แต่สถานะจะค้างที่ "Waiting" ตลอดไป -* **วิธีแก้:** ต้องทำการติดตั้งและ Register **Gitea Runner** (หรือ `act_runner`) ลงในเซิร์ฟเวอร์ (แนะนำ ASUSTOR) ให้เรียบร้อย จนกว่าสถานะในหน้า Settings จะขึ้น **Total: 1** หรือมากกว่า และเป็นสีเขียวครับ +* **วิธีแก้:** ต้องทำการติดตั้งและ Register **Gitea Runner** (หรือ `act_runner`) ตามคู่มือนี้ครับ: [10_gitea_runner.md](10_gitea_runner.md) +* **ผลลัพธ์:** เมื่อติดตั้งสำเร็จ สถานะในหน้า Settings จะขึ้น **Total: 1** หรือมากกว่า และเป็นสีเขียวครับ ### 7.6 ขั้นตอนการตรวจสอบผลการ Deploy เมื่อมีการรันแล้ว สามารถดูสถานะได้ที่: diff --git a/specs/08-infrastructure/10_gitea_runner.md b/specs/08-infrastructure/10_gitea_runner.md new file mode 100644 index 0000000..83d5fdf --- /dev/null +++ b/specs/08-infrastructure/10_gitea_runner.md @@ -0,0 +1,74 @@ +# การติดตั้ง Gitea Actions Runner (act_runner) บน ASUSTOR + +คู่มือนี้สำหรับติดตั้ง **act_runner** บน ASUSTOR เพื่อเชื่อมต่อกับ Gitea ที่รันอยู่บน QNAP + +> ⚠️ **Note:** Gitea อยู่บน **QNAP** แต่ Runner อยู่บน **ASUSTOR** ตามหลัก Server Role Separation +> (QNAP = Application, ASUSTOR = Infrastructure) + +## 🏗️ โครงสร้างการติดตั้ง +* **Platform:** ASUSTOR AS5403T (Infrastructure Server) +* **Method:** Portainer Stack หรือ Docker Compose +* **Path:** `/volume1/np-dms/gitea-runner/` + +--- + +## 🚀 ขั้นตอนการติดตั้ง + +### 1. รับ Registration Token +1. เข้า Gitea Web UI (`https://git.np-dms.work`) ไปที่ **Site Administration** -> **Actions** -> **Runners** +2. กดปุ่ม **Create new Runner** +3. คัดลอก **Registration Token** มาเก็บไว้ + +### 2. เตรียม Directory บน ASUSTOR +```bash +# SSH เข้า ASUSTOR +ssh admin@192.168.10.9 + +# สร้างโฟลเดอร์เก็บข้อมูล +mkdir -p /volume1/np-dms/gitea-runner/data +``` + +### 3. สร้าง Docker Compose + +สร้างไฟล์ `/volume1/np-dms/gitea-runner/docker-compose.yml` หรือใช้ Portainer Stack: + +```yaml +# File: /volume1/np-dms/gitea-runner/docker-compose.yml +# Deploy on: ASUSTOR AS5403T +# เชื่อมต่อกับ Gitea บน QNAP ผ่าน Domain URL + +version: "3.8" + +services: + runner: + image: gitea/act_runner:latest + container_name: gitea-runner + restart: always + environment: + # ใช้ Domain URL เพื่อเชื่อมต่อ Gitea ข้ามเครื่อง (QNAP) + - GITEA_INSTANCE_URL=https://git.np-dms.work + - GITEA_RUNNER_REGISTRATION_TOKEN=คัดลอก_TOKEN_มาวางที่นี่ + - GITEA_RUNNER_NAME=asustor-runner + # Label ต้องตรงกับ runs-on ใน deploy.yaml + - GITEA_RUNNER_LABELS=ubuntu-latest:docker://node:18-bullseye,self-hosted:docker://node:18-bullseye + volumes: + - /volume1/np-dms/gitea-runner/data:/data + - /var/run/docker.sock:/var/run/docker.sock +``` + +### 4. สั่งรัน Runner +```bash +cd /volume1/np-dms/gitea-runner +docker compose up -d +``` + +--- + +## 🔍 การตรวจสอบภายหลังการติดตั้ง +1. กลับไปที่หน้า **Settings -> Actions -> Runners** ใน Gitea (QNAP) +2. สถานะควรเปลี่ยนเป็น **Total: 1** และมีจุดสีเขียวหน้า `asustor-runner` +3. ลองกด **Run workflow** ในแถบ Actions เพื่อทดสอบ + +## ⚠️ ข้อควรระวัง +* **Network:** ASUSTOR ต้องเข้าถึง `https://git.np-dms.work` ได้ (ผ่าน DNS/NPM) +* **Disk Cleanup:** รัน `docker image prune -a` เป็นระยะเพื่อลบ cache images เก่า diff --git a/specs/08-infrastructure/README.md b/specs/08-infrastructure/README.md index e6da5db..d41e67d 100644 --- a/specs/08-infrastructure/README.md +++ b/specs/08-infrastructure/README.md @@ -50,14 +50,15 @@ | **Code** | Gitea | Git Repository | 1.0 CPU / 1GB RAM | #### ASUSTOR AS5403T (Infrastructure Stack) -| Category | Service | Notes | -| :--------------- | :------------------ | :------------------------------ | -| **File Storage** | NFS / SMB | Shared volumes for backup | -| **Backup** | Restic / Borg | Pull-based Backup (More Safe) | -| **Docker Infra** | Registry, Portainer | Container image registry, mgmt | -| **Monitoring** | Uptime Kuma | Service availability monitoring | -| **Metrics** | Prometheus, Grafana | Cross-Server Scraping | -| **Log** | Loki / Syslog | Centralized logging | +| Category | Service | Notes | +| :--------------- | :------------------ | :-------------------------------- | +| **File Storage** | NFS / SMB | Shared volumes for backup | +| **Backup** | Restic / Borg | Pull-based Backup (More Safe) | +| **Docker Infra** | Registry, Portainer | Container image registry, mgmt | +| **Monitoring** | Uptime Kuma | Service availability monitoring | +| **Metrics** | Prometheus, Grafana | Cross-Server Scraping | +| **Log** | Loki / Syslog | Centralized logging | +| **CI/CD** | Gitea Runner | Automated Deployment (act_runner) | --- @@ -192,12 +193,13 @@ graph TB ### Infrastructure Services (ASUSTOR) -| ไฟล์ | Application | Services | Path บน ASUSTOR | -| :--------------------------------------------------- | :----------------- | :--------------------------------------------------- | :---------------------------- | -| [05_monitoring.md](05_monitoring.md) | `lcbp3-monitoring` | `prometheus`, `grafana`, `node-exporter`, `cadvisor` | `/volume1/np-dms/monitoring/` | -| [06_backup.md](06_backup.md) | `lcbp3-backup` | `restic`, Pull-based strategy | `/volume1/np-dms/backup/` | -| [07_disaster_recovery.md](07_disaster_recovery.md) | - | DR Plan, RTO/RPO Targets | - | -| [08_secrets_management.md](08_secrets_management.md) | - | Secrets & Credentials Management | - | +| ไฟล์ | Application | Services | Path บน ASUSTOR | +| :--------------------------------------------------- | :----------------- | :--------------------------------------------------- | :------------------------------ | +| [05_monitoring.md](05_monitoring.md) | `lcbp3-monitoring` | `prometheus`, `grafana`, `node-exporter`, `cadvisor` | `/volume1/np-dms/monitoring/` | +| [10_gitea_runner.md](10_gitea_runner.md) | `gitea-runner` | `act_runner` | `/volume1/np-dms/gitea-runner/` | +| [06_backup.md](06_backup.md) | `lcbp3-backup` | `restic`, Pull-based strategy | `/volume1/np-dms/backup/` | +| [07_disaster_recovery.md](07_disaster_recovery.md) | - | DR Plan, RTO/RPO Targets | - | +| [08_secrets_management.md](08_secrets_management.md) | - | Secrets & Credentials Management | - | ---