Skip to content

chore: update adminapi; persist scripts for AIO image #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ postgres_exporter_release_checksum:
arm64: sha256:d869c16791481dc8475487ad84ae4371a63f9b399898ca1c666eead5cccf7182
amd64: sha256:ff541bd3ee19c0ae003d71424a75edfcc8695e828dd20d5b4555ce433c89d60b

adminapi_release: 0.44.3
adminapi_release: 0.45.1
adminmgr_release: 0.5.0

# Postgres Extensions
Expand Down
2 changes: 1 addition & 1 deletion common.vars.pkr.hcl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
postgres-version = "15.1.0.96"
postgres-version = "15.1.0.97"
2 changes: 1 addition & 1 deletion docker/all-in-one/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG pgbouncer_release=1.18.0
ARG postgrest_release=10.1.2
ARG gotrue_release=2.47.0
ARG kong_release=2.8.1
ARG adminapi_release=0.44.3
ARG adminapi_release=0.45.1
ARG adminmgr_release=0.5.0
ARG vector_release=0.22.3
ARG postgres_exporter_release=0.9.0
Expand Down
7 changes: 3 additions & 4 deletions docker/all-in-one/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function enable_swap {
PG_CONF=/etc/postgresql/postgresql.conf
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf

DATA_VOLUME_MOUNTPOINT=${DATA_VOLUME_MOUNTPOINT:-/data}
export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:-$DATA_VOLUME_MOUNTPOINT/machine.configured}

function setup_postgres {
Expand Down Expand Up @@ -85,6 +86,8 @@ function setup_postgres {
$PG_CONF

if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then
/opt/supabase-admin-api optimize db --destination-config-file-path /etc/postgresql-custom/generated-optimizations.conf

# Preserve postgresql configs across restarts
POSTGRESQL_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/postgresql-custom"

Expand Down Expand Up @@ -117,10 +120,6 @@ function setup_postgres {
chmod g+rx "/etc/wal-g"
chmod g+rx "${WALG_CONF_DIR}"
fi

# TODO: define instance size and type for running optimizations
# /opt/supabase-admin-api optimize db --destination-config-file-path /etc/postgresql-custom/generated-optimizations.conf
# /opt/supabase-admin-api optimize pgbouncer --destination-config-file-path /etc/pgbouncer-custom/generated-optimizations.ini
}

function setup_credentials {
Expand Down
13 changes: 13 additions & 0 deletions docker/all-in-one/init/configure-adminapi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ set -eou pipefail
ADMIN_API_CONF=/etc/adminapi/adminapi.yaml
touch /var/log/services/adminapi.log

ADMINAPI_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/adminapi"
mkdir -p "${ADMINAPI_CUSTOM_DIR}"
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then
echo "Copying existing custom adminapi config from /etc/adminapi to ${ADMINAPI_CUSTOM_DIR}"
cp -R "/etc/adminapi/." "${ADMINAPI_CUSTOM_DIR}/"
fi

rm -rf "/etc/adminapi"
ln -s "${ADMINAPI_CUSTOM_DIR}" "/etc/adminapi"
chown -R adminapi:adminapi "/etc/adminapi"
chown -R adminapi:adminapi "${ADMINAPI_CUSTOM_DIR}"
chmod g+rx "${ADMINAPI_CUSTOM_DIR}"

if [ -f "${INIT_PAYLOAD_PATH:-}" ]; then
echo "init adminapi payload"
tar -xzvf "$INIT_PAYLOAD_PATH" -C / ./etc/adminapi/adminapi.yaml
Expand Down
13 changes: 13 additions & 0 deletions docker/all-in-one/init/configure-gotrue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ sed -i "s|gotrue_api_host|${GOTRUE_API_HOST:-0.0.0.0}|g" /etc/gotrue.env
sed -i "s|gotrue_site_url|$GOTRUE_SITE_URL|g" /etc/gotrue.env
sed -i "s|gotrue_jwt_secret|$JWT_SECRET|g" /etc/gotrue.env

GOTRUE_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/gotrue"
mkdir -p "${GOTRUE_CUSTOM_DIR}"
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then
echo "Copying existing custom GoTrue config from /etc/gotrue to ${GOTRUE_CUSTOM_DIR}"
cp -R "/etc/gotrue/." "${GOTRUE_CUSTOM_DIR}/"
fi

rm -rf "/etc/gotrue"
ln -s "${GOTRUE_CUSTOM_DIR}" "/etc/gotrue"
chown -R adminapi:adminapi "/etc/gotrue"
chown -R adminapi:adminapi "${GOTRUE_CUSTOM_DIR}"
chmod g+rx "${GOTRUE_CUSTOM_DIR}"

if [ -f "${INIT_PAYLOAD_PATH:-}" ]; then
echo "init gotrue payload"
tar -xzvf "$INIT_PAYLOAD_PATH" -C / ./etc/gotrue.env
Expand Down
4 changes: 3 additions & 1 deletion docker/all-in-one/init/configure-pgbouncer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if [ -f "${INIT_PAYLOAD_PATH:-}" ]; then
fi

if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then
/opt/supabase-admin-api optimize pgbouncer --destination-config-file-path /etc/pgbouncer-custom/generated-optimizations.ini

# Preserve pgbouncer configs across restarts
PGBOUNCER_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/pgbouncer-custom"

Expand All @@ -28,5 +30,5 @@ if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then
ln -s "${PGBOUNCER_CUSTOM_DIR}" "/etc/pgbouncer-custom"
chown -R pgbouncer:pgbouncer "/etc/pgbouncer-custom"
chown -R pgbouncer:pgbouncer "${PGBOUNCER_CUSTOM_DIR}"
chmod g+rx "${PGBOUNCER_CUSTOM_DIR}"
chmod -R g+rx "${PGBOUNCER_CUSTOM_DIR}"
fi
17 changes: 15 additions & 2 deletions docker/all-in-one/init/configure-postgrest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,26 @@ sed -i "s|pgrst_db_extra_search_path|${PGRST_DB_SCHEMAS:-public,extensions}|g" /
sed -i "s|pgrst_db_anon_role|${PGRST_DB_ANON_ROLE:-anon}|g" /etc/postgrest/base.conf
sed -i "s|pgrst_jwt_secret|$JWT_SECRET|g" /etc/postgrest/base.conf

POSTGREST_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/postgrest"
mkdir -p "${POSTGREST_CUSTOM_DIR}"
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then
echo "Copying existing custom PostgREST config from /etc/postgrest/ to ${POSTGREST_CUSTOM_DIR}"
cp -R "/etc/postgrest/." "${POSTGREST_CUSTOM_DIR}/"
fi

rm -rf "/etc/postgrest"
ln -s "${POSTGREST_CUSTOM_DIR}" "/etc/postgrest"
chown -R postgrest:postgrest "/etc/postgrest"
chown -R postgrest:postgrest "${POSTGREST_CUSTOM_DIR}"
chmod g+rx "${POSTGREST_CUSTOM_DIR}"

if [ -f "${INIT_PAYLOAD_PATH:-}" ]; then
echo "init postgrest payload"
tar -xzvf "$INIT_PAYLOAD_PATH" -C / ./etc/postgrest/base.conf
chown -R postgrest:postgrest /etc/postgrest
fi

PGRST_CONF=/etc/postgrest/generated.conf
# TODO: merge base config with optimisations
# /opt/supabase-admin-api optimize postgrest --destination-config-file-path $PGRST_CONF

/opt/supabase-admin-api optimize postgrest --destination-config-file-path $PGRST_CONF
cat /etc/postgrest/base.conf >> $PGRST_CONF
2 changes: 1 addition & 1 deletion docker/all-in-one/shutdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ SQL
run_sql -c "ALTER SYSTEM SET log_disconnections = 'on';"
run_sql -c "SELECT pg_reload_conf();"

sleep $((MAX_IDLE_TIME_MINUTES * 60))
sleep $((DEFAULT_MAX_IDLE_TIME_MINUTES * 60))
while true; do
if [ -f "$CONFIG_FILE_PATH" ]; then
source "$CONFIG_FILE_PATH"
Expand Down