8000 chore: fly fixes; PITR + logging + shutdown + perms (#665) · supabase/postgres@932d7cc · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit 932d7cc

Browse files
authored
chore: fly fixes; PITR + logging + shutdown + perms (#665)
* chore: remove folder creation * trigger build * trigger build * chore: reorder symlinks * chore: fly fixes; PITR + logging + shutdown + perms * chore: rename shutdown script; refactoring
1 parent a1ecec8 commit 932d7cc

File tree

13 files changed

+671
-105
lines changed

13 files changed

+671
-105
lines changed

.github/workflows/dockerhub-release-aio.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Release AIO image on Dockerhub
33
on:
44
push:
55
branches:
6-
- pcnc/migrate-all-in-one
6+
- pcnc/fly-fixes
77
paths:
88
- ".github/workflows/dockerhub-release-aio.yml"
9-
- "docker/all-in-one/Dockerfile"
9+
- "docker/all-in-one/*"
1010
- "common.vars*"
1111
workflow_run:
1212
workflows: [Release on Dockerhub]

ansible/files/postgresql_config/custom_walg.conf.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# - Recovery Target -
1313

14+
#recovery_target = 'immediate'
1415
#recovery_target_time = ''
1516
#recovery_target_action = 'promote'
1617
#recovery_target_timeline = 'current'

ansible/vars.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ postgres_exporter_release_checksum:
4242
amd64: sha256:ff541bd3ee19c0ae003d71424a75edfcc8695e828dd20d5b4555ce433c89d60b
4343

4444
adminapi_release: 0.44.3
45-
adminmgr_release: 0.4.0
45+
adminmgr_release: 0.5.0
4646

4747
# Postgres Extensions
4848
postgis_release: "3.3.2"

docker/all-in-one/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG postgrest_release=10.1.2
55
ARG gotrue_release=2.47.0
66
ARG kong_release=2.8.1
77
ARG adminapi_release=0.44.3
8-
ARG adminmgr_release=0.4.0
8+
ARG adminmgr_release=0.5.0
99
ARG vector_release=0.22.3
1010
ARG postgres_exporter_release=0.9.0
1111

@@ -230,4 +230,6 @@ HEALTHCHECK --interval=3s --timeout=2s --start-period=4s --retries=10 CMD [ "hea
230230

231231
COPY docker/all-in-one/init /init
232232
COPY docker/all-in-one/entrypoint.sh /usr/local/bin/
233+
COPY docker/all-in-one/postgres-entrypoint.sh /usr/local/bin/
234+
COPY docker/all-in-one/shutdown.sh /usr/local/bin/supa-shutdown.sh
233235
ENTRYPOINT [ "entrypoint.sh" ]

docker/all-in-one/entrypoint.sh

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ function configure_services {
4040
PG_CONF=/etc/postgresql/postgresql.conf
4141
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf
4242

43+
export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:-$DATA_VOLUME_MOUNTPOINT/machine.configured}
44+
4345
function setup_postgres {
4446
tar -xzvf "$INIT_PAYLOAD_PATH" -C / ./etc/postgresql.schema.sql
4547
mv /etc/postgresql.schema.sql /docker-entrypoint-initdb.d/migrations/99-schema.sql
@@ -75,6 +77,40 @@ function setup_postgres {
7577
-e "s|ssl_key_file = ''|ssl_key_file = '$PGSSLKEY'|g" \
7678
$PG_CONF
7779

80+
if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then
81+
# Preserve postgresql configs across restarts
82+
POSTGRESQL_CUSTOM_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/postgresql-custom"
83+
84+
mkdir -p "${POSTGRESQL_CUSTOM_DIR}"
85+
86+
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then
87+
echo "Copying existing custom postgresql config from /etc/postgresql-custom to ${POSTGRESQL_CUSTOM_DIR}"
88+
cp -R "/etc/postgresql-custom/." "${POSTGRESQL_CUSTOM_DIR}/"
89+
fi
90+
91+
rm -rf "/etc/postgresql-custom"
92+
ln -s "${POSTGRESQL_CUSTOM_DIR}" "/etc/postgresql-custom"
93+
chown -R postgres:postgres "/etc/postgresql-custom"
94+
chown -R postgres:postgres "${POSTGRESQL_CUSTOM_DIR}"
95+
chmod g+rx "${POSTGRESQL_CUSTOM_DIR}"
96+
97+
# Preserve wal-g configs across restarts
98+
WALG_CONF_DIR="${DATA_VOLUME_MOUNTPOINT}/etc/wal-g"
99+
mkdir -p "${WALG_CONF_DIR}"
100+
101+
if [ ! -f "${CONFIGURED_FLAG_PATH}" ]; then
102+
echo "Copying existing custom wal-g config from /etc/wal-g to ${WALG_CONF_DIR}"
103+
cp -R "/etc/wal-g/." "${WALG_CONF_DIR}/"
104+
fi
105+
106+
rm -rf "/etc/wal-g"
107+
ln -s "${WALG_CONF_DIR}" "/etc/wal-g"
108+
chown -R adminapi:adminapi "/etc/wal-g"
109+
chown -R adminapi:adminapi "${WALG_CONF_DIR}"
110+
chmod g+rx "/etc/wal-g"
111+
chmod g+rx "${WALG_CONF_DIR}"
112+
fi
113+
78114
# TODO: define instance size and type for running optimizations
79115
# /opt/supabase-admin-api optimize db --destination-config-file-path /etc/postgresql-custom/generated-optimizations.conf
80116
# /opt/supabase-admin-api optimize pgbouncer --destination-config-file-path /etc/pgbouncer-custom/generated-optimizations.ini
@@ -121,14 +157,15 @@ fi
121157
if [ "${PGDATA_REAL:-}" ]; then
122158
mkdir -p "${PGDATA_REAL}"
123159
chown -R postgres:postgres "${PGDATA_REAL}"
124-
chmod g+rx "${PGDATA_REAL}"
160+
chmod -R g+rx "${PGDATA_REAL}"
125161
fi
126162

127163
if [ "${PGDATA:-}" ]; then
128164
if [ "${PGDATA_REAL:-}" ]; then
129165
mkdir -p "$(dirname "${PGDATA}")"
130166
rm -rf "${PGDATA}"
131167
ln -s "${PGDATA_REAL}" "${PGDATA}"
168+
chmod -R g+rx "${PGDATA}"
132169
else
133170
mkdir -p "$PGDATA"
134171
chown postgres:postgres "$PGDATA"
@@ -138,10 +175,22 @@ fi
138175

139176
# Download and extract init payload from s3
140177
export INIT_PAYLOAD_PATH=${INIT_PAYLOAD_PATH:-/tmp/payload.tar.gz}
141-
export CONFIGURED_FLAG_PATH=${CONFIGURED_FLAG_PATH:-$PGDATA/../machine.configured}
142178

143179
if [ "${INIT_PAYLOAD_PRESIGNED_URL:-}" ]; then
144-
curl -sSL "$INIT_PAYLOAD_PRESIGNED_URL" -o "$INIT_PAYLOAD_PATH"
180+
curl -fsSL "$INIT_PAYLOAD_PRESIGNED_URL" -o "/tmp/payload.tar.gz"
181+
mv "/tmp/payload.tar.gz" "$INIT_PAYLOAD_PATH"
182+
fi
183+
184+
if [ "${DATA_VOLUME_MOUNTPOINT}" ]; then
185+
BASE_LOGS_FOLDER="${DATA_VOLUME_MOUNTPOINT}/logs"
186+
187+
for folder in "postgresql" "services" "wal-g"; do
188+
mkdir -p "${BASE_LOGS_FOLDER}/${folder}"
189+
rm -rf "/var/log/${folder}"
190+
ln -s "${BASE_LOGS_FOLDER}/${folder}" "/var/log/${folder}"
191+
done
192+
193+
chown -R postgres:postgres "${LOGS_FOLDER}"
145194
fi
146195

147196
# Process init payload
@@ -152,7 +201,7 @@ else
152201
echo "Skipped extracting init payload: $INIT_PAYLOAD_PATH does not exist"
153202
fi
154203

155-
mkdir /var/log/services
204+
mkdir -p /var/log/services
156205

157206
SUPERVISOR_CONF=/etc/supervisor/supervisord.conf
158207
find /etc/supervisor/ -type d -exec chmod 0770 {} +

docker/all-in-one/etc/supervisor/db-only/postgresql.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[program:postgresql]
2-
command=/usr/local/bin/docker-entrypoint.sh postgres -D /etc/postgresql
2+
command=/usr/local/bin/postgres-entrypoint.sh postgres -D /etc/postgresql
33
user=postgres
44
stopsignal=INT
55
autorestart=true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[program:supa-shutdown]
2+
command=/usr/local/bin/supa-shutdown.sh
3+
user=root
4+
autorestart=true
5+
autostart=true
6+
stdout_logfile=/var/log/services/supa-shutdown.log
7+
redirect_stderr=true
8+
stdout_logfile_maxbytes=10MB
9+
priority=50

0 commit comments

Comments
 (0)
0