คำสั่ง th: ใช้ทุกบริการจาก terminal

Deploy Container และ Static Web, คัดลอกไฟล์ขึ้น Object Storage, เชื่อมต่อ Database และ Cache, ส่งข้อความเข้า Queue จากเครื่องของคุณหรือ CI

ดูทุกคำสั่ง พารามิเตอร์ และตัวอย่างได้ที่ คู่มืออ้างอิงคำสั่ง th

ติดตั้ง

Shell
# 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 จากโฟลเดอร์

Shell
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.com

Build เว็บก่อน (เช่น npm run build) แล้ว deploy โฟลเดอร์ผลลัพธ์ แต่ละครั้งเป็น Release ที่ย้อนกลับได้ และนับเหมือนการ Publish ในแพ็กเกจของคุณ

Object Storage

Shell
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 1h

Database และ Cache

Shell
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

Shell
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+C

Container มีคู่มือของตัวเอง: 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) ไม่ต้องสร้างเอง

ยังแก้ไม่ได้? ให้ทีมงานช่วย

เปิด ticket จากหน้าจัดการ บอกชื่อเว็บหรือบริการ สิ่งที่ทำ และข้อความที่เห็นบนจอ ทีมงานจะตอบกลับในเรื่องเดียวกัน ติดตามได้ในที่เดียว