diff --git a/Dockerfile b/Dockerfile index d8f6cd1..647256b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ ARG TW_BIN=./bin/tailwindcss WORKDIR /app COPY . /app -RUN apt-get update && apt-get install -y --no-install-recommends build-essential curl libev-dev +RUN apt-get update && apt-get install -y --no-install-recommends build-essential curl wget libev-dev RUN mkdir -p ./bin \ && curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v${TW_VERSION}/tailwindcss-linux-x64 \ diff --git a/entrypoint.sh b/entrypoint.sh index 8361b19..73f08a0 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,21 @@ #!/bin/bash set -e +echo "Starting server..." +.qlot/bin/clackup --system hp --server woo --address 0.0.0.0 --port 3000 src/app.lisp & + +SERVER_PID=$! + +echo "Waiting for server to be ready..." +for i in {1..10}; do + if curl -s -o /dev/null -w "%{http_code}" -I http://0.0.0.0:3000 | grep -q "200"; then + echo "Server is up." + break + fi + echo "Server not ready yet... retrying ($i)" + sleep 5 +done + if [[ -n "$CLOUDFLARE_ZONE_ID" && -n "$CLOUDFLARE_API_KEY" ]]; then echo "Purging Cloudflare cache..." curl -s -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/purge_cache" \ @@ -11,5 +26,4 @@ else echo "Cloudflare credentials not provided. Skipping cache purge." fi -echo "Starting server..." -exec .qlot/bin/clackup --system hp --server woo --address 0.0.0.0 --port 3000 src/app.lisp +wait $SERVER_PID diff --git a/src/routes/index.lisp b/src/routes/index.lisp index 683ccc1..418e8c5 100644 --- a/src/routes/index.lisp +++ b/src/routes/index.lisp @@ -1,7 +1,8 @@ (defpackage #:hp/routes/index (:use #:cl #:hsx) - (:export #:handle-get)) + (:export #:handle-get + #:handle-head)) (in-package #:hp/routes/index) (defparameter *links* @@ -30,3 +31,7 @@ (declare (ignore params)) (list :body (~page) :cache :static)) + +; for health check +(defun handle-head (params) + (declare (ignore params)))