Bỏ qua

07 · Deploy & môi trường

Đối tượng: DevOps.


1. Tổng quan

ClinicOS deploy như site tĩnh: GitHub → Cloudflare Pages. Không có build step cho code (HTML tĩnh). Tài liệu (clinicos-docs) thì build bằng MkDocs.


2. Repo code ClinicOS

Cấu trúc liên quan deploy

repo/
├── wrangler.toml          # pages_build_output_dir = "admin"
├── .github/workflows/deploy.yml
└── admin/                 # ← output directory
    ├── index.html
    ├── _headers
    ├── assets/
    └── pages/

Đẩy lên GitHub lần đầu

git init
git add .
git commit -m "Hasaki ClinicOS"
git branch -M main
git remote add origin https://github.com/<user>/<repo>.git
git push -u origin main

Xác thực

GitHub không nhận mật khẩu tài khoản khi push. Dùng Personal Access Token (Settings → Developer settings → Tokens, quyền repo) làm password.

Cloudflare Pages

Hai cách:

Cloudflare → Pages → Connect to Git → chọn repo → Build command: để trống · Build output directory: admin

Dùng .github/workflows/deploy.yml sẵn có; thêm secrets CLOUDFLARE_API_TOKEN, CLOUDFLARE_ACCOUNT_ID.


3. Lỗi thường gặp

Output directory \"admin\" not found

Cloudflare không thấy admin/. Nguyên nhân thường gặp:

  • File bị lồng một cấp (vd beauty-clinic-repo/admin/) → sửa Root directory trong Pages về thư mục con đó, hoặc git mv đưa file lên gốc repo.
  • Chưa commit thư mục admin/ → kiểm tra gốc repo trên GitHub có admin/ chưa.

Push bị 'unrelated histories'

Khi lỡ tạo README trên GitHub trước:

git pull origin main --allow-unrelated-histories
git push -u origin main


4. Repo tài liệu (clinicos-docs)

Build bằng MkDocs Material.

pip install -r requirements-docs.txt
mkdocs serve     # xem thử http://localhost:8000
mkdocs build     # ra thư mục site/

Cloudflare Pages cho repo docs: Build command: pip install -r requirements-docs.txt && mkdocs build · Output directory: site


5. Lưu ý môi trường phát triển

Bài học vận hành

Trong môi trường tạm (sandbox), thư mục làm việc có thể bị reset về trạng thái cũ giữa các phiên. Quy trình an toàn: khôi phục từ bản đóng gói mới nhất → verify DOM runtime → đóng gói lại trong một mạch liền. Bản zip/commit mới nhất là nguồn chuẩn.