Deploy จากเครื่องของคุณหรือ CI ด้วย th CLI

คำสั่งเดียว build โฟลเดอร์ของคุณแล้ว deploy ให้เลย ไม่ต้องมี Docker ในเครื่อง

ทุกคำสั่งและพารามิเตอร์ของ th container อยู่ในคู่มืออ้างอิง CLI

ติดตั้งและเข้าสู่ระบบ

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
# or with Go 1.23+
go install github.com/mrzack99s/thailandhosting-cli/cmd/th@latest

th auth login จะเปิด Console ให้ตรวจว่ารหัสตรงกับใน terminal แล้วกด อนุญาต การเข้าสู่ระบบนี้ใช้ได้ 90 วัน และแสดงใน บัญชี → อุปกรณ์ที่เข้าสู่ระบบ ซึ่งออกจากระบบได้จากที่นั่น

Shell
th auth login                     # opens the Console to approve
th config set project my-project  # optional: the CLI picks your first Project
th container deploy api --source .      # build this folder and deploy it

--source ทำอะไรบ้าง

  1. CLI แพ็กโฟลเดอร์ โดยตัดไฟล์ที่อยู่ใน .thignore, .dockerignore หรือ .gitignore (รวมถึง .git และ node_modules) ขนาดไม่เกิน 100 MB
  2. ระบบ build ให้ ถ้ามี Dockerfile จะใช้ไฟล์นั้น ถ้าไม่มีจะเขียนให้สำหรับ Node.js (package.json), Python (requirements.txt หรือ pyproject.toml) หรือ Go (go.mod) และแสดงใน log ให้คัดลอกไปปรับได้ log จะไหลมาที่ terminal ของคุณ
  3. image ถูกเก็บใน Registry ของ Project และ deploy เป็น Revision ใหม่ ครั้งแรกจะสร้าง Container ให้ ครั้งต่อไปคงการตั้งค่าเดิมไว้ เปลี่ยนเฉพาะที่คุณระบุ

กด Ctrl+C ระหว่าง build ได้ Build ยังทำต่อที่ฝั่งเรา ดูต่อด้วย th builds log <id> --follow

Deploy จาก image ปรับการตั้งค่า และย้อน Revision

Shell
th container deploy api --image ghcr.io/acme/api:1.4 --port 3000 \
  --cpu 1 --memory 512Mi --min-instances 0 --max-instances 5 \
  --set-env-vars NODE_ENV=production --secret-env API_KEY=xxxx
Shell
th container services list
th container services describe api
th container services logs api --lines 200
th container revisions list --service api
th container services update-traffic api --to-revision 3   # roll back
th container images list api      # images and what keeps them
th container images delete api:old-tag
th builds list
th builds log <build-id> --follow

image ที่ build หรือ push อยู่ที่ registry.thailandhosting.com/<project>/<name> จะ push ด้วย Docker เองก็ได้:

Shell
th auth configure-docker   # docker login to our registry
docker build -t registry.thailandhosting.com/my-project/api:1.4 .
docker push registry.thailandhosting.com/my-project/api:1.4
th container deploy api --image registry.thailandhosting.com/my-project/api:1.4

Registry เก็บ image ไว้ให้ 10 Revision ล่าสุดของแต่ละ Container (Revision ที่เก่ากว่านั้นย้อนกลับไม่ได้หลังผ่านไป 7 วัน) และ image ที่ติด tag ไว้ แต่ละ Project ได้ 20 GB และจะได้อีเมลเตือนเมื่อใช้ถึง 80% ดูและลบ image ได้ด้วย th container images list / th container images delete หรือการ์ด Registry ในหน้า Container

Deploy จาก GitHub Actions หรือ CI อื่น

ใน Console เปิด Integrations → API keys สร้าง Key ที่มีสิทธิ์ Containers: deploy (run:write) Key นี้ใช้ได้เฉพาะ Container, Build และ Registry ของ Project ของมัน เก็บไว้เป็น secret ชื่อ TH_API_KEY

Shell
# .github/workflows/deploy.yml
on: { push: { branches: [main] } }
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with: { go-version: '1.23' }
      - run: go install github.com/mrzack99s/thailandhosting-cli/cmd/th@latest
      - run: th container deploy api --source .
        env:
          TH_API_KEY: ${{ secrets.TH_API_KEY }}   # a key with the run:write scope

Build และ Registry คิดเงินตามการใช้งาน Wallet ของ Project ต้องมียอดเงิน เครื่อง Build สร้าง image ได้สำหรับ CPU แบบเดียว ถ้าประเภทเครื่องของ Container ใช้อีกแบบ ให้ build เองด้วย docker buildx --platform แล้ว deploy ด้วย --image

ถ้าเจอปัญหา

ขึ้นว่า “ไม่พบ Dockerfile และไม่รู้จักชนิดโปรเจกต์”

เพิ่ม Dockerfile ที่ชั้นบนสุดของโฟลเดอร์ หรือสั่ง deploy จากโฟลเดอร์ที่มี package.json, go.mod หรือ requirements.txt

Build จบด้วย exit code 137

Build ใช้หน่วยความจำเกิน ลดงานตอน build หรือ build image เองแล้ว deploy ด้วย --image

CLI ขึ้นว่า “Token ไม่ถูกต้องหรือหมดอายุ”

สั่ง th auth login ใหม่ ถ้าเป็น CI ให้ตรวจว่า API Key มีสิทธิ์ run:write และยังไม่หมดอายุ

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

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