260214:1707 4rd Deploy (Prepare CI/CDB)
Some checks failed
Build and Deploy / deploy (push) Has been cancelled

This commit is contained in:
admin
2026-02-14 17:07:48 +07:00
parent 4d900d0930
commit ff4033b8b6
6 changed files with 74 additions and 47 deletions

View File

@@ -0,0 +1,48 @@
name: Build and Deploy
on:
push:
branches:
- main
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Deploy to QNAP via SSH
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
port: ${{ secrets.PORT }}
script_stop_signal: true # Stop script on error
script: |
echo "🚀 Starting Deployment..."
# 1. Update Code
echo "📂 Pulling latest code..."
cd /share/np-dms/app/source
git pull origin main
# 2. Build Backend
echo "🏗️ Building Backend..."
docker build -f backend/Dockerfile -t lcbp3-backend:latest .
# 3. Build Frontend
echo "🏗️ Building Frontend..."
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
# 5. Cleanup
echo "🧹 Cleaning up unused images..."
docker image prune -f
echo "✅ Deployment Complete!"

View File

@@ -65,7 +65,7 @@ RUN addgroup -g 1001 -S nextjs && \
# Copy standalone output from build # Copy standalone output from build
COPY --from=build --chown=nextjs:nextjs /app/frontend/.next/standalone ./ COPY --from=build --chown=nextjs:nextjs /app/frontend/.next/standalone ./
COPY --from=build --chown=nextjs:nextjs /app/frontend/.next/static ./.next/static COPY --from=build --chown=nextjs:nextjs /app/frontend/.next/static ./frontend/.next/static
USER nextjs USER nextjs
@@ -74,4 +74,4 @@ EXPOSE 3000
HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=20s \ HEALTHCHECK --interval=30s --timeout=10s --retries=3 --start-period=20s \
CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1 CMD wget --no-verbose --tries=1 --spider http://localhost:3000/ || exit 1
CMD ["node", "server.js"] CMD ["node", "frontend/server.js"]

Binary file not shown.

View File

@@ -88,7 +88,7 @@ http://localhost:3000/api/docs
**Default Admin Account:** **Default Admin Account:**
- Username: `admin` - Username: `admin`
- Password: `Admin@123` (Change immediately!) - Password: `Center2025` (Change immediately!)
--- ---

View File

@@ -5,7 +5,6 @@ VALUES (1, 'OWNER'),
(4, 'CONTRACTOR'), (4, 'CONTRACTOR'),
(5, 'THIRD PARTY'), (5, 'THIRD PARTY'),
(6, 'GUEST'); (6, 'GUEST');
INSERT INTO organizations ( INSERT INTO organizations (
id, id,
organization_code, organization_code,
@@ -80,7 +79,6 @@ VALUES (1, 'กทท.', 'การท่าเรือแห่งประเ
), ),
(31, 'EN', 'Third Party Environment', 5), (31, 'EN', 'Third Party Environment', 5),
(32, 'CAR', 'Third Party Fishery Care', 5); (32, 'CAR', 'Third Party Fishery Care', 5);
-- Seed project -- Seed project
INSERT INTO projects (project_code, project_name) INSERT INTO projects (project_code, project_name)
VALUES ( VALUES (
@@ -107,7 +105,6 @@ VALUES (
'LCBP3-EN', 'LCBP3-EN',
'โครงการพัฒนาท่าเรือแหลมฉบัง ระยะที่ 3 (ส่วนที่ 4) งานก่อสร้าง' 'โครงการพัฒนาท่าเรือแหลมฉบัง ระยะที่ 3 (ส่วนที่ 4) งานก่อสร้าง'
); );
-- Seed contract -- Seed contract
-- ใช้ Subquery เพื่อดึง project_id มาเชื่อมโยง ทำให้ไม่ต้องมานั่งจัดการ ID ด้วยตัวเอง -- ใช้ Subquery เพื่อดึง project_id มาเชื่อมโยง ทำให้ไม่ต้องมานั่งจัดการ ID ด้วยตัวเอง
INSERT INTO contracts ( INSERT INTO contracts (
@@ -186,7 +183,6 @@ VALUES (
), ),
TRUE TRUE
); );
-- Seed user -- Seed user
-- Initial SUPER_ADMIN user -- Initial SUPER_ADMIN user
INSERT INTO users ( INSERT INTO users (
@@ -239,7 +235,6 @@ VALUES (
NULL, NULL,
10 10
); );
-- ========================================================== -- ==========================================================
-- Seed Roles (บทบาทพื้นฐาน 5 บทบาท ตาม Req 4.3) -- Seed Roles (บทบาทพื้นฐาน 5 บทบาท ตาม Req 4.3)
-- ========================================================== -- ==========================================================
@@ -293,7 +288,6 @@ VALUES (
'Contract', 'Contract',
'ผู้ดูแลสัญญา: จัดการสมาชิกในสัญญา, สร้าง / จัดการข้อมูลหลักเฉพาะสัญญา, และอนุมัติเอกสารในสัญญา' 'ผู้ดูแลสัญญา: จัดการสมาชิกในสัญญา, สร้าง / จัดการข้อมูลหลักเฉพาะสัญญา, และอนุมัติเอกสารในสัญญา'
); );
-- ========================================================== -- ==========================================================
-- Seed Role-Permissions Mapping (จับคู่สิทธิ์เริ่มต้น) -- Seed Role-Permissions Mapping (จับคู่สิทธิ์เริ่มต้น)
-- ========================================================== -- ==========================================================
@@ -304,7 +298,6 @@ VALUES (
-- ========================================================== -- ==========================================================
-- SECTION 2: ROLE-PERMISSION MAPPINGS -- SECTION 2: ROLE-PERMISSION MAPPINGS
-- ========================================================== -- ==========================================================
-- Seed data for the 'user_assignments' table -- Seed data for the 'user_assignments' table
INSERT INTO user_assignments ( INSERT INTO user_assignments (
id, id,
@@ -322,7 +315,6 @@ VALUES (1, 1, 1, NULL, NULL, NULL, NULL),
(3, 3, 4, 41, NULL, NULL, 1), (3, 3, 4, 41, NULL, NULL, 1),
-- editor01: Editor role (role_id=4) at organization 41 (คคง.), assigned by superadmin -- editor01: Editor role (role_id=4) at organization 41 (คคง.), assigned by superadmin
(4, 4, 5, 10, NULL, NULL, 1); (4, 4, 5, 10, NULL, NULL, 1);
-- viewer01: Viewer role (role_id=5) at organization 10 (สคฉ.03), assigned by superadmin -- viewer01: Viewer role (role_id=5) at organization 10 (สคฉ.03), assigned by superadmin
-- ===================================================== -- =====================================================
-- == 4. การเชื่อมโยงโครงการกับองค์กร (project_organizations) == -- == 4. การเชื่อมโยงโครงการกับองค์กร (project_organizations) ==
@@ -348,7 +340,6 @@ WHERE organization_code IN (
'EN', 'EN',
'CAR' 'CAR'
); );
-- โครงการย่อย (LCBP3C1) จะมีเฉพาะองค์กรที่เกี่ยวข้อง -- โครงการย่อย (LCBP3C1) จะมีเฉพาะองค์กรที่เกี่ยวข้อง
INSERT INTO project_organizations (project_id, organization_id) INSERT INTO project_organizations (project_id, organization_id)
SELECT ( SELECT (
@@ -365,7 +356,6 @@ WHERE organization_code IN (
'คคง.', 'คคง.',
'ผรม.1 ' 'ผรม.1 '
); );
-- ทำเช่นเดียวกันสำหรับโครงการอื่นๆ (ตัวอย่าง) -- ทำเช่นเดียวกันสำหรับโครงการอื่นๆ (ตัวอย่าง)
INSERT INTO project_organizations (project_id, organization_id) INSERT INTO project_organizations (project_id, organization_id)
SELECT ( SELECT (
@@ -382,7 +372,6 @@ WHERE organization_code IN (
'คคง.', 'คคง.',
'ผรม.2' 'ผรม.2'
); );
-- ===================================================== -- =====================================================
-- == 5. การเชื่อมโยงสัญญากับองค์กร (contract_organizations) == -- == 5. การเชื่อมโยงสัญญากับองค์กร (contract_organizations) ==
-- ===================================================== -- =====================================================
@@ -414,7 +403,6 @@ VALUES (
), ),
'Designer' 'Designer'
); );
-- สัญญาที่ปรึกษาควบคุมงาน (PSLCBP3) -- สัญญาที่ปรึกษาควบคุมงาน (PSLCBP3)
INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract) INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract)
VALUES ( VALUES (
@@ -443,7 +431,6 @@ VALUES (
), ),
'Consultant' 'Consultant'
); );
-- สัญญางานก่อสร้าง ส่วนที่ 1 (LCBP3-C1) -- สัญญางานก่อสร้าง ส่วนที่ 1 (LCBP3-C1)
INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract) INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract)
VALUES ( VALUES (
@@ -472,7 +459,6 @@ VALUES (
), ),
'Contractor' 'Contractor'
); );
-- สัญญางานก่อสร้าง ส่วนที่ 2 (LCBP3-C2) -- สัญญางานก่อสร้าง ส่วนที่ 2 (LCBP3-C2)
INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract) INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract)
VALUES ( VALUES (
@@ -501,7 +487,6 @@ VALUES (
), ),
'Contractor' 'Contractor'
); );
-- สัญญาตรวจสอบสิ่งแวดล้อม (LCBP3-EN) -- สัญญาตรวจสอบสิ่งแวดล้อม (LCBP3-EN)
INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract) INSERT INTO contract_organizations (contract_id, organization_id, role_in_contract)
VALUES ( VALUES (
@@ -530,7 +515,6 @@ VALUES (
), ),
'Consultant' 'Consultant'
); );
-- Seed correspondence_status -- Seed correspondence_status
INSERT INTO correspondence_status ( INSERT INTO correspondence_status (
status_code, status_code,
@@ -561,7 +545,6 @@ VALUES ('DRAFT', 'Draft', 10, 1),
('CCBDSN', 'Canceled by Designer', 92, 1), ('CCBDSN', 'Canceled by Designer', 92, 1),
('CCBCSC', 'Canceled by CSC', 93, 1), ('CCBCSC', 'Canceled by CSC', 93, 1),
('CCBCON', 'Canceled by Contractor', 94, 1); ('CCBCON', 'Canceled by Contractor', 94, 1);
-- Seed correspondence_types -- Seed correspondence_types
INSERT INTO correspondence_types (type_code, type_name, sort_order, is_active) INSERT INTO correspondence_types (type_code, type_name, sort_order, is_active)
VALUES ('RFA', 'Request for Approval', 1, 1), VALUES ('RFA', 'Request for Approval', 1, 1),
@@ -574,7 +557,6 @@ VALUES ('RFA', 'Request for Approval', 1, 1),
('MOM', 'Minutes of Meeting', 8, 1), ('MOM', 'Minutes of Meeting', 8, 1),
('NOTICE', 'Notice', 9, 1), ('NOTICE', 'Notice', 9, 1),
('OTHER', 'Other', 10, 1); ('OTHER', 'Other', 10, 1);
-- Seed rfa_types -- Seed rfa_types
INSERT INTO rfa_types ( INSERT INTO rfa_types (
contract_id, contract_id,
@@ -1064,7 +1046,6 @@ SELECT id,
'รายงานการฝึกปฏิบัติ' 'รายงานการฝึกปฏิบัติ'
FROM contracts FROM contracts
WHERE contract_code = 'LCBP3-C2'; WHERE contract_code = 'LCBP3-C2';
-- Seed rfa_status_codes -- Seed rfa_status_codes
INSERT INTO rfa_status_codes ( INSERT INTO rfa_status_codes (
status_code, status_code,
@@ -1079,7 +1060,6 @@ VALUES ('DFT', 'Draft', 'ฉบับร่าง', 1),
('ASB', 'AS - Built', 'แบบก่อสร้างจริง', 30), ('ASB', 'AS - Built', 'แบบก่อสร้างจริง', 30),
('OBS', 'Obsolete', 'ไม่ใช้งาน', 80), ('OBS', 'Obsolete', 'ไม่ใช้งาน', 80),
('CC', 'Canceled', 'ยกเลิก', 99); ('CC', 'Canceled', 'ยกเลิก', 99);
INSERT INTO rfa_approve_codes ( INSERT INTO rfa_approve_codes (
approve_code, approve_code,
approve_name, approve_name,
@@ -1094,14 +1074,12 @@ VALUES ('1A', 'Approved by Authority', 10, 1),
('3R', 'Revise and Resubmit', 32, 1), ('3R', 'Revise and Resubmit', 32, 1),
('4X', 'Reject', 40, 1), ('4X', 'Reject', 40, 1),
('5N', 'No Further Action', 50, 1); ('5N', 'No Further Action', 50, 1);
-- Seed circulation_status_codes -- Seed circulation_status_codes
INSERT INTO circulation_status_codes (code, description, sort_order) INSERT INTO circulation_status_codes (code, description, sort_order)
VALUES ('OPEN', 'Open', 1), VALUES ('OPEN', 'Open', 1),
('IN_REVIEW', 'In Review', 2), ('IN_REVIEW', 'In Review', 2),
('COMPLETED', 'ปCompleted', 3), ('COMPLETED', 'ปCompleted', 3),
('CANCELLED', 'Cancelled / Withdrawn', 9); ('CANCELLED', 'Cancelled / Withdrawn', 9);
-- ตาราง "แม่" ของ RFA (มีความสัมพันธ์ 1:N กับ rfa_revisions) -- ตาราง "แม่" ของ RFA (มีความสัมพันธ์ 1:N กับ rfa_revisions)
-- ========================================================== -- ==========================================================
-- SEED DATA 6B.md (Disciplines, RFA Types, Sub Types) -- SEED DATA 6B.md (Disciplines, RFA Types, Sub Types)
@@ -1365,7 +1343,6 @@ SELECT id,
'Other' 'Other'
FROM contracts FROM contracts
WHERE contract_code = 'LCBP3-C1'; WHERE contract_code = 'LCBP3-C1';
-- LCBP3-C2 -- LCBP3-C2
INSERT INTO disciplines ( INSERT INTO disciplines (
contract_id, contract_id,
@@ -1610,7 +1587,6 @@ SELECT id,
'Others' 'Others'
FROM contracts FROM contracts
WHERE contract_code = 'LCBP3-C2'; WHERE contract_code = 'LCBP3-C2';
-- 2. Seed ข้อมูล Correspondence Sub Types (Mapping RFA Types กับ Number) -- 2. Seed ข้อมูล Correspondence Sub Types (Mapping RFA Types กับ Number)
-- เนื่องจาก sub_type_code ตรงกับ RFA Type Code แต่ Req ต้องการ Mapping เป็น Number -- เนื่องจาก sub_type_code ตรงกับ RFA Type Code แต่ Req ต้องการ Mapping เป็น Number
-- LCBP3-C1 -- LCBP3-C1
@@ -1661,7 +1637,6 @@ FROM contracts c,
correspondence_types ct correspondence_types ct
WHERE c.contract_code = 'LCBP3-C1' WHERE c.contract_code = 'LCBP3-C1'
AND ct.type_code = 'RFA'; AND ct.type_code = 'RFA';
-- LCBP3-C2 -- LCBP3-C2
INSERT INTO correspondence_sub_types ( INSERT INTO correspondence_sub_types (
contract_id, contract_id,
@@ -1709,7 +1684,6 @@ FROM contracts c,
correspondence_types ct correspondence_types ct
WHERE c.contract_code = 'LCBP3-C2' WHERE c.contract_code = 'LCBP3-C2'
AND ct.type_code = 'RFA'; AND ct.type_code = 'RFA';
-- LCBP3-C3 -- LCBP3-C3
INSERT INTO correspondence_sub_types ( INSERT INTO correspondence_sub_types (
contract_id, contract_id,
@@ -1757,7 +1731,6 @@ FROM contracts c,
correspondence_types ct correspondence_types ct
WHERE c.contract_code = 'LCBP3-C3' WHERE c.contract_code = 'LCBP3-C3'
AND ct.type_code = 'RFA'; AND ct.type_code = 'RFA';
-- LCBP3-C4 -- LCBP3-C4
INSERT INTO correspondence_sub_types ( INSERT INTO correspondence_sub_types (
contract_id, contract_id,
@@ -1805,7 +1778,6 @@ FROM contracts c,
correspondence_types ct correspondence_types ct
WHERE c.contract_code = 'LCBP3-C4' WHERE c.contract_code = 'LCBP3-C4'
AND ct.type_code = 'RFA'; AND ct.type_code = 'RFA';
INSERT INTO `correspondences` ( INSERT INTO `correspondences` (
`id`, `id`,
`correspondence_number`, `correspondence_number`,
@@ -1842,7 +1814,6 @@ VALUES (
1, 1,
NULL NULL
); );
INSERT INTO `correspondence_revisions` ( INSERT INTO `correspondence_revisions` (
`id`, `id`,
`correspondence_id`, `correspondence_id`,
@@ -1881,7 +1852,6 @@ VALUES (
1, 1,
NULL NULL
); );
INSERT INTO `rfas` ( INSERT INTO `rfas` (
`id`, `id`,
`rfa_type_id`, `rfa_type_id`,
@@ -1890,7 +1860,6 @@ INSERT INTO `rfas` (
`deleted_at` `deleted_at`
) )
VALUES (2, 68, '2025-12-06 05:40:02', 1, NULL); VALUES (2, 68, '2025-12-06 05:40:02', 1, NULL);
INSERT INTO `rfa_revisions` ( INSERT INTO `rfa_revisions` (
`id`, `id`,
`rfa_id`, `rfa_id`,
@@ -1931,7 +1900,6 @@ VALUES (
NULL, NULL,
NULL NULL
); );
-- ========================================================== -- ==========================================================
-- 20. Workflow Definitions (Unified Workflow Engine) -- 20. Workflow Definitions (Unified Workflow Engine)
-- ========================================================== -- ==========================================================
@@ -2168,16 +2136,12 @@ VALUES (
NOW(), NOW(),
NOW() NOW()
); );
INSERT INTO `document_number_formats` ( INSERT INTO `document_number_formats` (
`id`, `id`,
`project_id`, `project_id`,
`correspondence_type_id`, `correspondence_type_id`,
`discipline_id`, `discipline_id`,
`format_template`, `format_string`,
`reset_sequence_yearly`,
`example_number`,
`padding_length`,
`reset_annually`, `reset_annually`,
`is_active`, `is_active`,
`description`, `description`,
@@ -2191,9 +2155,6 @@ VALUES (
0, 0,
'{ORG}-{RECIPIENT}-{SEQ:4}-{YEAR}', '{ORG}-{RECIPIENT}-{SEQ:4}-{YEAR}',
1, 1,
NULL,
4,
1,
1, 1,
NULL, NULL,
'2025-12-16 09:33:36', '2025-12-16 09:33:36',
@@ -2206,9 +2167,6 @@ VALUES (
0, 0,
'{ORG}-{RECIPIENT}-{SEQ:4}-{YEAR}', '{ORG}-{RECIPIENT}-{SEQ:4}-{YEAR}',
1, 1,
NULL,
4,
1,
1, 1,
NULL, NULL,
'2025-12-16 09:34:10', '2025-12-16 09:34:10',

View File

@@ -183,6 +183,27 @@ docker load < /share/np-dms/app/lcbp3-frontend.tar
--- ---
## 7. Automated Deployment via Gitea
ระบบรองรับการ Deploy อัตโนมัติผ่าน **Gitea Actions** เมื่อมีการ Push code เข้าสู่ branch `main`
### 7.1 Prerequisites
1. **Enable Actions:** เปิดใช้งาน Gitea Actions ใน Repository Settings
2. **Secrets:** ต้องกำหนด Secrets ต่อไปนี้ใน Repository Settings -> Actions -> Secrets:
- `HOST`: IP Address ของ QNAP Server (e.g. `192.168.10.8`)
- `USERNAME`: SSH Username (e.g. `admin`)
- `PASSWORD`: SSH Password (หรือใช้ `KEY` สำหรับ Private Key)
- `PORT`: SSH Port (Default: `22`)
### 7.2 Workflow Process
เมื่อ Pipeline ทำงาน จะดำเนินการดังนี้ผ่าน SSH:
1. `git pull`: ดึง Code ล่าสุดที่ `/share/np-dms/app/source`
2. `docker build`: Build images ใหม่สำหรับ Backend และ Frontend
3. `docker-compose up -d`: Recreate containers ด้วย image ใหม่
4. `docker image prune`: ลบ Image เก่าที่ไม่ได้ใช้เพื่อประหยัดพื้นที่
---
## 📦 Resource Summary ## 📦 Resource Summary
| Service | Image | CPU Limit | Memory Limit | Port | | Service | Image | CPU Limit | Memory Limit | Port |