ข้ามไปยังเนื้อหา

ตรวจสอบ

รันการตรวจสอบเหล่านี้หลังจากรอ 5—10 นาที เพื่อให้ cloud-init ทำงานเสร็จสมบูรณ์

Terminal window
ORIGIN_IP=$(terraform output -raw public_ip)
curl -sf "http://${ORIGIN_IP}/health" | jq .

ผลลัพธ์ที่คาดหวัง:

{
"status": "healthy",
"component": "origin-server",
"applications": ["juice-shop", "dvwa", "vampi", "httpbin", "whoami", "csd-demo", "dvga", "restaurant", "crapi"]
}
Terminal window
# Default landing page
curl -sf "http://${ORIGIN_IP}/" -o /dev/null -w "Landing: %{http_code}\n"
# Juice Shop
curl -sf "http://${ORIGIN_IP}/juice-shop/" -o /dev/null -w "Juice Shop: %{http_code}\n"
# DVWA
curl -sf "http://${ORIGIN_IP}/dvwa/" -o /dev/null -w "DVWA: %{http_code}\n"
# VAmPI
curl -sf "http://${ORIGIN_IP}/vampi/" -o /dev/null -w "VAmPI: %{http_code}\n"
# httpbin
curl -sf "http://${ORIGIN_IP}/httpbin/get" -o /dev/null -w "httpbin: %{http_code}\n"
# whoami
curl -sf "http://${ORIGIN_IP}/whoami/" -o /dev/null -w "whoami: %{http_code}\n"
# DVGA
curl -sf "http://${ORIGIN_IP}/dvga/" -o /dev/null -w "DVGA: %{http_code}\n"
# RESTaurant
curl -sf "http://${ORIGIN_IP}/restaurant/docs" -o /dev/null -w "RESTaurant: %{http_code}\n"
# crAPI (port 8888)
curl -sf "http://${ORIGIN_IP}:8888" -o /dev/null -w "crAPI: %{http_code}\n"

ทั้งหมดควรคืนค่า 200 (DVWA จะคืนค่า 302 redirect ไปยังหน้า login)

Repository นี้มีชุดทดสอบ smoke test จำนวน 39 รายการ:

Terminal window
./tests/smoke-test.sh ${ORIGIN_IP}

ชุดทดสอบนี้จะตรวจสอบแอปพลิเคชันทั้ง 9 รายการ, health endpoints, การลงทะเบียน/เข้าสู่ระบบของ VAmPI, การทดสอบ exfil round-trip ของ CSD Demo, GraphQL ของ DVGA, Swagger ของ RESTaurant, crAPI บนพอร์ต 8888, nginx gzip และการซ่อนเวอร์ชัน

SSH เข้าสู่ VM และตรวจสอบว่า container ทั้ง 41 รายการกำลังทำงาน:

Terminal window
ssh azureuser@${ORIGIN_IP} "sudo docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'" | sort

ผลลัพธ์ที่คาดหวัง (41 containers):

NAMES STATUS PORTS
crapi-community Up X minutes
crapi-identity Up X minutes
crapi-mailhog Up X minutes 0.0.0.0:18025->8025/tcp
crapi-mongo Up X minutes 27017/tcp
crapi-postgres Up X minutes 5432/tcp
crapi-web Up X minutes 0.0.0.0:8888->80/tcp
crapi-workshop Up X minutes
csd-demo-1 Up X minutes 127.0.0.1:5001->5001/tcp
csd-demo-2 Up X minutes 127.0.0.1:5002->5001/tcp
csd-demo-3 Up X minutes 127.0.0.1:5003->5001/tcp
csd-demo-4 Up X minutes 127.0.0.1:5004->5001/tcp
dvga-1 Up X minutes 127.0.0.1:5201->5013/tcp
dvga-2 Up X minutes 127.0.0.1:5202->5013/tcp
dvga-3 Up X minutes 127.0.0.1:5203->5013/tcp
dvga-4 Up X minutes 127.0.0.1:5204->5013/tcp
dvwa-1 Up X minutes 127.0.0.1:8101->80/tcp
dvwa-2 Up X minutes 127.0.0.1:8102->80/tcp
dvwa-3 Up X minutes 127.0.0.1:8103->80/tcp
dvwa-4 Up X minutes 127.0.0.1:8104->80/tcp
dvwa-db Up X minutes 3306/tcp
httpbin-1 Up X minutes 127.0.0.1:8201->80/tcp
httpbin-2 Up X minutes 127.0.0.1:8202->80/tcp
httpbin-3 Up X minutes 127.0.0.1:8203->80/tcp
httpbin-4 Up X minutes 127.0.0.1:8204->80/tcp
juice-shop-1 Up X minutes 127.0.0.1:3001->3000/tcp
juice-shop-2 Up X minutes 127.0.0.1:3002->3000/tcp
juice-shop-3 Up X minutes 127.0.0.1:3003->3000/tcp
juice-shop-4 Up X minutes 127.0.0.1:3004->3000/tcp
restaurant-1 Up X minutes 127.0.0.1:8301->8080/tcp
restaurant-2 Up X minutes 127.0.0.1:8302->8080/tcp
restaurant-3 Up X minutes 127.0.0.1:8303->8080/tcp
restaurant-4 Up X minutes 127.0.0.1:8304->8080/tcp
restaurant-db Up X minutes 5432/tcp
vampi-1 Up X minutes 127.0.0.1:5101->5000/tcp
vampi-2 Up X minutes 127.0.0.1:5102->5000/tcp
vampi-3 Up X minutes 127.0.0.1:5103->5000/tcp
vampi-4 Up X minutes 127.0.0.1:5104->5000/tcp
whoami-1 Up X minutes 127.0.0.1:8082->80/tcp
whoami-2 Up X minutes 127.0.0.1:8083->80/tcp
whoami-3 Up X minutes 127.0.0.1:8084->80/tcp
whoami-4 Up X minutes 127.0.0.1:8085->80/tcp
Terminal window
ssh azureuser@${ORIGIN_IP} "sudo nginx -t && sudo systemctl status nginx --no-pager"

หาก endpoints คืนค่า 502 หรือปฏิเสธการเชื่อมต่อ อาจเป็นเพราะ cloud-init ยังอยู่ในขั้นตอนการจัดเตรียม:

Terminal window
ssh azureuser@${ORIGIN_IP} "cloud-init status"
  • status: running — ยังอยู่ในขั้นตอนการจัดเตรียม รอสักครู่
  • status: done — การจัดเตรียมเสร็จสมบูรณ์ ให้ตรวจสอบ Docker containers
  • status: error — ตรวจสอบ logs ด้านล่าง
Terminal window
ssh azureuser@${ORIGIN_IP} "sudo tail -100 /var/log/cloud-init-output.log"
Terminal window
# Check container logs (each app has 4 instances: -1 through -4)
ssh azureuser@${ORIGIN_IP} "sudo docker logs juice-shop-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs dvwa-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs vampi-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs httpbin-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs csd-demo-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs dvga-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs restaurant-1 2>&1 | tail -20"
ssh azureuser@${ORIGIN_IP} "sudo docker logs crapi-web 2>&1 | tail -20"

upstream container ยังไม่พร้อมหรือเกิดข้อผิดพลาด:

Terminal window
# Check nginx error log
ssh azureuser@${ORIGIN_IP} "sudo tail -20 /var/log/nginx/error.log"
# Restart all instances of a specific app
ssh azureuser@${ORIGIN_IP} "for i in 1 2 3 4; do sudo docker restart juice-shop-\$i; done"
# Rebuild and restart all containers
ssh azureuser@${ORIGIN_IP} "cd /opt/origin-server && sudo docker compose build && sudo docker compose up -d"

Docker images ใช้พื้นที่ประมาณ 4.7 GiB การบันทึก access log ถูกปิดใช้งานเพื่อป้องกันดิสก์เต็มจากการทดสอบโหลด CDN Logrotate ถูกกำหนดค่าเป็นการป้องกันเชิงลึก (จำกัดที่ 500 MiB) ตรวจสอบการใช้งานดิสก์:

Terminal window
ssh azureuser@${ORIGIN_IP} "df -h / && sudo docker system df"

ตรวจสอบ containers ที่ใกล้ถึงขีดจำกัดหน่วยความจำ (ความเสี่ยง OOM):

Terminal window
ssh azureuser@${ORIGIN_IP} "sudo docker stats --no-stream --format 'table {{.Name}}\t{{.MemUsage}}\t{{.MemPerc}}' | sort"

หากจำเป็น ให้ rebuild และรีสตาร์ทบริการทั้งหมด:

Terminal window
ssh azureuser@${ORIGIN_IP} "cd /opt/origin-server && sudo docker compose down && sudo docker compose build && sudo docker compose up -d && sudo systemctl restart nginx"