- Created a GitHub Actions workflow for CI/CD to deploy to Ghyamah, including testing, building, and pushing Docker images. - Added architecture design document for handling 15,000 requests per second, detailing system components, capacity planning, and cold start strategies. - Introduced a Python-based uptime/latency/SSL monitor with a static dashboard, utilizing standard libraries only. - Included Dockerfile and entrypoint script for the monitoring application, ensuring it runs as a non-root user and handles process management. - Added a .dockerignore file to exclude unnecessary files from the Docker build context. - Created an HTML dashboard for visualizing monitoring metrics, including uptime, latency, and SSL certificate status.
43 أسطر
1.3 KiB
Bash
43 أسطر
1.3 KiB
Bash
#!/bin/sh
|
|
# entrypoint.sh — runs the Python monitoring loop and a static HTTP server
|
|
# side by side in a single container. POSIX sh so it works on Alpine's
|
|
# default shell.
|
|
|
|
set -eu
|
|
|
|
PORT="${PORT:-8080}"
|
|
WEB_DIR="${WEB_DIR:-/app/web}"
|
|
|
|
echo "[entrypoint] starting monitor loop"
|
|
python3 /app/monitor.py &
|
|
MONITOR_PID=$!
|
|
|
|
echo "[entrypoint] serving dashboard from ${WEB_DIR} on 0.0.0.0:${PORT}"
|
|
cd "${WEB_DIR}"
|
|
python3 -m http.server "${PORT}" --bind 0.0.0.0 &
|
|
SERVER_PID=$!
|
|
|
|
# Forward termination signals to both children and wait for them so the
|
|
# container shuts down cleanly (e.g. on `docker stop` / platform redeploys).
|
|
term_handler() {
|
|
echo "[entrypoint] shutting down..."
|
|
kill -TERM "$MONITOR_PID" "$SERVER_PID" 2>/dev/null || true
|
|
wait "$MONITOR_PID" "$SERVER_PID" 2>/dev/null || true
|
|
exit 0
|
|
}
|
|
trap term_handler TERM INT
|
|
|
|
# busybox ash (Alpine's /bin/sh) has no `wait -n`, so poll instead: if
|
|
# either child dies unexpectedly, bring the whole container down so the
|
|
# orchestrator (Docker/Kubernetes/Cloud Run/etc.) can restart it.
|
|
while true; do
|
|
if ! kill -0 "$MONITOR_PID" 2>/dev/null; then
|
|
echo "[entrypoint] monitor loop exited unexpectedly — stopping container"
|
|
term_handler
|
|
fi
|
|
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
|
|
echo "[entrypoint] http server exited unexpectedly — stopping container"
|
|
term_handler
|
|
fi
|
|
sleep 2
|
|
done |