fix: add entrypoint script to wait for postgres before starting
Some checks failed
CI / Detect changes (push) Has been cancelled
CI / API Lint (push) Has been cancelled
CI / API Tests (push) Has been cancelled
CI / Scanner Lint (push) Has been cancelled
CI / Scanner Tests (push) Has been cancelled
CI / Banner Lint & Typecheck (push) Has been cancelled
CI / Banner Tests (push) Has been cancelled
CI / Banner Build (push) Has been cancelled
CI / Admin UI Typecheck (push) Has been cancelled
CI / Admin UI Tests (push) Has been cancelled
CI / Admin UI Build (push) Has been cancelled

This commit is contained in:
Ami
2026-04-21 15:38:56 +07:00
parent 35ea49d6d2
commit 51b8e15726
2 changed files with 33 additions and 2 deletions

View File

@@ -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"]

29
entrypoint.sh Normal file
View File

@@ -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 "$@"