From 83f5e19367a6f57ce78b48bee82091a1a5528d44 Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 11:24:26 +0000 Subject: [PATCH 01/13] Bumping version to v6.0.0 Co-Authored-By: Claude Opus 5.5 --- VERSION | 2 +- VERSION_MAJOR | 2 +- VERSION_MINOR | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 28cbf7c..f4965a3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -5.0.0 \ No newline at end of file +6.0.0 \ No newline at end of file diff --git a/VERSION_MAJOR b/VERSION_MAJOR index 7813681..62f9457 100644 --- a/VERSION_MAJOR +++ b/VERSION_MAJOR @@ -1 +1 @@ -5 \ No newline at end of file +6 \ No newline at end of file diff --git a/VERSION_MINOR b/VERSION_MINOR index 6e63660..5049538 100644 --- a/VERSION_MINOR +++ b/VERSION_MINOR @@ -1 +1 @@ -5.0 \ No newline at end of file +6.0 \ No newline at end of file From 6e05ada6368d54c62a51f37485358a57fa62edef Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 11:24:26 +0000 Subject: [PATCH 02/13] Using new shared build process Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 36 +++++++++++ .github/workflows/dev.yml | 113 ---------------------------------- .github/workflows/publish.yml | 94 ---------------------------- README.md | 2 +- 4 files changed, 37 insertions(+), 208 deletions(-) create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/dev.yml delete mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..c5afbc8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +name: build + +on: + push: + branches: ['**'] + tags-ignore: ['**'] + release: + types: [published] + workflow_dispatch: + +jobs: + build: + uses: bfren/docker/.github/workflows/build.yml@shared-build + with: + image: postgresql + folders: | + 14 + 15 + 16 + 17 + 18 + platforms: | + linux/amd64 + linux/arm/v7 + linux/arm64 + tags: | + postgresql${FOLDER} + postgresql${FOLDER}-${VERSION_MAJOR} + postgresql${FOLDER}-${VERSION_MINOR} + postgresql${FOLDER}-${VERSION} + postgresql${POSTGRESQL_MINOR} + postgresql${POSTGRESQL_MINOR}-${VERSION} + secrets: + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml deleted file mode 100644 index 864d7b7..0000000 --- a/.github/workflows/dev.yml +++ /dev/null @@ -1,113 +0,0 @@ -name: dev - -on: - push: - branches: ['**'] - tags-ignore: ['**'] - workflow_dispatch: - -env: - TEST_TAG: postgresql:test - -jobs: - build: - strategy: - fail-fast: false - matrix: - postgresql: [ "14", "15", "16", "17", "18" ] - runs-on: ubuntu-latest - steps: - - - name: Checkout code - uses: actions/checkout@v7 - - - name: Get repository name - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV - shell: bash - - - name: Read image version - uses: bfren/read-file@v2 - with: - file: ./VERSION - id: version - - - name: Read PostgreSQL version - minor - uses: bfren/read-file@v2 - with: - file: ./${{ matrix.postgresql }}/overlay/tmp/POSTGRESQL_MINOR - id: postgresql_minor - - - name: Read image version - uses: bfren/read-file@v2 - with: - file: ./VERSION_MAJOR - id: version_major - - - name: Read image version - uses: bfren/read-file@v2 - with: - file: ./VERSION_MINOR - id: version_minor - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Login to DockerHub - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Login to Quay.io Container Registry - uses: docker/login-action@v4 - with: - registry: quay.io - username: ${{ github.repository_owner }} - password: ${{ secrets.QUAY_TOKEN }} - - - name: Build and export - id: docker_export - uses: docker/build-push-action@v7 - with: - file: ./${{ matrix.postgresql }}/Dockerfile - build-args: | - BF_IMAGE=${{ env.REPOSITORY_NAME }} - BF_VERSION=${{ steps.version.outputs.contents }} - load: true - tags: ${{ env.TEST_TAG }} - - - name: Run tests - id: docker_test - run: | - docker run --entrypoint /test ${{ env.TEST_TAG }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v7 - with: - context: . - file: ./${{ matrix.postgresql }}/Dockerfile - build-args: | - BF_IMAGE=${{ env.REPOSITORY_NAME }} - BF_VERSION=${{ steps.version.outputs.contents }} - push: ${{ startsWith(github.ref, 'refs/heads/') }} - platforms: linux/amd64,linux/arm/v7,linux/arm64 - tags: | - bfren/postgresql:postgresql${{ matrix.postgresql }}-dev - bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_major.outputs.contents }}-dev - bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_minor.outputs.contents }}-dev - bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version.outputs.contents }}-dev - bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }}-dev - bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }}-${{ steps.version.outputs.contents }}-dev - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-dev - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_major.outputs.contents }}-dev - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_minor.outputs.contents }}-dev - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version.outputs.contents }}-dev - quay.io/bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }}-dev - quay.io/bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }}-${{ steps.version.outputs.contents }}-dev - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index 186b818..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: publish - -on: - release: - types: [published] - workflow_dispatch: - -jobs: - publish: - strategy: - fail-fast: false - matrix: - postgresql: [ "14", "15", "16", "17", "18" ] - runs-on: ubuntu-latest - steps: - - - name: Checkout code - uses: actions/checkout@v7 - - - name: Get repository name - run: echo "REPOSITORY_NAME=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV - shell: bash - - - name: Read PostgreSQL version - minor - uses: bfren/read-file@v2 - with: - file: ./${{ matrix.postgresql }}/overlay/tmp/POSTGRESQL_MINOR - id: postgresql_minor - - - name: Read image version - uses: bfren/read-file@v2 - with: - file: ./VERSION_MAJOR - id: version_major - - - name: Read image version - uses: bfren/read-file@v2 - with: - file: ./VERSION_MINOR - id: version_minor - - - name: Read image version - uses: bfren/read-file@v2 - with: - file: ./VERSION - id: version - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Login to DockerHub - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Login to Quay.io Container Registry - uses: docker/login-action@v4 - with: - registry: quay.io - username: ${{ github.repository_owner }} - password: ${{ secrets.QUAY_TOKEN }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v7 - with: - context: . - file: ./${{ matrix.postgresql }}/Dockerfile - build-args: | - BF_IMAGE=${{ env.REPOSITORY_NAME }} - BF_PUBLISHING=1 - BF_VERSION=${{ steps.version.outputs.contents }} - push: true - platforms: linux/amd64,linux/arm/v7,linux/arm64 - tags: | - bfren/postgresql:postgresql${{ matrix.postgresql }} - bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_major.outputs.contents }} - bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_minor.outputs.contents }} - bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version.outputs.contents }} - bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }} - bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }}-${{ steps.version.outputs.contents }} - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }} - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_major.outputs.contents }} - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version_minor.outputs.contents }} - quay.io/bfren/postgresql:postgresql${{ matrix.postgresql }}-${{ steps.version.outputs.contents }} - quay.io/bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }} - quay.io/bfren/postgresql:postgresql${{ steps.postgresql_minor.outputs.contents }}-${{ steps.version.outputs.contents }} - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/README.md b/README.md index 77a0db7..b3d3aca 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PostgreSQL -![GitHub release (latest by date)](https://img.shields.io/github/v/release/bfren/docker-postgresql) ![Docker Pulls](https://img.shields.io/endpoint?url=https%3A%2F%2Fbfren.dev%2Fdocker%2Fpulls%2Fpostgresql) ![Docker Image Size](https://img.shields.io/endpoint?url=https%3A%2F%2Fbfren.dev%2Fdocker%2Fsize%2Fpostgresql) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bfren/docker-postgresql/dev.yml?branch=main) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/bfren/docker-postgresql) ![Docker Pulls](https://img.shields.io/endpoint?url=https%3A%2F%2Fbfren.dev%2Fdocker%2Fpulls%2Fpostgresql) ![Docker Image Size](https://img.shields.io/endpoint?url=https%3A%2F%2Fbfren.dev%2Fdocker%2Fsize%2Fpostgresql) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/bfren/docker-postgresql/build.yml?branch=main) [Docker Hub](https://hub.docker.com/r/bfren/postgresql) - [Quay.io](https://quay.io/repository/bfren/postgresql) - [bfren ecosystem](https://github.com/bfren/docker) From 870f9f3f4bd9fad0740f689835444a92ac0c40ff Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 11:24:26 +0000 Subject: [PATCH 03/13] Adding CHANGELOG to start with v6.0.0 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b618943 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,18 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [6.0.0] - Unreleased + +### Changed + +- **Breaking:** base image updated to `bfren/alpine-s6` 7.0.0 - see the + [Alpine + S6 changelog](https://github.com/bfren/docker-alpine-s6/blob/main/CHANGELOG.md). + `bf env set` must now run as root. +- Images are built and published by the shared `bfren/docker` build workflow (`build.yml`), replacing the separate + `dev.yml` and `publish.yml` workflows. + +[6.0.0]: https://github.com/bfren/docker-postgresql/compare/v5.0.0...v6.0.0 From a3e40969efd5587728b4167a5bb19a4829d401ff Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 11:24:26 +0000 Subject: [PATCH 04/13] Using latest base images Co-Authored-By: Claude Opus 5.5 --- 14/Dockerfile | 2 +- 15/Dockerfile | 2 +- 16/Dockerfile | 2 +- 17/Dockerfile | 2 +- 18/Dockerfile | 2 +- generate-dockerfiles.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/14/Dockerfile b/14/Dockerfile index 3558dc7..b1f4293 100644 --- a/14/Dockerfile +++ b/14/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.20-6.7.3 +FROM quay.io/bfren/alpine-s6:alpine3.20-7.0.0-dev LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/15/Dockerfile b/15/Dockerfile index 966dc02..5809c19 100644 --- a/15/Dockerfile +++ b/15/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.22-6.7.3 +FROM quay.io/bfren/alpine-s6:alpine3.22-7.0.0-dev LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/16/Dockerfile b/16/Dockerfile index 603396f..a330419 100644 --- a/16/Dockerfile +++ b/16/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.24-6.7.3 +FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0-dev LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/17/Dockerfile b/17/Dockerfile index cf60e79..d82e23c 100644 --- a/17/Dockerfile +++ b/17/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.24-6.7.3 +FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0-dev LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/18/Dockerfile b/18/Dockerfile index 95fa89c..2a7f5b5 100644 --- a/18/Dockerfile +++ b/18/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.24-6.7.3 +FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0-dev LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/generate-dockerfiles.sh b/generate-dockerfiles.sh index 3b37a28..a892503 100755 --- a/generate-dockerfiles.sh +++ b/generate-dockerfiles.sh @@ -4,7 +4,7 @@ set -euo pipefail docker pull bfren/alpine -BASE_VERSION="6.7.3" +BASE_VERSION="7.0.0-dev" echo "Base: ${BASE_VERSION}" POSTGRESQL_VERSIONS="14 15 16 17 18" From 709cff3e1d9d7a7aa1a63a05e9179ac35803a21c Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 11:24:27 +0000 Subject: [PATCH 05/13] Updating README tag examples and application versions Co-Authored-By: Claude Opus 5.5 --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b3d3aca..4224b48 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ It is built on [Alpine + S6](https://github.com/bfren/docker-alpine-s6), with Po ```yaml services: db: - image: quay.io/bfren/postgresql:postgresql18-4.3 + image: quay.io/bfren/postgresql:postgresql18-6.0 restart: unless-stopped environment: - BF_PG_APPLICATION=myapp @@ -58,11 +58,11 @@ Images are published to Docker Hub (`bfren/postgresql`) and Quay.io (`quay.io/bf | Tag | Example | Use when | | ----------------------- | ---------------------- | -------------------------------------------------- | | `postgresqlN` | `postgresql18` | You want the latest image for a PostgreSQL version | -| `postgresqlN-MAJOR` | `postgresql18-4` | You want updates, but not breaking changes | -| `postgresqlN-MINOR` | `postgresql18-4.3` | You want fixes only - **recommended** | -| `postgresqlN-VERSION` | `postgresql18-4.3.0` | You want to pin this image exactly | +| `postgresqlN-MAJOR` | `postgresql18-6` | You want updates, but not breaking changes | +| `postgresqlN-MINOR` | `postgresql18-6.0` | You want fixes only - **recommended** | +| `postgresqlN-VERSION` | `postgresql18-6.0.0` | You want to pin this image exactly | | `postgresqlN.M` | `postgresql18.6` | You want an exact PostgreSQL release | -| `postgresqlN.M-VERSION` | `postgresql18.6-4.3.0` | You want to pin both | +| `postgresqlN.M-VERSION` | `postgresql18.6-6.0.0` | You want to pin both | | PostgreSQL | Release | Alpine | Supported until | | ---------- | ------- | ------ | --------------- | From 836ea2213706477e2188b1e868c1517e1842d50c Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 11:25:21 +0000 Subject: [PATCH 06/13] auto-pr passes the branch name as a variable Co-Authored-By: Claude Opus 5.5 --- .github/workflows/auto-pr.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-pr.yml b/.github/workflows/auto-pr.yml index 61886a1..5646eac 100644 --- a/.github/workflows/auto-pr.yml +++ b/.github/workflows/auto-pr.yml @@ -13,6 +13,8 @@ jobs: uses: actions/checkout@v7 - name: Create Pull Request - run: gh pr create -B main --title "${{ github.ref_name }}" --body "Merging branch to create ${{ github.ref_name }}." + # pass the branch name as a variable - ${{ }} in run is pasted into the script, so a branch name could run code + run: gh pr create -B main --title "${BRANCH}" --body "Merging branch to create ${BRANCH}." env: + BRANCH: ${{ github.ref_name }} GITHUB_TOKEN: ${{ secrets.PAT }} From d4062e18f9300a3f60c786ed48c0fabf309bf80c Mon Sep 17 00:00:00 2001 From: bfren Date: Sat, 31 Oct 2026 12:30:27 +0000 Subject: [PATCH 07/13] Cancelling older builds when a newer push starts Co-Authored-By: Claude Opus 5.5 --- .github/workflows/build.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c5afbc8..4a4b09a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,6 +8,12 @@ on: types: [published] workflow_dispatch: +# one run per branch at a time - a newer push cancels the older run, so it cannot finish last and overwrite the +# newer images +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: build: uses: bfren/docker/.github/workflows/build.yml@shared-build From fb58f83c58a95cb175c8eb3511c002c90202a072 Mon Sep 17 00:00:00 2001 From: bfren Date: Sun, 1 Nov 2026 17:28:02 +0000 Subject: [PATCH 08/13] Switching from @shared-build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4a4b09a..4ebb53e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ concurrency: jobs: build: - uses: bfren/docker/.github/workflows/build.yml@shared-build + uses: bfren/docker/.github/workflows/build.yml@main with: image: postgresql folders: | From 5b98e34f7a27c074fe94b9243694c49600e13083 Mon Sep 17 00:00:00 2001 From: bfren Date: Sun, 1 Nov 2026 18:11:06 +0000 Subject: [PATCH 09/13] Pinning the Docker Hub README action to a commit Co-Authored-By: Claude Opus 5.5 --- .github/workflows/update-readme.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml index 31e6472..fdd3e44 100644 --- a/.github/workflows/update-readme.yml +++ b/.github/workflows/update-readme.yml @@ -16,15 +16,9 @@ jobs: - name: Checkout code uses: actions/checkout@v7 - - - name: Login to DockerHub - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Update repo description with README.md - uses: peter-evans/dockerhub-description@v5 + uses: peter-evans/dockerhub-description@1b9a80c056b620d92cedb9d9b5a223409c68ddfa # v5 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} From ed4ea774421fcfc52e471ed58c0481747268f4d7 Mon Sep 17 00:00:00 2001 From: bfren Date: Sun, 1 Nov 2026 18:11:09 +0000 Subject: [PATCH 10/13] Keeping the dump after a restore, streaming backups and refusing to export 'dump' Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 ++++++ README.md | 4 +-- overlay/etc/nu/scripts/bf-postgresql/db.nu | 5 ++-- overlay/etc/nu/scripts/bf-postgresql/dump.nu | 3 ++- .../etc/nu/scripts/bf-postgresql/export-db.nu | 3 +++ .../etc/nu/scripts/bf-postgresql/restore.nu | 27 ++++++++++++++++--- overlay/etc/nu/scripts/tests/files.nu | 21 +++++++++++++++ 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b618943..1dda458 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,4 +15,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Images are built and published by the shared `bfren/docker` build workflow (`build.yml`), replacing the separate `dev.yml` and `publish.yml` workflows. +### Fixed + +- A restore no longer deletes the dump file: it is renamed `dump.sql.restored`, and errors from `psql` (which carries + on after a failed statement) are saved to `dump.sql.log`, with a warning if any statement failed. +- Backups are written straight to the file instead of being held in memory first, so large databases no longer need + that much memory to back up. +- `pg-export dump` is refused - `/backup/dump.sql` would replace the whole cluster on the next start. + [6.0.0]: https://github.com/bfren/docker-postgresql/compare/v5.0.0...v6.0.0 diff --git a/README.md b/README.md index 4224b48..3fd3f0d 100644 --- a/README.md +++ b/README.md @@ -142,11 +142,11 @@ At a random minute every eight hours (00:xx, 08:xx and 16:xx in `BF_TZ`), `pg-du `pg-restore ` restores a backup folder's `dump.sql` (or `dump.sql.bz2`), e.g. `pg-restore 202610171608`. It **replaces the whole cluster**: PostgreSQL is stopped, `/data` is emptied, a new cluster is created from the dump, and PostgreSQL starts again. -You can also restore while the container is stopped: put `dump.sql` or `dump.sql.bz2` in the root of `/backup` and start the container. The dump file is deleted once it has been restored. +You can also restore while the container is stopped: put `dump.sql` or `dump.sql.bz2` in the root of `/backup` and start the container. The dump file is renamed `dump.sql.restored` once it has been restored, and `psql`'s errors are saved to `dump.sql.log` - check `docker logs` for a warning that some statements failed. ### Export and import -* `pg-export ` saves `/backup/.sql`. +* `pg-export ` saves `/backup/.sql` - except for a database called `dump`, because `/backup/dump.sql` is restored over the whole cluster on the next start. * `pg-import ` runs `/backup/.sql` in that database, creating it (owned by the application user) if it doesn't exist. Files from `pg-export` and the per-database backup files drop and recreate the tables they contain. To move a database between containers, `pg-export` in one, copy the file to the other's `/backup`, then `pg-import`. diff --git a/overlay/etc/nu/scripts/bf-postgresql/db.nu b/overlay/etc/nu/scripts/bf-postgresql/db.nu index 6b4b246..13397d2 100644 --- a/overlay/etc/nu/scripts/bf-postgresql/db.nu +++ b/overlay/etc/nu/scripts/bf-postgresql/db.nu @@ -18,8 +18,9 @@ export def dump [ # ensure the database exists if not (exists $name) { bf write error $"Database ($name) does not exist." db/dump } - # dump database and save to specified file - { ^pg pg_dump --clean --if-exists $name } | bf handle -s {|x| $x | save --force $file } db/dump + # dump database and save to specified file - streamed rather than through bf handle, which would hold the whole + # dump in memory (a failure still stops the script) + ^pg pg_dump --clean --if-exists $name o> $file } # Get a list of databases, ignoring system databases diff --git a/overlay/etc/nu/scripts/bf-postgresql/dump.nu b/overlay/etc/nu/scripts/bf-postgresql/dump.nu index e2eeca8..ae453da 100644 --- a/overlay/etc/nu/scripts/bf-postgresql/dump.nu +++ b/overlay/etc/nu/scripts/bf-postgresql/dump.nu @@ -12,7 +12,8 @@ export def main [] { bf write $"Dumping data cluster." dump let dump_file = $"($temp_dir)/(bf env PG_DUMP_BASENAME).sql" bf write debug $" .. to ($dump_file)" dump - { ^pg pg_dumpall --clean --if-exists } | bf handle -s {|x| $x | save --force $dump_file } dump + # streamed, not through bf handle which would hold the whole dump in memory - a failure still stops the script + ^pg pg_dumpall --clean --if-exists o> $dump_file # compress dump file if (bf env check PG_BACKUP_COMPRESS_FILES) { diff --git a/overlay/etc/nu/scripts/bf-postgresql/export-db.nu b/overlay/etc/nu/scripts/bf-postgresql/export-db.nu index dc6c53e..0ba744a 100644 --- a/overlay/etc/nu/scripts/bf-postgresql/export-db.nu +++ b/overlay/etc/nu/scripts/bf-postgresql/export-db.nu @@ -6,6 +6,9 @@ export def main [] { # capture database name let name = $in + # the dump file in the backup root is restored over the whole cluster on the next start + if $name == (bf env PG_DUMP_BASENAME) { bf write error $"A database called ($name) cannot be exported." export } + # create path to export file let export_file = $"(bf env PG_BACKUP)/($name).sql" diff --git a/overlay/etc/nu/scripts/bf-postgresql/restore.nu b/overlay/etc/nu/scripts/bf-postgresql/restore.nu index 5273596..012fa49 100644 --- a/overlay/etc/nu/scripts/bf-postgresql/restore.nu +++ b/overlay/etc/nu/scripts/bf-postgresql/restore.nu @@ -38,22 +38,41 @@ export def main [] { conf generate ctl start - # run restore + # run restore - psql carries on after an SQL error and still exits 0, so errors are saved to a log and counted bf write debug " .. restoring data" restore - { open --raw $dump_file.path | ^pg psql } | bf handle restore + let log = $"($dump_file.path).log" + { open --raw $dump_file.path | ^pg psql e> $log } | bf handle restore # stop the PostgreSQL service bf write debug " .. stopping PostgreSQL service" restore ctl stop - # unset restoring variable and delete dump file + # unset restoring variable and keep the dump file, renamed so it is not restored again bf env unset $restoring - rm --force $dump_file.path + mv --force $dump_file.path $"($dump_file.path).restored" + + # warn about errors, which may mean the data was only partly restored + let count = errors $log | length + if $count > 0 { + bf write notok $"($count) error\(s\) during restore - see ($log)." restore + return + } # if we get here there have been no errors bf write ok "Done." restore } +# Return the errors in a psql log, ignoring the ones every restore of a pg_dumpall dump causes: the dump drops and +# creates the postgres role, which already exists in the new cluster and cannot be dropped by itself +export def errors [ + log: string # Path to the psql stderr log +]: nothing -> list { + let expected = ['current user cannot be dropped' 'role "postgres" already exists'] + open --raw $log + | lines + | where {|x| ($x | str contains "ERROR:") and not ($expected | any {|e| $x | str contains $e }) } +} + # Get details of a dump file - returns a record with the following values, having decompressed the file if required # - exists: bool Whether or not a dump file exists # - path: string Absolute path to the dump file (only set if it exists) diff --git a/overlay/etc/nu/scripts/tests/files.nu b/overlay/etc/nu/scripts/tests/files.nu index 5b1aa56..adf2fd5 100644 --- a/overlay/etc/nu/scripts/tests/files.nu +++ b/overlay/etc/nu/scripts/tests/files.nu @@ -57,6 +57,18 @@ export def restore__fails_when_backup_has_no_dump [] { assert error { with-env $env_vars { bf-postgresql restore from "202601010000" } } } +export def restore_errors__ignores_errors_every_restore_causes [] { + let log = mktemp + [ + 'psql:/backup/dump.sql:14: ERROR: current user cannot be dropped' + 'psql:/backup/dump.sql:20: ERROR: role "postgres" already exists' + 'psql:/backup/dump.sql:95: ERROR: syntax error at or near "INSER"' + 'psql:/backup/dump.sql:96: NOTICE: table "x" does not exist, skipping' + ] | str join "\n" | save --force $log + + assert equal ['psql:/backup/dump.sql:95: ERROR: syntax error at or near "INSER"'] (bf-postgresql restore errors $log) +} + #====================================================================================================================== # export and import @@ -71,6 +83,15 @@ export def export__saves_database_to_backup_root [] { assert ((open --raw $"($env_vars.BF_PG_BACKUP)/app.sql") starts-with "-- dump") } +export def export__refuses_the_dump_file_name [] { + # /backup/dump.sql would replace the whole cluster on the next start + let stubs = helpers stubs + let env_vars = helpers pg_env + + assert error { helpers with_stubs $stubs { with-env $env_vars { "dump" | bf-postgresql export-db } } } + assert not ($"($env_vars.BF_PG_BACKUP)/dump.sql" | path exists) +} + export def import__runs_file_through_stdin [] { # the file is read by root and passed to psql, as the postgres user may not be able to read it let stubs = helpers stubs From 869eb704959bfd3154c30d8b5103a08b41263821 Mon Sep 17 00:00:00 2001 From: bfren Date: Tue, 3 Nov 2026 08:46:46 +0000 Subject: [PATCH 11/13] Keeping local work when pulling - pull.sh fast-forwards with git pull --ff-only instead of running git reset --hard, which threw away uncommitted changes - Helper scripts are stored as executable, so pull.sh no longer needs to chmod them Co-Authored-By: Claude Opus 5.5 --- pull.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) mode change 100644 => 100755 pull.sh diff --git a/pull.sh b/pull.sh old mode 100644 new mode 100755 index 95298cc..00d8436 --- a/pull.sh +++ b/pull.sh @@ -1,9 +1,8 @@ #!/bin/sh -git reset --hard && git pull +# only fast-forward, so local work is kept +git pull --ff-only if [ -n "${1-}" ] ; then - git checkout ${1} && git pull + git checkout ${1} && git pull --ff-only fi - -chmod +x pull.sh run.sh test.nu From ca37b5cd42143e729a0f09c94a833e77088c1891 Mon Sep 17 00:00:00 2001 From: bfren Date: Thu, 5 Nov 2026 08:30:07 +0000 Subject: [PATCH 12/13] Removing -dev tag to prep for release --- 14/Dockerfile | 2 +- 15/Dockerfile | 2 +- 16/Dockerfile | 2 +- 17/Dockerfile | 2 +- 18/Dockerfile | 2 +- generate-dockerfiles.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/14/Dockerfile b/14/Dockerfile index b1f4293..8429d03 100644 --- a/14/Dockerfile +++ b/14/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.20-7.0.0-dev +FROM quay.io/bfren/alpine-s6:alpine3.20-7.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/15/Dockerfile b/15/Dockerfile index 5809c19..f047b8b 100644 --- a/15/Dockerfile +++ b/15/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.22-7.0.0-dev +FROM quay.io/bfren/alpine-s6:alpine3.22-7.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/16/Dockerfile b/16/Dockerfile index a330419..b8837fb 100644 --- a/16/Dockerfile +++ b/16/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0-dev +FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/17/Dockerfile b/17/Dockerfile index d82e23c..e20bd16 100644 --- a/17/Dockerfile +++ b/17/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0-dev +FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/18/Dockerfile b/18/Dockerfile index 2a7f5b5..d5ed6e8 100644 --- a/18/Dockerfile +++ b/18/Dockerfile @@ -1,4 +1,4 @@ -FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0-dev +FROM quay.io/bfren/alpine-s6:alpine3.24-7.0.0 LABEL org.opencontainers.image.source="https://github.com/bfren/docker-postgresql" diff --git a/generate-dockerfiles.sh b/generate-dockerfiles.sh index a892503..a41b728 100755 --- a/generate-dockerfiles.sh +++ b/generate-dockerfiles.sh @@ -4,7 +4,7 @@ set -euo pipefail docker pull bfren/alpine -BASE_VERSION="7.0.0-dev" +BASE_VERSION="7.0.0" echo "Base: ${BASE_VERSION}" POSTGRESQL_VERSIONS="14 15 16 17 18" From 37d44eca87f9d98f0c7f2e331baa8a381d28efef Mon Sep 17 00:00:00 2001 From: bfren Date: Thu, 5 Nov 2026 10:03:06 +0000 Subject: [PATCH 13/13] Prepping CHANGELOG.md for release --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dda458..27c527c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [6.0.0] - Unreleased +## [6.0.0] - 2026-11-05 ### Changed