th container

Deploy Container จากโฟลเดอร์หรือ image ย้อนกลับไป Revision ก่อนหน้า อ่าน log และดูแล Registry ของ Project ให้เป็นระเบียบ

เกี่ยวกับ

Container รันแอปของคุณจาก image และเพิ่ม Instance เมื่อมีคนใช้มากขึ้น จนลดเหลือศูนย์เมื่อไม่มีใครเรียก (--min-instances 0) ทุกการ Deploy สร้าง Revision ใหม่ Revision ล่าสุดได้รับ traffic ทั้งหมด และคุณส่ง traffic กลับไปที่ Revision ก่อนหน้าได้ทุกเมื่อ

  • จาก source (--source ค่าเริ่มต้น): th แพ็กโฟลเดอร์แล้วเรา build ให้ จึงไม่ต้องมี Docker ถ้ามี Dockerfile จะใช้ไฟล์นั้น ถ้าไม่มี โปรเจกต์ Node.js, Python และ Go จะได้ Dockerfile ที่สร้างให้ ซึ่งแสดงใน log ของ Build ไฟล์ที่ระบุใน .thignore (ถ้าไม่มีใช้ .dockerignore ถ้าไม่มีอีกใช้ .gitignore) จะไม่ถูกอัปโหลด และ source ที่แพ็กแล้วมีขนาดได้ไม่เกิน 100 MB
  • จาก image (--image): image ใดก็ได้ที่แพลตฟอร์ม pull ได้ หรือ image ที่คุณ push ด้วย Docker หลังรัน th auth configure-docker
  • การตั้งค่า: การ Deploy ครั้งแรกจะสร้าง Container (ต้องมี Region) การ Deploy ครั้งต่อไปจะคงการตั้งค่าเดิม และเปลี่ยนเฉพาะพารามิเตอร์ที่คุณใส่ พารามิเตอร์ตัวแปรสภาพแวดล้อมจะแทนที่ตัวแปรทั้งชุด
  • Registry: image ที่ build และ push แล้วเก็บใน Registry ของ Project ได้ 20 GB ต่อ Project image ของ 10 Revision ล่าสุดของแต่ละ Container และ image ที่มี tag จะถูกเก็บไว้ Build เข้า Registry อื่นด้วย --repository และจัดการ Registry ด้วย th registry

แอปต้องฟังที่ 0.0.0.0 บนพอร์ตใน $PORT (ค่าเริ่มต้น 8080) ดูเรื่องการขยายและการเข้าถึงได้ที่ Container ทำงานอย่างไร ในศูนย์ช่วยเหลือ

คู่มือการใช้งาน

Deploy จาก source

  1. ในโฟลเดอร์โปรเจกต์ รัน th container deploy api --source . (ครั้งแรกให้ใส่ --region หรือตั้งด้วย th config set region)
  2. th จะแพ็กและอัปโหลดโฟลเดอร์ แล้วแสดง log ของ Build ใน terminal
  3. เมื่อ Build สำเร็จ Revision ใหม่จะถูก Deploy และแสดง URL ของบริการ
Shell
th container deploy api --source . --region bkk

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

Deploy image และเปลี่ยนการตั้งค่า

Shell
th container deploy api --image ghcr.io/acme/api:1.4 --port 3000
th container deploy api --cpu 1 --memory 512Mi --min-instances 0 --max-instances 5 \
  --set-env-vars NODE_ENV=production --secret-env API_KEY=xxxx

พารามิเตอร์ที่ไม่ได้ใส่จะคงค่าปัจจุบันของบริการ --env, --set-env-vars และ --secret-env รวมกันจะแทนที่ตัวแปรทั้งหมด จึงต้องใส่ทุกตัวทุกครั้งที่เปลี่ยนตัวใดตัวหนึ่ง

ย้อนกลับไป Revision ก่อนหน้า

  1. ดูรายการ Revision ด้วย th container revisions list --service api เครื่องหมาย * คือ Revision ที่ให้บริการอยู่
  2. ส่ง traffic ทั้งหมดไปที่ Revision ที่ต้องการ: th container services update-traffic api --to-revision 3
  3. ถ้าจะกลับไปใช้ล่าสุด ใช้ --to-revision LATEST
Shell
th container revisions list --service api
th container services update-traffic api --to-revision 3

เพิ่มพื้นที่ว่างใน Registry

  1. ดูว่าแต่ละ repository ใช้พื้นที่เท่าไรด้วย th container images list
  2. ดู image ของ repository หนึ่งด้วย th container images list api KEPT=yes หมายถึงมี Container รัน image นั้นอยู่ หรือมี Revision เก็บไว้สำหรับย้อนกลับ
  3. ลบ tag (api:old-tag) ลบ image ด้วย digest (api@sha256:…) หรือลบทั้ง repository ที่ไม่มีอะไรรันอยู่
Shell
th container images list
th container images list api
th container images delete api:old-tag
th container images delete-repository old-worker

คำสั่ง

คำสั่งคำอธิบาย
th container deployDeploy Container
th container services listแสดง Container ของ Project ปัจจุบัน
th container services describeแสดงการตั้งค่าและ Revision ที่ให้บริการอยู่ของ Container
th container services logsแสดง log บรรทัดล่าสุดของ Container
th container services update-trafficส่ง traffic ทั้งหมดไปที่ Revision ก่อนหน้า (หรือใหม่กว่า)
th container services deleteลบ Container และทุก Revision ของ Container นั้น
th container revisions listแสดง Revision ของ Container เรียงจากใหม่ไปเก่า
th container images listถ้าไม่ใส่ REPOSITORY จะแสดง repository ใน Registry ของ Project และพื้นที่ที่ใช้ไปจากโควตาของ Registry
th container images deleteIMAGE คือ REPOSITORY:TAG (ลบเฉพาะ tag), REPOSITORY@sha256:DIGEST หรือ REPOSITORY@ ตามด้วยเลขฐานสิบหก 7 ตัวแรกขึ้นไปของ digest (ลบ image และทุก tag ของ image นั้น) หรือชื่อเต็ม <host>/<namespace>/REPOSITORY[:TAG|@DIGEST]
th container images delete-repositoryลบ repository พร้อมทุก image และ tag ในนั้น
th builds listแสดง Build ล่าสุด 100 รายการของ Project ทั้ง Container และ Function เรียงจากใหม่ไปเก่า
th builds logแสดง log ของ Build --follow แสดงต่อไปจนกว่า Build จะจบ
th builds cancelหยุด Build ที่อยู่ในคิวหรือกำลังทำงาน

th container deploy

Deploy Container

ไวยากรณ์

Shell
th container deploy NAME [--source DIR | --image IMAGE] [flags]

เมื่อใช้ --source (ค่าเริ่มต้น ".") โฟลเดอร์จะถูกอัปโหลดและ build บน ThailandHosting โดยไม่ต้องมี Docker ในเครื่อง ใช้ Dockerfile ของโฟลเดอร์นั้น หรือ Dockerfile ที่สร้างให้สำหรับ Node.js, Go หรือ Python ไฟล์ที่ระบุใน .thignore (ถ้าไม่มีใช้ .dockerignore ถ้าไม่มีอีกใช้ .gitignore) จะไม่ถูกอัปโหลด

ถ้ายังไม่มีบริการชื่อ NAME จะสร้างบริการใหม่ (ต้องมี Region) ถ้ามีแล้วจะ Deploy เป็น Revision ใหม่ซึ่งได้รับ traffic ทั้งหมด แฟล็กที่ไม่ได้ใส่จะคงการตั้งค่าปัจจุบันของบริการ

Build จาก source เก็บ image ใน Registry หลักของ Project เป็น <host>/<project>/NAME ใส่ --repository REGISTRY/IMAGE เพื่อเก็บใน Registry อื่นของ Project แทน (ดู th registry list)

ตัวอย่าง

Build โฟลเดอร์ปัจจุบันแล้ว Deploy เป็น Container ใหม่ใน bkk

Shell
th container deploy api --source . --region bkk

Build เก็บใน Registry prod เป็น prod/api:v1.4.0

Shell
th container deploy api --source . --repository prod/api --tag v1.4.0

Deploy image ที่ฟังพอร์ต 3000

Shell
th container deploy api --image ghcr.io/acme/api:1.4 --port 3000

เปลี่ยนขนาดและตั้งตัวแปร

Shell
th container deploy api --cpu 0.5 --memory 512Mi --env NODE_ENV=production

ลดเหลือศูนย์เมื่อว่าง และขยายได้ถึง 5 Instance

Shell
th container deploy api --min-instances 0 --max-instances 5 --concurrency 80

ให้ผู้เรียกต้องใช้ Invoker token

Shell
th container deploy api --no-allow-unauthenticated

ใน CI: ไม่มีคำถามยืนยัน

Shell
th container deploy api --source . --quiet

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Container (บริการ) ซึ่งเป็นส่วนหนึ่งของ URL ของบริการ

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--sourceข้อความ.โฟลเดอร์ที่จะอัปโหลดและ build
--imageข้อความDeploy image นี้แทนการ build
--portตัวเลข8080พอร์ตที่ Container ฟัง
--cpuข้อความvCPU เช่น 0.25, 0.5, 1, 2
--memoryข้อความหน่วยความจำ เช่น 256Mi, 512Mi, 1Gi
--compute-classข้อความcompute class เช่น general, economy, highcpu, highmem
--envรายการตัวแปรสภาพแวดล้อม KEY=VALUE (ระบุซ้ำได้)
--set-env-varsรายการตัวแปรสภาพแวดล้อม KEY=VALUE,KEY2=VALUE2
--secret-envรายการตัวแปรสภาพแวดล้อมแบบ secret KEY=VALUE (ระบุซ้ำได้)
--min-instancesตัวเลขจำนวน Instance ต่ำสุด (0 คือลดเหลือศูนย์ได้)
--max-instancesตัวเลขจำนวน Instance สูงสุด
--concurrencyตัวเลขจำนวน request ที่แต่ละ Instance รับพร้อมกัน
--timeoutข้อความtimeout ของ request เช่น 300s หรือ 5m
--allow-unauthenticatedแฟล็กอนุญาตให้เรียกแบบสาธารณะ (--no-allow-unauthenticated ต้องใช้ Invoker token)
--cpu-always-allocatedแฟล็กคง CPU ไว้ระหว่าง request
--health-check-pathข้อความHTTP path สำหรับ health check
--commandรายการEntrypoint คั่นด้วยจุลภาค (ระบุซ้ำได้)
--argsรายการอาร์กิวเมนต์ คั่นด้วยจุลภาค (ระบุซ้ำได้)
--clear-commandแฟล็กใช้ entrypoint ของ image เอง
--clear-argsแฟล็กใช้อาร์กิวเมนต์ของ image เอง
--dockerfileข้อความDockerfilepath ของ Dockerfile ใน source
--tagข้อความtag ของ image สำหรับการ build จาก source
--repositoryข้อความNAMEที่เก็บ image ของการ build จาก source: IMAGE หรือ REGISTRY/IMAGE
--messageข้อความบันทึกที่เก็บไว้กับ Revision
--asyncแฟล็กจบคำสั่งทันทีเมื่อระบบรับการ Deploy แล้ว (ใช้ได้เฉพาะกับ --image)

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container services list

แสดง Container ของ Project ปัจจุบัน

ไวยากรณ์

Shell
th container services list

ตัวอย่าง

ดูรายการ Container ของ Project

Shell
th container services list

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container services describe

แสดงการตั้งค่าและ Revision ที่ให้บริการอยู่ของ Container

ไวยากรณ์

Shell
th container services describe NAME

ตัวอย่าง

ดูการตั้งค่าและ Revision ที่ให้บริการอยู่

Shell
th container services describe api

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Container (บริการ) ซึ่งเป็นส่วนหนึ่งของ URL ของบริการ

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container services logs

แสดง log บรรทัดล่าสุดของ Container

ไวยากรณ์

Shell
th container services logs NAME [--lines N]

ตัวอย่าง

log 200 บรรทัดล่าสุด

Shell
th container services logs api --lines 200

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Container (บริการ) ซึ่งเป็นส่วนหนึ่งของ URL ของบริการ

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--linesตัวเลข100จำนวนบรรทัด

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container services update-traffic

ส่ง traffic ทั้งหมดไปที่ Revision ก่อนหน้า (หรือใหม่กว่า)

ไวยากรณ์

Shell
th container services update-traffic NAME --to-revision REV

REV คือชื่อ หมายเลข หรือ ID ของ Revision หรือ LATEST

ตัวอย่าง

ย้อนกลับไป Revision 3

Shell
th container services update-traffic api --to-revision 3

กลับไปใช้ Revision ล่าสุด

Shell
th container services update-traffic api --to-revision LATEST

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Container (บริการ) ซึ่งเป็นส่วนหนึ่งของ URL ของบริการ

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--to-revisionจำเป็นข้อความชื่อ หมายเลข หรือ ID ของ Revision หรือ LATEST

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container services delete

ลบ Container และทุก Revision ของ Container นั้น

ไวยากรณ์

Shell
th container services delete NAME [--quiet]

--quiet ข้ามการยืนยัน

ตัวอย่าง

ลบหลังยืนยัน

Shell
th container services delete api

ลบโดยไม่ถามยืนยัน

Shell
th container services delete api --quiet

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
NAMEจำเป็นชื่อ Container (บริการ) ซึ่งเป็นส่วนหนึ่งของ URL ของบริการ

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container revisions list

แสดง Revision ของ Container เรียงจากใหม่ไปเก่า

ไวยากรณ์

Shell
th container revisions list --service NAME

เครื่องหมาย * คือ Revision ที่ให้บริการอยู่

ตัวอย่าง

ดูรายการ Revision โดย * คือ Revision ที่ให้บริการอยู่

Shell
th container revisions list --service api

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--serviceจำเป็นข้อความชื่อบริการ

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container images list

ถ้าไม่ใส่ REPOSITORY จะแสดง repository ใน Registry ของ Project และพื้นที่ที่ใช้ไปจากโควตาของ Registry

ไวยากรณ์

Shell
th container images list [REPOSITORY]

ถ้าใส่ REPOSITORY จะแสดง image ใน repository นั้น เรียงจากใหม่ไปเก่า KEPT=yes หมายถึงมี Container รัน image นั้นอยู่ หรือมี Revision เก็บไว้สำหรับย้อนกลับ

ตัวอย่าง

repository และพื้นที่ Registry ที่ใช้

Shell
th container images list

image ของ repository api

Shell
th container images list api

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
REPOSITORYไม่บังคับrepository ใน Registry ของ Project ปกติเป็นชื่อเดียวกับ Container

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container images delete

IMAGE คือ REPOSITORY:TAG (ลบเฉพาะ tag), REPOSITORY@sha256:DIGEST หรือ REPOSITORY@ ตามด้วยเลขฐานสิบหก 7 ตัวแรกขึ้นไปของ digest (ลบ image และทุก tag ของ image นั้น) หรือชื่อเต็ม <host>/<namespace>/REPOSITORY[:TAG|@DIGEST]

ไวยากรณ์

Shell
th container images delete IMAGE [--quiet]

image ที่ Container รันอยู่จะลบไม่ได้ --quiet ข้ามการยืนยัน

ตัวอย่าง

ลบ tag

Shell
th container images delete api:old-tag

ลบ image และทุก tag ด้วย digest

Shell
th container images delete api@3f2c9a1

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
IMAGEจำเป็นREPOSITORY:TAG, REPOSITORY@sha256:DIGEST, REPOSITORY@ ตามด้วยเลขฐานสิบหก 7 ตัวแรกขึ้นไปของ digest หรือชื่อเต็ม <host>/<namespace>/REPOSITORY…

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th container images delete-repository

ลบ repository พร้อมทุก image และ tag ในนั้น

ไวยากรณ์

Shell
th container images delete-repository REPOSITORY [--quiet]

ลบไม่ได้ถ้ามี Container รัน image ใด image หนึ่งของ repository นั้นอยู่ --quiet ข้ามการยืนยัน

ตัวอย่าง

ลบ repository ที่ไม่มีอะไรรันอยู่

Shell
th container images delete-repository old-worker

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
REPOSITORYจำเป็นrepository ใน Registry ของ Project ปกติเป็นชื่อเดียวกับ Container

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th builds list

แสดง Build ล่าสุด 100 รายการของ Project ทั้ง Container และ Function เรียงจากใหม่ไปเก่า

ไวยากรณ์

Shell
th builds list [--status STATUS] [--kind container|function] [--repository REPOSITORY]

REPOSITORY คือที่เก็บ image (IMAGE ใน Registry หลัก หรือ REGISTRY/IMAGE ใน Registry อื่น) DEPLOYED TO คือบริการที่ Revision ใช้ image นั้น image removed หมายถึง image ถูก Cleanup หรือลบออกจาก Registry แล้ว

ตัวอย่าง

Build ที่อยู่ในคิวหรือกำลังทำงาน

Shell
th builds list --status active

Build ของ Function ที่ล้มเหลว

Shell
th builds list --kind function --status failed

Build ล่าสุด 100 รายการ ทั้ง Container และ Function

Shell
th builds list

เฉพาะ Build ที่เก็บใน api

Shell
th builds list --repository api

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--statusข้อความเฉพาะ Build ที่ active (อยู่ในคิวหรือกำลังทำงาน), queued, running, succeeded, failed หรือ cancelled
--kindข้อความเฉพาะ Build ของ container หรือ function
--repositoryข้อความเฉพาะ Build ที่เก็บใน repository นี้

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th builds log

แสดง log ของ Build --follow แสดงต่อไปจนกว่า Build จะจบ

ไวยากรณ์

Shell
th builds log ID [--follow]

ตัวอย่าง

ติดตาม Build จนจบ

Shell
th builds log <build-id> --follow

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
IDจำเป็นBuild ID ตามที่ th container deploy หรือ th builds list แสดง

พารามิเตอร์

ชื่อชนิดค่าเริ่มต้นคำอธิบาย
--followแฟล็กแสดงต่อไปจนกว่า Build จะจบ

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑

th builds cancel

หยุด Build ที่อยู่ในคิวหรือกำลังทำงาน

ไวยากรณ์

Shell
th builds cancel ID

ตัวอย่าง

หยุด Build ที่อยู่ในคิวหรือกำลังทำงาน

Shell
th builds cancel <build-id>

อาร์กิวเมนต์ตามตำแหน่ง

ชื่อคำอธิบาย
IDจำเป็นBuild ID ตามที่ th container deploy หรือ th builds list แสดง

พารามิเตอร์ส่วนกลาง

คำสั่งนี้รับพารามิเตอร์ส่วนกลางด้วย: --project, --region, --endpoint, --format, --quiet

กลับขึ้นด้านบน ↑