ดูทุกคำสั่ง พารามิเตอร์ และตัวอย่างได้ที่ คู่มืออ้างอิงคำสั่ง th
ติดตั้ง
# Linux, macOS
curl -fsSL https://raw.githubusercontent.com/mrzack99s/thailandhosting-cli/main/install.sh | sh
# Windows (PowerShell)
irm https://raw.githubusercontent.com/mrzack99s/thailandhosting-cli/main/install.ps1 | iexสคริปต์จะดาวน์โหลด th จาก GitHub และตรวจ checksum ก่อนติดตั้ง ถ้ามี Go 1.23 ขึ้นไปจะใช้ go install github.com/mrzack99s/thailandhosting-cli/cmd/th@latest ก็ได้
เข้าสู่ระบบ
th auth login จะเปิด Console ให้ตรวจว่ารหัสตรงกับใน terminal แล้วกด อนุญาต ใช้ได้ 90 วัน และแสดงใน บัญชี → อุปกรณ์ที่เข้าสู่ระบบ ตั้ง Project และ Region ครั้งเดียวด้วย th config set project … และ th config set region …
Static Web จากโฟลเดอร์
th static-site deploy docs ./dist # creates the site on the first deploy
th static-site releases docs
th static-site rollback docs previous
th static-site domains add docs www.example.comBuild เว็บก่อน (เช่น npm run build) แล้ว deploy โฟลเดอร์ผลลัพธ์ แต่ละครั้งเป็น Release ที่ย้อนกลับได้ และนับเหมือนการ Publish ในแพ็กเกจของคุณ
Object Storage
th object-storage buckets create my-bucket
th object-storage cp ./report.pdf th://my-bucket/reports/
th object-storage cp -r ./backups th://my-bucket/backups
th object-storage sync ./public th://my-bucket/site --delete
th object-storage ls th://my-bucket/reports/
th object-storage sign th://my-bucket/reports/report.pdf --expires 1hDatabase และ Cache
th database create app-db --engine postgres
th database public app-db --enable --allow 203.0.113.7/32 # your IP
th database connect app-db # opens psql with the credentials
th database credentials app-db
th database backups create app-db
th cache create sessions --engine thcache
th cache connect sessions # opens redis-cliที่อยู่ภายใน (private) ใช้ได้เฉพาะใน VPC ของ Project ถ้าจะเชื่อมจากเครื่องของคุณ ให้เปิดการเข้าถึงจากภายนอกสำหรับ IP ของคุณก่อน
Queue Service
th queue create jobs --visibility-timeout 60s
th queue send jobs '{"order": 1042}'
th queue receive jobs --max 10 --ack
th queue tail jobs # receive and acknowledge until Ctrl+CContainer มีคู่มือของตัวเอง: Deploy จากเครื่องของคุณหรือ CI ด้วย th CLI
ใช้ใน CI
- Container และ Static Web: สร้าง API Key ที่ Integrations → API keys โดยให้สิทธิ์ Containers: deploy (
run:write) หรือ Static Web: deploy (static:write) แล้วตั้งเป็นTH_API_KEY - Object Storage และ Queue Service: สร้าง Access key ในหน้าของบริการนั้น แล้วตั้ง
TH_OBJECT_STORAGE_KEY_ID/TH_OBJECT_STORAGE_SECRETหรือTH_QUEUE_KEY_ID/TH_QUEUE_SECRET
เมื่อเข้าสู่ระบบบนเครื่องของคุณเอง th จะสร้าง key ชั่วคราวของ Object Storage หรือ Queue ให้เอง (12 ชั่วโมง ตามสิทธิ์ของคุณใน Project) ไม่ต้องสร้างเอง