Automatic upgrade
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-03-29 00:23:52 +00:00
parent 06b715861b
commit 604b7818be
2 changed files with 45 additions and 2 deletions

View File

@@ -11,9 +11,14 @@ FROM postgis/postgis:16-master
COPY --from=builder /usr/local/src/pg_autoconfig/bin/pg_autoconfig /
COPY upgrade-entrypoint.sh /
RUN localedef -i cs_CZ -c -f UTF-8 -A /usr/share/locale/locale.alias cz_CZ.UTF-8 && \
apt-get update && apt-get install -y postgresql-16-auto-failover pg-auto-failover-cli postgresql-16-pgvector && rm -rf /var/lib/apt/lists/*
apt-get update && apt-get install -y postgresql-16-auto-failover pg-auto-failover-cli postgresql-16-pgvector && \
rm -rf /var/lib/apt/lists/* && \
chmod +x /upgrade-entrypoint.sh
#ENV LANG en_GB.utf8
ENTRYPOINT [ "/pg_autoconfig" ]
ENTRYPOINT [ "/upgrade-entrypoint.sh" ]
CMD [ "/pg_autoconfig" ]

38
upgrade-entrypoint.sh Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/bash
set -e
DATA_DIR="/var/lib/postgresql/data"
OLD_VERSION_FILE="$DATA_DIR/PG_VERSION"
NEW_VERSION="16"
if [ -f "$OLD_VERSION_FILE" ]; then
OLD_VERSION=$(cat "$OLD_VERSION_FILE")
if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "Data version ($OLD_VERSION) differs from engine ($NEW_VERSION). Starting upgrade..."
# 1. Move old data to a temporary folder
mkdir -p $DATA_DIR/old_data
mv $DATA_DIR/* $DATA_DIR/old_data/ || true
# 2. Initialize new data directory
mkdir $DATA_DIR/new_data
initdb -D $DATA_DIR/new_data
# 3. Run pg_upgrade
# --link is used to avoid copying files (fast, but requires a backup!)
pg_upgrade \
-d $DATA_DIR/old_data \
-D $DATA_DIR/new_data \
-b /usr/bin/postgres-16 \
-B /usr/local/bin \
--link
echo "Upgrade complete. Cleaning up..."
rm -rf $DATA_DIR/old_data
mv $DATA_DIR/new_data/* $DATA_DIR/
rmdir $DATA_DIR/new_data
fi
fi
exec $@