mirror of
https://git.koehn.com/docker/postgres-wal-g.git
synced 2026-11-25 17:43:20 -06:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
653ab7a387 | ||
|
|
d6f4953452 | ||
|
|
05c907dcee | ||
|
|
a8212acfb5 | ||
|
|
14d15c287e | ||
|
|
fb913a8062 | ||
|
|
52888bd104 | ||
|
|
a437ca53f4 | ||
|
|
8669c7e663 | ||
|
|
fc63329212 | ||
|
|
9ca1e4b2c0 | ||
|
|
e33df13659 | ||
|
|
42be7c5361 | ||
|
|
caa0e988b1 | ||
|
|
0283464236 | ||
|
|
599b4a7394 | ||
|
|
181d81d8b6 | ||
|
|
fe1d076b54 | ||
|
|
d644e427bf | ||
|
|
2843231ba3 | ||
|
|
d38cf5c191 | ||
|
|
aab6a0cbc3 | ||
|
|
3f5f137aac | ||
|
|
f1b9fe6c8f | ||
|
|
63777d0241 | ||
|
|
ffe01b37ae | ||
|
|
6ccf13f61e | ||
|
|
06627b7c94 | ||
|
|
47a9a80143 | ||
|
|
59d62b6071 | ||
|
|
63e54dbefb | ||
|
|
353e9afdca | ||
|
|
25c88d9aee | ||
|
|
9210fd7661 | ||
|
|
61ff6dd3ea | ||
|
|
2509a90e5e | ||
|
|
e21c44f8cc | ||
|
|
97d2c06256 | ||
|
|
9330274a80 | ||
|
|
9e3a846dc1 | ||
|
|
ff60201d72 | ||
|
|
17c6ecb0d7 | ||
|
|
f888c65103 | ||
|
|
2dbb67d57d | ||
|
|
4821a6be85 | ||
|
|
b4004f97e1 | ||
|
|
d21915e04f | ||
|
|
b1025bf7be | ||
|
|
f49433d3ee | ||
|
|
53618b8e55 | ||
|
|
179daa3d14 | ||
|
|
7fe34cd27c | ||
|
|
7b1cc24f2e | ||
|
|
66d4b429cf | ||
|
|
8d201da1a2 | ||
|
|
226ba8b2d0 | ||
|
|
93013a5b39 | ||
|
|
20b012a6a0 | ||
|
|
83fa1e24a6 | ||
|
|
36f146a58f | ||
|
|
caf5c50aa6 | ||
|
|
c0dabcc230 | ||
|
|
192afe1453 | ||
|
|
69f99303d4 | ||
|
|
ef80955920 | ||
|
|
2ae1d24f9a | ||
|
|
2b8df13fda | ||
|
|
c1346e5f41 | ||
|
|
2f98080099 | ||
|
|
acadcd0db6 | ||
|
|
0670df99dc | ||
|
|
9af7b9169d | ||
|
|
f2fa1d42d6 | ||
|
|
4666db46fc | ||
|
|
6565723c06 | ||
|
|
a4ca8d4b45 | ||
|
|
25642d5ed8 | ||
|
|
ac557f48c2 | ||
|
|
9fdba2423e | ||
|
|
3adadf55b3 | ||
|
|
5b3cd141cb | ||
|
|
2f6dc3a509 | ||
|
|
21c53dc4dd | ||
|
|
f2ef1c9d00 | ||
|
|
4b02d05230 | ||
|
|
2d1dea3953 | ||
|
|
7936f2a660 | ||
|
|
f884fca8d3 | ||
|
|
808d390383 | ||
|
|
888a8e06bf | ||
|
|
8e6481be9b | ||
|
|
bd622797b1 | ||
|
|
d18b5088ad | ||
|
|
c030b76a4c | ||
|
|
ed3f8308bc | ||
|
|
e5067b4257 | ||
|
|
e34430fd7e | ||
|
|
67f8f0cb65 | ||
|
|
a7020c5d4e | ||
|
|
a8028d9962 | ||
|
|
99ef19d076 | ||
|
|
a4118b3a0f | ||
|
|
0b977ac06b | ||
|
|
0043e3f3a4 |
No files matched your search
@@ -0,0 +1,45 @@
|
|||||||
|
name: ci
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Get Postgres and WAL-G versions
|
||||||
|
env:
|
||||||
|
TAG: ${{ gitea.ref_name }}
|
||||||
|
id: versions
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=postgres::${TAG:0:4}"
|
||||||
|
echo "::set-output name=walg::${TAG:5:6}"
|
||||||
|
|
||||||
|
- name: Install Docker
|
||||||
|
run: curl -fsSL https://get.docker.com | sh
|
||||||
|
|
||||||
|
- name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Hub
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.koehn.com
|
||||||
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||||
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
needs: [versions, ssh]
|
||||||
|
with:
|
||||||
|
build-args: |
|
||||||
|
BASE=${{ steps.versions.outputs.postgres }}
|
||||||
|
WAL_G=${{ steps.versions.outputs.walg }}
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64,linux/arm64
|
||||||
|
tags: git.koehn.com/docker/postgres-wal-g:${{ gitea.ref_name }}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
stages:
|
|
||||||
- build
|
|
||||||
|
|
||||||
build:
|
|
||||||
stage: build
|
|
||||||
image:
|
|
||||||
name: gcr.io/kaniko-project/executor:v1.5.2-debug
|
|
||||||
entrypoint: [""]
|
|
||||||
script:
|
|
||||||
- |
|
|
||||||
cat > /kaniko/.docker/config.json <<EOF
|
|
||||||
{
|
|
||||||
"auths": {
|
|
||||||
"https://index.docker.io/v1/": {
|
|
||||||
"auth":"${DOCKER_AUTH}"
|
|
||||||
},
|
|
||||||
"${CI_REGISTRY}": {
|
|
||||||
"username": "${CI_REGISTRY_USER}",
|
|
||||||
"password": "${CI_REGISTRY_PASSWORD}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination koehn/postgres-wal-g:13.4-$CI_COMMIT_TAG --build-arg BASE=13.4 --build-arg WALG_RELEASE=$(echo $CI_COMMIT_TAG | awk -F '-' '{print $1}')
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
|
|
||||||
+6
-5
@@ -1,13 +1,14 @@
|
|||||||
ARG BASE
|
ARG BASE=latest
|
||||||
|
|
||||||
FROM golang:1.15 as build
|
FROM golang:1-bookworm AS build
|
||||||
|
|
||||||
ARG WALG_RELEASE=v1.0
|
ARG WALG_RELEASE=master
|
||||||
|
|
||||||
RUN apt-get update -qq && apt-get install -qqy --no-install-recommends --no-install-suggests cmake liblzo2-dev libsodium23 && \
|
RUN apt-get update && apt-get install -qqy --no-install-recommends --no-install-suggests cmake gnutls-bin liblzo2-dev libsodium23 libsodium-dev && \
|
||||||
cd /go/src/ && \
|
cd /go/src/ && \
|
||||||
git clone -b $WALG_RELEASE --recurse-submodules https://github.com/wal-g/wal-g.git && \
|
git clone -b $WALG_RELEASE --recurse-submodules https://github.com/wal-g/wal-g.git && \
|
||||||
cd wal-g && \
|
cd wal-g && \
|
||||||
|
GOBIN=/go/bin go mod tidy && \
|
||||||
GOBIN=/go/bin USE_LIBSODIUM=1 USE_LZO=1 make install_and_build_pg
|
GOBIN=/go/bin USE_LIBSODIUM=1 USE_LZO=1 make install_and_build_pg
|
||||||
|
|
||||||
|
|
||||||
@@ -15,7 +16,7 @@ FROM postgres:$BASE
|
|||||||
|
|
||||||
|
|
||||||
RUN export DEBIAN_FRONTEND=noninteractive && \
|
RUN export DEBIAN_FRONTEND=noninteractive && \
|
||||||
apt-get update -qq && \
|
apt-get update && \
|
||||||
apt-get install -qqy curl ca-certificates libsodium23 vim
|
apt-get install -qqy curl ca-certificates libsodium23 vim
|
||||||
|
|
||||||
COPY --from=build /go/src/wal-g/main/pg/wal-g /usr/local/bin/wal-g
|
COPY --from=build /go/src/wal-g/main/pg/wal-g /usr/local/bin/wal-g
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
FROM koehn/postgres-wal-g:13.3-v1.0-2
|
|
||||||
|
|
||||||
RUN apt-get update -qq && apt-get install -qqy --no-install-recommends postgis postgresql-13-postgis-3
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,48 +1,55 @@
|
|||||||
# Postgres WAL-G
|
# Postgres WAL-G
|
||||||
|
|
||||||
This image extends the stock [Postgres Image](https://hub.docker.com/_/postgres/)
|
This image extends the stock [Postgres Image](https://hub.docker.com/_/postgres/)
|
||||||
and adds [WAL-G](https://github.com/wal-g/wal-g) support, along with some
|
and adds [WAL-G](https://github.com/wal-g/wal-g) support, along with some
|
||||||
helpful scripts. It allows you to simply and easily create continuous
|
helpful scripts. It allows you to simply and easily create continuous, encrypted
|
||||||
archives of Postgres databases in S3-compatible storage.
|
archives of Postgres databases in S3-compatible storage.
|
||||||
|
|
||||||
## Environment
|
## Environment
|
||||||
To use the image, you'll need to configure a bucket on your favorite S3-
|
To use the image, you'll need to configure a bucket on your favorite S3-
|
||||||
compatible provider, and set a few environment variables:
|
compatible provider, and set a few environment variables:
|
||||||
|
|
||||||
* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` that can read/write files
|
* `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` that can read/write files
|
||||||
to your bucket
|
to your bucket
|
||||||
* `AWS_ENDPOINT` (et al) to tell WAL-G where to archive (see
|
* `AWS_ENDPOINT` (et al) to tell WAL-G where to archive (see
|
||||||
[WAL-G documentation](https://github.com/wal-g/wal-g) for details)
|
[WAL-G documentation](https://github.com/wal-g/wal-g/blob/master/docs/PostgreSQL.md) for details)
|
||||||
* `WALG_S3_PREFIX` to tell WAL-G which bucket and prefix you'd like to use
|
* `WALG_S3_PREFIX` to tell WAL-G which bucket and prefix you'd like to use
|
||||||
|
* `WALG_LIBSODIUM_KEY` to encrypt the files stored in S3
|
||||||
## Configuration
|
|
||||||
In your `/varlib/postgresql/data/pgsql/postgresql.conf` file, set your [archive
|
## Configuration
|
||||||
settings](https://www.postgresql.org/docs/9.1/continuous-archiving.html).
|
In your `/var/lib/postgresql/data/pgsql/postgresql.conf` file, set your [archive
|
||||||
Importantly, you should set `archive_mode = on` and
|
settings](https://www.postgresql.org/docs/current/continuous-archiving.html).
|
||||||
`archive_command = 'wal-g wal-push %p'`. This will
|
Importantly, you should set `archive_mode = on` and
|
||||||
tell Postgres to have WAL-G send WAL files to S3.
|
`archive_command = 'wal-g wal-push %p'`. This will
|
||||||
|
tell Postgres to have WAL-G send WAL files to S3.
|
||||||
## Full Backups
|
|
||||||
To run a full backup, simply run `/wal-g/backup.sh`.
|
## Full Backups
|
||||||
|
To run a full backup, simply run `/wal-g/backup.sh`.
|
||||||
## Continuous Backups
|
|
||||||
These will happen automatically once you've started Postgres with your edited
|
## Continuous Backups
|
||||||
`postgresql.conf` file (see
|
These will happen automatically once you've started Postgres with your edited
|
||||||
[Configuration](https://gitlab.koehn.com/docker/postgres-wal-g#configuration), above).
|
`postgresql.conf` file (see
|
||||||
|
[Configuration](#configuration), above).
|
||||||
## Recovery
|
|
||||||
Testing recovery is simple: run a new Docker container with the correct
|
## Recovery
|
||||||
environment variables set and run `/wal-g/recover.sh`. It will:
|
Testing recovery is simple: run a new Docker container with the correct
|
||||||
1. Recover from the most recent full backup
|
environment variables set and run `/wal-g/recover.sh`. It will:
|
||||||
2. Configure Postgres to not accept incoming connections or perform streaming
|
1. Recover from the most recent full backup
|
||||||
backups until the recovery is complete (important for testing!)
|
2. Configure Postgres to not accept incoming connections or perform streaming
|
||||||
3. Configure Postgres to apply all the WAL files
|
backups until the recovery is complete (important for testing!)
|
||||||
4. Shut down Postgres, re-enable incoming connections and streaming backups
|
3. Configure Postgres to apply all the WAL files
|
||||||
|
4. Shut down Postgres, re-enable incoming connections and streaming backups
|
||||||
At this point you should have high confidence that the recovery was successful.
|
|
||||||
If you start your recovered backup, be sure to turn `archive_mode = off` to avoid
|
At this point you should have high confidence that the recovery was successful.
|
||||||
pushing additional WAL files to S3!
|
If you start your recovered backup, be sure to turn `archive_mode = off` to avoid
|
||||||
|
pushing additional WAL files to S3!
|
||||||
## Postgres Versions
|
|
||||||
Currently I build for Postgres 13, but you can build for whatever version you'd like. Be advised that 9.6 is the
|
## Postgres Versions
|
||||||
earliest version that WAL-G supports.
|
Currently I build for Postgres 16, but you can build for whatever version that wal-g supports.
|
||||||
|
|
||||||
|
## Kubernetes Deployments and Justfile
|
||||||
|
For an example of how to use this in Kubernetes (I happen to use k3s), you can check
|
||||||
|
out my deployment of this image [here](https://git.koehn.com/k3s-home/postgres).
|
||||||
|
|
||||||
|
That link also contains a `justfile` that has some useful recipes for creating
|
||||||
|
database, creating backups, testing backups, verifying backups, etc.
|
||||||
@@ -2,18 +2,18 @@
|
|||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
REV=$1
|
# e.g., 14.3
|
||||||
|
PG_VERSION=$1
|
||||||
|
|
||||||
|
#e.g., v2.0.1
|
||||||
|
WALG_VERSION=$2
|
||||||
IMAGE_NAME=koehn/postgres-wal-g
|
IMAGE_NAME=koehn/postgres-wal-g
|
||||||
|
|
||||||
build_image() {
|
build_image() {
|
||||||
BASE=$1
|
BASE=$1
|
||||||
IMAGE=$IMAGE_NAME:$BASE-$REV
|
IMAGE=$IMAGE_NAME:$BASE-$WALG_VERSION
|
||||||
|
docker buildx build -t $IMAGE --push . --build-arg BASE=$PG_VERSION --build-arg WALG_RELEASE=$WALG_VERSION --ulimit memlock=16384:16384 --platform linux/amd64,linux/arm64 --sbom=true --provenance=true
|
||||||
docker build --pull -t "$IMAGE" --build-arg BASE=$BASE .
|
|
||||||
docker push $IMAGE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build_image "11.1" "$REV"
|
build_image "$PG_VERSION" "$WALG_VERSION"
|
||||||
build_image "9.6"
|
|
||||||
|
|
||||||
wait
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||||
|
}
|
||||||
+22
-4
@@ -9,17 +9,29 @@
|
|||||||
# * 4. Disabling archive mode so as not to corrupt S3 backups
|
# * 4. Disabling archive mode so as not to corrupt S3 backups
|
||||||
# * Starts postgres
|
# * Starts postgres
|
||||||
#
|
#
|
||||||
# When recovery is done, hit ^C and start database using `/docker-entrypoint.sh postgres` and you should be able to connect to the database and verify backups are OK.
|
|
||||||
# If you get an error message, DON'T PANIC! Just read the message and do what it tells you to do.
|
# If you get an error message, DON'T PANIC! Just read the message and do what it tells you to do.
|
||||||
|
|
||||||
if [ $(id -u) == "0" ] ; then
|
[ -z ${AWS_ACCESS_KEY_ID+x} ] && VARS="$VARS AWS_ACCESS_KEY_ID"
|
||||||
echo "this command must be run as the postgres user."
|
[ -z ${AWS_SECRET_ACCESS_KEY+x} ] && VARS="$VARS AWS_SECRET_ACCESS_KEY"
|
||||||
|
[ -z ${AWS_ENDPOINT+x} ] && VARS="$VARS AWS_ENDPOINT"
|
||||||
|
[ -z ${AWS_REGION+x} ] && VARS="$VARS AWS_REGION"
|
||||||
|
[ -z ${WALG_S3_PREFIX+x} ] && VARS="$VARS WALG_S3_PREFIX"
|
||||||
|
[ -z ${WALG_LIBSODIUM_KEY+x} ] && VARS="$VARS WALG_LIBSODIUM_KEY"
|
||||||
|
|
||||||
|
if [ ! -z "$VARS" ] ; then
|
||||||
|
echo "The following enviornment variables must be set:$VARS"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -e
|
if [ $(id -u) == "0" ] ; then
|
||||||
|
echo "this command must be run as the postgres user (\`su postgres\`)."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
if [ -z ${PGDATA+x} ]; then
|
if [ -z ${PGDATA+x} ]; then
|
||||||
|
echo "Setting PGDATA to /var/lib/postgresql/data/pgsql"
|
||||||
export PGDATA=/var/lib/postgresql/data/pgsql
|
export PGDATA=/var/lib/postgresql/data/pgsql
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -37,3 +49,9 @@ sed -i -e 's/^archive_mode = on/archive_mode = off/' $PGDATA/postgresql.conf
|
|||||||
PG_VERSION=$(ls /usr/lib/postgresql/)
|
PG_VERSION=$(ls /usr/lib/postgresql/)
|
||||||
|
|
||||||
/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl start -D $PGDATA
|
/usr/lib/postgresql/$PG_VERSION/bin/pg_ctl start -D $PGDATA
|
||||||
|
|
||||||
|
echo "Recovery complete. Press <return> to continue."
|
||||||
|
echo "If this is a production recovery, simply restart the container."
|
||||||
|
echo ""
|
||||||
|
echo "To test the database, disable \`archive_mode\` in $PGDATA/postgresql.conf or you risk "
|
||||||
|
echo "corrupting backups of the production instance. Then run \`postgres start\` to start the instance in test mode."
|
||||||
Reference in new issue
Block a user