1
0

Switch to our own postgres container

This commit is contained in:
nicolas.dorier
2021-10-21 13:38:12 +09:00
parent 8b3f0368a8
commit b153b84953
5 changed files with 17 additions and 91 deletions

View File

@@ -1,71 +0,0 @@
#!/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
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
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

View File

@@ -353,7 +353,7 @@ We are trying to update our dependencies to run on `arm32v7` and `x64` boards. H
| nicolasdorier/ndlc-cli | 1.0.1 | [✔️](https://raw.githubusercontent.com/dgarage/ndlc/releases/1.0.1/amd64.Dockerfile) | [✔️](https://raw.githubusercontent.com/dgarage/ndlc/releases/1.0.1/arm32v7.Dockerfile) | [✔️](https://raw.githubusercontent.com/dgarage/ndlc/releases/1.0.1/arm64v8.Dockerfile) | [Github](https://github.com/dgarage/ndlc) - [DockerHub](https://hub.docker.com/r/nicolasdorier/ndlc-cli) |
| pihole/pihole | v5.7 | [✔️](https://raw.githubusercontent.com/pi-hole/docker-pi-hole/v5.7/Dockerfile) | [✔️](https://raw.githubusercontent.com/pi-hole/docker-pi-hole/v5.7/Dockerfile) | [✔️](https://raw.githubusercontent.com/pi-hole/docker-pi-hole/v5.7/Dockerfile) | [Github](https://github.com/pi-hole/docker-pi-hole) - [DockerHub](https://hub.docker.com/r/pihole/pihole) |
| btcpayserver/tor | 0.4.5.9 | [✔️](https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Tor/0.4.5.9/Tor/0.4.5.9/linuxamd64.Dockerfile) | [✔️](https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Tor/0.4.5.9/Tor/0.4.5.9/linuxarm32v7.Dockerfile) | [✔️](https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Tor/0.4.5.9/Tor/0.4.5.9/linuxarm64v8.Dockerfile) | [Github](https://github.com/btcpayserver/dockerfile-deps) - [DockerHub](https://hub.docker.com/r/btcpayserver/tor) |
| postgres | 13.4 | [✔️](https://raw.githubusercontent.com/docker-library/postgres/b7cb3c6eacea93be2259381033be3cc435649369/9.6/Dockerfile) | [✔️](https://raw.githubusercontent.com/docker-library/postgres/b7cb3c6eacea93be2259381033be3cc435649369/9.6/Dockerfile) | [✔️](https://raw.githubusercontent.com/docker-library/postgres/b7cb3c6eacea93be2259381033be3cc435649369/9.6/Dockerfile) | [Github](https://github.com/docker-library/postgres) - [DockerHub](https://hub.docker.com/_/postgres) |
| btcpayserver/postgres | 13.4 | [✔️](https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Postgres/13.4/Postgres/13.4/linuxamd64.Dockerfile) | [✔️](https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Postgres/13.4/Postgres/13.4/linuxarm32v7.Dockerfile) | [✔️](https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Postgres/13.4/Postgres/13.4/linuxarm64v8.Dockerfile) | [Github](https://github.com/btcpayserver/dockerfile-deps) - [DockerHub](https://hub.docker.com/r/btcpayserver/postgres) |
| kamigawabul/docker-bitcoingold | 0.15.2 | [✔️](https://raw.githubusercontent.com/Vutov/docker-bitcoin/master/bitcoingold/0.15.2/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/Vutov/docker-bitcoin) - [DockerHub](https://hub.docker.com/r/kamigawabul/docker-bitcoingold) |
| kamigawabul/btglnd | latest | [✔️](https://raw.githubusercontent.com/vutov/lnd/master/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/vutov/lnd) - [DockerHub](https://hub.docker.com/r/kamigawabul/btglnd) |
| acinq/eclair | release-0.4.1 | [✔️](https://raw.githubusercontent.com/ACINQ/eclair/v0.4.1/Dockerfile) | ️❌ | ️❌ | [Github](https://github.com/ACINQ/eclair) - [DockerHub](https://hub.docker.com/r/acinq/eclair) |

View File

@@ -554,11 +554,11 @@ namespace DockerFileBuildHelper
dockerInfo.GitRef = $"f1a8498333ae3ab340b5b39fbac1d7e1dc0d628c";
break;
case "postgres":
dockerInfo.DockerFilePath = $"9.6/Dockerfile";
dockerInfo.DockerFilePathARM32v7 = $"9.6/Dockerfile";
dockerInfo.DockerFilePathARM64v8 = $"9.6/Dockerfile";
dockerInfo.GitLink = "https://github.com/docker-library/postgres";
dockerInfo.GitRef = $"b7cb3c6eacea93be2259381033be3cc435649369";
dockerInfo.DockerFilePath = $"Postgres/{NoRevision(image.Tag)}/linuxamd64.Dockerfile";
dockerInfo.DockerFilePathARM32v7 = $"Postgres/{NoRevision(image.Tag)}/linuxarm32v7.Dockerfile";
dockerInfo.DockerFilePathARM64v8 = $"Postgres/{NoRevision(image.Tag)}/linuxarm64v8.Dockerfile";
dockerInfo.GitLink = "https://github.com/btcpayserver/dockerfile-deps";
dockerInfo.GitRef = $"Postgres/{image.Tag}";
dockerInfo.SupportedByUs = true;
break;
case "traefik":

View File

@@ -1040,18 +1040,18 @@ cd - && cd ..
# Build postgres
# https://raw.githubusercontent.com/docker-library/postgres/b7cb3c6eacea93be2259381033be3cc435649369/9.6/Dockerfile
DOCKERFILE="9.6/Dockerfile"
# https://raw.githubusercontent.com/docker-library/postgres/b7cb3c6eacea93be2259381033be3cc435649369/9.6/Dockerfile
[[ "$(uname -m)" == "armv7l" ]] && DOCKERFILE="9.6/Dockerfile"
# https://raw.githubusercontent.com/docker-library/postgres/b7cb3c6eacea93be2259381033be3cc435649369/9.6/Dockerfile
[[ "$(uname -m)" == "aarch64" ]] && DOCKERFILE="9.6/Dockerfile"
echo "Building postgres:13.4"
git clone https://github.com/docker-library/postgres postgres
# https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Postgres/13.4/Postgres/13.4/linuxamd64.Dockerfile
DOCKERFILE="Postgres/13.4/linuxamd64.Dockerfile"
# https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Postgres/13.4/Postgres/13.4/linuxarm32v7.Dockerfile
[[ "$(uname -m)" == "armv7l" ]] && DOCKERFILE="Postgres/13.4/linuxarm32v7.Dockerfile"
# https://raw.githubusercontent.com/btcpayserver/dockerfile-deps/Postgres/13.4/Postgres/13.4/linuxarm64v8.Dockerfile
[[ "$(uname -m)" == "aarch64" ]] && DOCKERFILE="Postgres/13.4/linuxarm64v8.Dockerfile"
echo "Building btcpayserver/postgres:13.4"
git clone https://github.com/btcpayserver/dockerfile-deps postgres
cd postgres
git checkout b7cb3c6eacea93be2259381033be3cc435649369
git checkout Postgres/13.4
cd "$(dirname $DOCKERFILE)"
docker build -f "$DOCKERFILE" -t "postgres:13.4" .
docker build -f "$DOCKERFILE" -t "btcpayserver/postgres:13.4" .
cd - && cd ..

View File

@@ -3,14 +3,11 @@ version: "3"
services:
postgres:
restart: unless-stopped
image: postgres:13.4
entrypoint: ./migrate-docker-entrypoint.sh
command: postgres
image: btcpayserver/postgres:13.4
environment:
POSTGRES_HOST_AUTH_METHOD: trust
volumes:
- "postgres_datadir:/var/lib/postgresql/data"
- "./postgres/migrate-docker-entrypoint.sh:/migrate-docker-entrypoint.sh:ro"
volumes:
postgres_datadir: