mirror of
https://github.com/Retropex/dockerfile-deps.git
synced 2025-05-13 00:40:41 +02:00
Add our own image of postgres for migrations
This commit is contained in:
parent
4df8202cbd
commit
1882d54625
16
Postgres/13.4/linuxamd64.Dockerfile
Normal file
16
Postgres/13.4/linuxamd64.Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM postgres:13.4
|
||||||
|
|
||||||
|
ENV PREVIOUS_VERSION 9.6
|
||||||
|
RUN cp /etc/apt/sources.list.d/pgdg.list /etc/apt/sources.list.d/pgdg.list.backup && \
|
||||||
|
sed -i "s/$/ $PREVIOUS_VERSION/" /etc/apt/sources.list.d/pgdg.list && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
postgresql-$PREVIOUS_VERSION \
|
||||||
|
postgresql-contrib-$PREVIOUS_VERSION && \
|
||||||
|
rm /etc/apt/sources.list.d/pgdg.list && mv /etc/apt/sources.list.d/pgdg.list.backup /etc/apt/sources.list.d/pgdg.list && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY migrate-docker-entrypoint.sh /migrate-docker-entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/migrate-docker-entrypoint.sh"]
|
||||||
|
CMD ["postgres"]
|
23
Postgres/13.4/linuxarm32v7.Dockerfile
Normal file
23
Postgres/13.4/linuxarm32v7.Dockerfile
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
FROM --platform=arm postgres:13.4
|
||||||
|
|
||||||
|
# Postgres doesn't ship packages for 9.6
|
||||||
|
ENV PREVIOUS_VERSION 9.6
|
||||||
|
RUN FALLBACK="http://aois.blob.core.windows.net/public/$PREVIOUS_VERSION-$(uname -m).tar.gz" && \
|
||||||
|
FALLBACK_SHARE="http://aois.blob.core.windows.net/public/share-$PREVIOUS_VERSION-$(uname -m).tar.gz" && \
|
||||||
|
apt-get update && apt-get install --no-install-recommends -y wget && \
|
||||||
|
rm -rf /var/lib/apt/lists/* && \
|
||||||
|
cd /usr/lib/postgresql && \
|
||||||
|
wget $FALLBACK && \
|
||||||
|
echo "50a98f90ad9c61d0b5b5ccb9c984ca48bd6e6f331ed17eb87086a2c4290c75c6 9.6-armv7l.tar.gz" | sha256sum -c - && \
|
||||||
|
tar -xvf *.tar.gz && \
|
||||||
|
rm -f *.tar.gz && \
|
||||||
|
cd /usr/share/postgresql && \
|
||||||
|
wget $FALLBACK_SHARE && \
|
||||||
|
echo "10c8c66d97fcb1cd9b22334118ba5afd495147c94f3a03409ca98da54643b433 share-9.6-armv7l.tar.gz" | sha256sum -c - && \
|
||||||
|
tar -xvf *.tar.gz && \
|
||||||
|
rm -f *.tar.gz
|
||||||
|
|
||||||
|
COPY migrate-docker-entrypoint.sh /migrate-docker-entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/migrate-docker-entrypoint.sh"]
|
||||||
|
CMD ["postgres"]
|
16
Postgres/13.4/linuxarm64v8.Dockerfile
Normal file
16
Postgres/13.4/linuxarm64v8.Dockerfile
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
FROM --platform=arm64 postgres:13.4
|
||||||
|
|
||||||
|
ENV PREVIOUS_VERSION 9.6
|
||||||
|
RUN cp /etc/apt/sources.list.d/pgdg.list /etc/apt/sources.list.d/pgdg.list.backup && \
|
||||||
|
sed -i "s/$/ $PREVIOUS_VERSION/" /etc/apt/sources.list.d/pgdg.list && \
|
||||||
|
apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends \
|
||||||
|
postgresql-$PREVIOUS_VERSION \
|
||||||
|
postgresql-contrib-$PREVIOUS_VERSION && \
|
||||||
|
rm /etc/apt/sources.list.d/pgdg.list && mv /etc/apt/sources.list.d/pgdg.list.backup /etc/apt/sources.list.d/pgdg.list && \
|
||||||
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY migrate-docker-entrypoint.sh /migrate-docker-entrypoint.sh
|
||||||
|
|
||||||
|
ENTRYPOINT ["/migrate-docker-entrypoint.sh"]
|
||||||
|
CMD ["postgres"]
|
76
Postgres/13.4/migrate-docker-entrypoint.sh
Executable file
76
Postgres/13.4/migrate-docker-entrypoint.sh
Executable file
@ -0,0 +1,76 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -Eeo pipefail
|
||||||
|
shopt -s extglob
|
||||||
|
|
||||||
|
CURRENT_PGVERSION=""
|
||||||
|
EXPECTED_PGVERSION="$PG_MAJOR"
|
||||||
|
if [[ -f "/var/lib/postgresql/data/PG_VERSION" ]]; then
|
||||||
|
CURRENT_PGVERSION="$(cat /var/lib/postgresql/data/PG_VERSION)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$CURRENT_PGVERSION" != "$EXPECTED_PGVERSION" ]] && \
|
||||||
|
[[ "$CURRENT_PGVERSION" != "" ]]; then
|
||||||
|
|
||||||
|
if ! [ -f "/usr/lib/postgresql/$CURRENT_PGVERSION/bin/pg_upgrade" ]; then
|
||||||
|
sed -i "s/$/ $CURRENT_PGVERSION/" /etc/apt/sources.list.d/pgdg.list
|
||||||
|
if ! apt-get update; then
|
||||||
|
echo "apt-get update failed. Are you using raspberry pi 4? If yes, please follow https://blog.samcater.com/fix-workaround-rpi4-docker-libseccomp2-docker-20/"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! apt-get install -y --no-install-recommends \
|
||||||
|
postgresql-$CURRENT_PGVERSION \
|
||||||
|
postgresql-contrib-$CURRENT_PGVERSION; then
|
||||||
|
# On arm32, postgres doesn't ship those packages, so we download
|
||||||
|
# the binaries from an archive we built from the postgres 9.6.20 image's binaries
|
||||||
|
FALLBACK="https://aois.blob.core.windows.net/public/$CURRENT_PGVERSION-$(uname -m).tar.gz"
|
||||||
|
FALLBACK_SHARE="https://aois.blob.core.windows.net/public/share-$CURRENT_PGVERSION-$(uname -m).tar.gz"
|
||||||
|
echo "Failure to install postgresql-$CURRENT_PGVERSION and postgresql-contrib-$CURRENT_PGVERSION trying fallback $FALLBACK"
|
||||||
|
apt-get install -y wget
|
||||||
|
pushd . > /dev/null
|
||||||
|
cd /usr/lib/postgresql
|
||||||
|
wget $FALLBACK
|
||||||
|
tar -xvf *.tar.gz
|
||||||
|
rm -f *.tar.gz
|
||||||
|
cd /usr/share/postgresql
|
||||||
|
wget $FALLBACK_SHARE
|
||||||
|
tar -xvf *.tar.gz
|
||||||
|
rm -f *.tar.gz
|
||||||
|
popd > /dev/null
|
||||||
|
echo "Successfully installed PG utilities via the fallback"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Migration binaries already present on the image"
|
||||||
|
fi
|
||||||
|
|
||||||
|
export PGBINOLD="/usr/lib/postgresql/$CURRENT_PGVERSION/bin"
|
||||||
|
export PGDATABASE="/var/lib/postgresql/data"
|
||||||
|
export PGDATAOLD="/var/lib/postgresql/data/$CURRENT_PGVERSION"
|
||||||
|
export PGDATANEW="/var/lib/postgresql/data/$EXPECTED_PGVERSION"
|
||||||
|
|
||||||
|
mkdir -p "$PGDATANEW" "$PGDATAOLD"
|
||||||
|
find "$PGDATABASE" -maxdepth 1 -mindepth 1 \
|
||||||
|
-not -wholename "$PGDATAOLD" \
|
||||||
|
-not -wholename "$PGDATANEW" \
|
||||||
|
-exec mv {} "$PGDATAOLD/" \;
|
||||||
|
|
||||||
|
chmod 700 "$PGDATAOLD" "$PGDATANEW"
|
||||||
|
chown postgres .
|
||||||
|
chown -R postgres "$PGDATAOLD" "$PGDATANEW" "$PGDATABASE"
|
||||||
|
if [ ! -s "$PGDATANEW/PG_VERSION" ]; then
|
||||||
|
PGDATA="$PGDATANEW" eval "gosu postgres initdb $POSTGRES_INITDB_ARGS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
gosu postgres pg_upgrade
|
||||||
|
rm $PGDATANEW/*.conf
|
||||||
|
mv $PGDATANEW/* "$PGDATABASE"
|
||||||
|
mv $PGDATAOLD/*.conf "$PGDATABASE"
|
||||||
|
rm -r "$PGDATANEW"
|
||||||
|
./delete_old_cluster.sh
|
||||||
|
rm ./analyze_new_cluster.sh
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -f "docker-entrypoint.sh" ]; then
|
||||||
|
exec ./docker-entrypoint.sh "$@"
|
||||||
|
else
|
||||||
|
exec docker-entrypoint.sh "$@"
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user