diff --git a/Dockerfile b/Dockerfile index 7f9f55e..917e151 100644 --- a/Dockerfile +++ b/Dockerfile @@ -59,9 +59,11 @@ COPY --from=admin-builder /build/admin/dist /var/www/html # Copy configs COPY apps/admin-ui/nginx.conf /etc/nginx/conf.d/default.conf COPY supervisord.conf /etc/supervisord.conf +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \ CMD curl -f http://localhost/health || exit 1 -ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["supervisord", "-c", "/etc/supervisord.conf"] +ENTRYPOINT ["/entrypoint.sh"] +CMD ["/usr/bin/tini", "--", "supervisord", "-c", "/etc/supervisord.conf"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..320d2e3 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh +set -e + +# Extract host and port from DATABASE_URL for wait check +DB_HOST=$(echo "$DATABASE_URL" | sed -E 's|.*@([^/:]+).*|\1|') +DB_PORT=$(echo "$DATABASE_URL" | sed -E 's|.*:[0-9]+/([0-9]+).*|\1|' | head -1) + +if [ -z "$DB_PORT" ] || [ "$DB_PORT" = "$DB_HOST" ]; then + DB_PORT="5432" +fi + +echo "Waiting for postgres at $DB_HOST:$DB_PORT ..." + +max_retries=30 +counter=0 +until pg_isready -h "$DB_HOST" -p "$DB_PORT" -q 2>/dev/null; do + counter=$((counter + 1)) + if [ $counter -ge $max_retries ]; then + echo "ERROR: postgres at $DB_HOST:$DB_PORT not ready after ${max_retries}s" + exit 1 + fi + echo " postgres not ready, retrying in 2s ... ($counter/$max_retries)" + sleep 2 +done + +echo "postgres is ready!" + +# Execute the passed command (supervisord) +exec "$@"