build(docker): keep dev database out of the image, warn when ADMIN_TOKEN is unset

- .dockerignore: exclude data/*.sqlite*, data/backups, data/projects.migrated.json so a
  fresh container always seeds from data/projects.json (the dev DB was being baked in)
- publish.mjs: log a hint that requests through a published port are not loopback, so a
  container without ADMIN_TOKEN cannot write
- .env.example / README / AGENTS.md: document the ADMIN_TOKEN requirement for containers

Verified with docker 27.4.0: image build, PORT env (8110/8112 incl. .env), seed 6 rows,
PUT with x-admin-token, VACUUM INTO backup, SQLite on a Windows bind mount
(integrity_check ok), persistence across restart, compose up with PORT + volume override.
This commit is contained in:
Bkk1234 committed 2026-11-23 00:39:44 +07:00
1 parent 0fa0406770
commit d7927d4759
5 files changed
+16

No files matched your search

+2
View File
@@ -107,6 +107,8 @@ curl -s localhost:8090/api/projects | head -5
- **ครั้งแรกที่รัน** ถ้าฐานข้อมูลว่าง `seedFromJson` จะย้ายข้อมูลจาก `data/projects.json` เข้าให้ (เก็บสำเนาไว้ที่ `data/projects.migrated.json`) · ถ้าฐานข้อมูลมีข้อมูลแล้วจะไม่ทับ — แก้ JSON มือเปล่าจึงไม่มีผลกับหน้าเว็บ
- **Node 22 ยังติดป้าย experimental ให้ `node:sqlite`** จึงต้องมี `--disable-warning=ExperimentalWarning` (ใส่ไว้ใน `npm start` และ `CMD` ของ Dockerfile แล้ว) ไม่งั้น log จะมีคำเตือนทุกครั้ง
- `data/hobbypj.sqlite` + `-wal` + `-shm` ไม่ขึ้น git — ย้ายเครื่องให้ commit `data/projects.json` แล้วปล่อยให้ seed ทำงาน หรือคัดลอกไฟล์ `.sqlite` ไปเอง
- **`.dockerignore` ต้องตัด `data/*.sqlite*`, `data/backups`, `data/projects.migrated.json`** ไม่งั้นฐานข้อมูลของเครื่อง dev ถูกอบลง image และ container ใหม่จะไม่ seed จาก `projects.json` (เจอมาแล้วรอบหนึ่ง)
- **container ต้องมี `ADMIN_TOKEN`** — คำขอผ่านพอร์ต mapping มาจาก bridge network ไม่ใช่ loopback จึงตกกติกา "เฉพาะเครื่องนี้" แล้วได้ 403
- `GET /api/projects` คืน `writable` ตามกติกาเดียวกับ `PUT` (ไม่ใช่ “มาจาก loopback ก็เขียนได้”) และมี `token_required` บอกว่าตั้ง `ADMIN_TOKEN` ไว้ไหม — หน้าหลังบ้านใช้สองค่านี้เขียนข้อความสถานะ
- `PUT` ตอบกลับ `database` + `backup` (path แบบ `/`) เพื่อตรวจย้อนหลังได้ว่าบันทึกลงไฟล์ไหนและสำรองไว้ที่ไหน
- กดเผยแพร่ซ้ำโดยไม่แก้อะไรจะได้ commit ใหม่ (เพราะ `updated_at` เปลี่ยน) — ปกติ ไม่ใช่บั๊ก