From 9f4d7e5a220b9e08633fbba2da34c1d44e9ce227 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 17 May 2025 22:06:33 +0800 Subject: [PATCH] . --- Dockerfile | 54 +++++++++++++++++++++++++++++- supabase/kong/wrapper.sh | 10 +++++- supabase/postgres/supervisord.conf | 37 ++++++++++---------- supabase/postgres/wrapper.sh | 9 ++++- supabase/storage-api/wrapper.sh | 3 +- 5 files changed, 91 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index c0597f7..6ea3e1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -331,4 +331,56 @@ RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ COPY --from=s3final node_modules /supabase/storage-api/node_modules COPY --from=s3final dist /supabase/storage-api/dist -COPY --from=s3final migrations /supabase/storage-api/migrations \ No newline at end of file +COPY --from=s3final migrations /supabase/storage-api/migrations + +#=========================================== kong ========================================================= +ARG ASSET=ce +ENV ASSET $ASSET + +ARG EE_PORTS + +COPY docker-kong_v2.8.1/ubuntu/kong.deb /tmp/kong.deb + +ARG KONG_VERSION=2.8.1 +ENV KONG_VERSION $KONG_VERSION + +ARG KONG_AMD64_SHA="10d12d23e5890414d666663094d51a42de41f8a9806fbc0baaf9ac4d37794361" +ARG KONG_ARM64_SHA="61c13219ef64dac9aeae5ae775411e8cfcd406f068cf3e75d463f916ae6513cb" + +# hadolint ignore=DL3015 +RUN set -ex; \ + arch=$(dpkg --print-architecture); \ + case "${arch}" in \ + amd64) KONG_SHA256=$KONG_AMD64_SHA ;; \ + arm64) KONG_SHA256=$KONG_ARM64_SHA ;; \ + esac; \ + apt-get update \ + && if [ "$ASSET" = "ce" ] ; then \ + apt-get install -y curl \ + && UBUNTU_CODENAME=focal \ + && KONG_REPO=$(echo ${KONG_VERSION%.*} | sed 's/\.//') \ + && curl -fL https://packages.konghq.com/public/gateway-$KONG_REPO/deb/ubuntu/pool/$UBUNTU_CODENAME/main/k/ko/kong_$KONG_VERSION/kong_${KONG_VERSION}_$arch.deb -o /tmp/kong.deb \ + && apt-get purge -y curl \ + && echo "$KONG_SHA256 /tmp/kong.deb" | sha256sum -c -; \ + else \ + # this needs to stay inside this "else" block so that it does not become part of the "official images" builds (https://github.com/docker-library/official-images/pull/11532#issuecomment-996219700) + apt-get upgrade -y ; \ + fi; \ + apt-get install -y --no-install-recommends unzip git \ + # Please update the ubuntu install docs if the below line is changed so that + # end users can properly install Kong along with its required dependencies + # and that our CI does not diverge from our docs. + && apt install --yes /tmp/kong.deb \ + && rm -rf /var/lib/apt/lists/* \ + && rm -rf /tmp/kong.deb \ + && chown kong:0 /usr/local/bin/kong \ + && chown -R kong:0 /usr/local/kong \ + && ln -s /usr/local/openresty/bin/resty /usr/local/bin/resty \ + && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/luajit \ + && ln -s /usr/local/openresty/luajit/bin/luajit /usr/local/bin/lua \ + && ln -s /usr/local/openresty/nginx/sbin/nginx /usr/local/bin/nginx \ + && if [ "$ASSET" = "ce" ] ; then \ + kong version ; \ + fi + +COPY --chmod=0755 docker-kong_v2.8.1/ubuntu/docker-entrypoint.sh /supabase/kong/docker-entrypoint.sh diff --git a/supabase/kong/wrapper.sh b/supabase/kong/wrapper.sh index 3c8d4f4..50d433b 100644 --- a/supabase/kong/wrapper.sh +++ b/supabase/kong/wrapper.sh @@ -1,5 +1,13 @@ #!/bin/bash -set -e +set -euo pipefail + +# 捕获 SIGINT / SIGTERM / SIGQUIT 信号以优雅退出 +cleanup() { + echo "[gotrue] Caught termination signal, shutting down..." + exit 0 +} + +trap SIGQUIT until curl -s http://localhost:5000/rest/v1/ >/dev/null 2>&1; do echo "Waiting for postgrest (via Kong)..." diff --git a/supabase/postgres/supervisord.conf b/supabase/postgres/supervisord.conf index 33969fe..191409f 100644 --- a/supabase/postgres/supervisord.conf +++ b/supabase/postgres/supervisord.conf @@ -44,24 +44,25 @@ autorestart=true stderr_logfile=/var/log/storage-api.err.log stdout_logfile=/var/log/storage-api.out.log -# [program:kong] -# command=/supabase/kong/docker-entrypoint.sh kong docker-start -# autorestart=true -# stdout_logfile=/var/log/kong.out.log -# stderr_logfile=/var/log/kong.err.log -# environment= -# KONG_DATABASE="postgres", -# KONG_PG_HOST="127.0.0.1", -# KONG_PG_PORT="5432", -# KONG_PG_USER="supabase_admin", -# KONG_PG_PASSWORD="postgres", -# KONG_PG_DATABASE="postgres", -# KONG_LOG_LEVEL="info", -# KONG_PROXY_ACCESS_LOG="/dev/stdout", -# KONG_ADMIN_ACCESS_LOG="/dev/stdout", -# KONG_PROXY_ERROR_LOG="/dev/stderr", -# KONG_ADMIN_ERROR_LOG="/dev/stderr", -# KONG_PREFIX="/usr/local/kong" +[program:kong] +command=/bin/bash /supabase/kong/wrapper.sh +user=kong +autorestart=true +stdout_logfile=/var/log/kong.out.log +stderr_logfile=/var/log/kong.err.log +environment= + KONG_DATABASE="postgres", + KONG_PG_HOST="127.0.0.1", + KONG_PG_PORT="5432", + KONG_PG_USER="supabase_admin", + KONG_PG_PASSWORD="postgres", + KONG_PG_DATABASE="postgres", + KONG_LOG_LEVEL="info", + KONG_PROXY_ACCESS_LOG="/dev/stdout", + KONG_ADMIN_ACCESS_LOG="/dev/stdout", + KONG_PROXY_ERROR_LOG="/dev/stderr", + KONG_ADMIN_ERROR_LOG="/dev/stderr", + KONG_PREFIX="/usr/local/kong" diff --git a/supabase/postgres/wrapper.sh b/supabase/postgres/wrapper.sh index 1c6d72f..2ed3ebb 100644 --- a/supabase/postgres/wrapper.sh +++ b/supabase/postgres/wrapper.sh @@ -1,4 +1,11 @@ #!/bin/bash -set -e +# 捕获 SIGINT / SIGTERM / SIGQUIT 信号以优雅退出 + +cleanup() { + echo "[gotrue] Caught termination signal, shutting down..." + exit 0 +} + +trap SIGINT SIGQUIT exec /usr/local/bin/docker-entrypoint.sh postgres -D /etc/postgresql \ No newline at end of file diff --git a/supabase/storage-api/wrapper.sh b/supabase/storage-api/wrapper.sh index fc4603b..09428c9 100644 --- a/supabase/storage-api/wrapper.sh +++ b/supabase/storage-api/wrapper.sh @@ -9,7 +9,8 @@ export DATABASE_URL="postgres://supabase_admin:postgres@127.0.0.1:5432/postgres" export DATABASE_POOL_URL="postgresql://postgres:postgres@127.0.0.1:6432/postgres" export DB_INSTALL_ROLES="true" export STORAGE_BACKEND="file" -export FILE_STORAGE_BACKEND_PATH="/var/lib/storage" # ✅ 必需,否则直接崩溃 +export FILE_STORAGE_BACKEND_PATH="/var/lib/storage" +export DB_INSTALL_ROLES="false" # 等待 gotrue 服务可用(健康检查) until curl -s http://localhost:9999/ >/dev/null 2>&1; do