Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Bitnami patch #66

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ RUN cd postgresql-16.* && \
# Use the PostgreSQL Alpine image as our output image base
FROM postgres:${PGTARGET}-alpine3.20

# Copy default configuration in case the original container does not provide it (Bitnami ...)
RUN mkdir -p /opt/pgautoupgrade && \
chmod 660 /opt/pgautoupgrade && \
chown 999:999 /opt/pgautoupgrade
COPY --chown=999 postgresql.conf pg_hba.conf /opt/pgautoupgrade/
Comment on lines +150 to +154
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as an alternative to the copy process, we could also invoke pg_setup_hba_conf() in the entrypoint.sh to generate a valid pg_hba.conf. postgresql.conf I am not sure ...


# We need to define this here, to make the above PGTARGET available after the FROM
ARG PGTARGET

Expand Down Expand Up @@ -179,12 +185,11 @@ RUN apk update && \
# Pass the PG build target through to the running image
ENV PGTARGET=${PGTARGET}

# Copy across the post-upgrade shell script
COPY pgautoupgrade-postupgrade.sh pgautoupgrade-healthcheck.sh /usr/local/bin/
# Copy across all our shell scripts
COPY pgautoupgrade-postupgrade.sh pgautoupgrade-healthcheck.sh postgres-docker-entrypoint.sh docker-entrypoint.sh /usr/local/bin/

# Set up the script run by the container when it starts
WORKDIR /var/lib/postgresql
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

HEALTHCHECK CMD /usr/local/bin/pgautoupgrade-healthcheck.sh
Expand Down
11 changes: 8 additions & 3 deletions Dockerfile.bookworm
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ RUN cd postgresql-16.* && \
# Use the PostgreSQL Bookworm image as our output image base
FROM postgres:${PGTARGET}-bookworm

# Copy default configuration in case the original container does not provide it (Bitnami ...)
RUN mkdir -p /opt/pgautoupgrade && \
chmod 660 /opt/pgautoupgrade && \
chown 999:999 /opt/pgautoupgrade
COPY --chown=999 postgresql.conf pg_hba.conf /opt/pgautoupgrade/

# We need to define this here, to make the above PGTARGET available after the FROM
ARG PGTARGET

Expand Down Expand Up @@ -174,12 +180,11 @@ RUN apt update && \
# Pass the PG build target through to the running image
ENV PGTARGET=${PGTARGET}

# Copy across the post-upgrade shell script
COPY pgautoupgrade-postupgrade.sh pgautoupgrade-healthcheck.sh /usr/local/bin/
# Copy across all our shell scripts
COPY pgautoupgrade-postupgrade.sh pgautoupgrade-healthcheck.sh postgres-docker-entrypoint.sh docker-entrypoint.sh /usr/local/bin/

# Set up the script run by the container when it starts
WORKDIR /var/lib/postgresql
COPY docker-entrypoint.sh /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]

HEALTHCHECK CMD /usr/local/bin/pgautoupgrade-healthcheck.sh
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ $ docker run --name pgauto -it \
<NAME_OF_THE_PGAUTOUPGRADE_IMAGE>
```

### Upgrading from a Bitnami container

If you used the Postgres image by Bitnami, we have made a couple of adjustments to make this upgrade work as well.

The Bitnami containers do not persist the `postgresql.conf` and `pg_hba.conf` file in the Postgres data directory. If we detect that these files are missing, we will copy a default version of these files into the data directory. If you request the "one shot" mode, these files will be removed again at the end of the upgrade process.

The official Postgres image, and therefore ours as well, use `999` as ID for the postgres user inside the container. Bitnami uses 1001. During the upgrade process, we make a copy of the data, which will be assigned to ID `999`. If you request the "one shot" mode, the original file permissions will be restored once the upgrade is completed.

Be aware that we use the environment variables from the official Postgres image. Ensure you set `PGDATA` to the Bitnami folder (by default `/bitnami/postgresql`) and `POSTGRES_PASSWORD` to the password of your Postgres user.

The container has to run as `root` if using `one shot` mode, otherwise we are unable to restore the existing file permissions of your Postgres data directory. You can run the container as user `999`, but then you will have to manually apply the file permissions to your Postgres data directory.

> [!WARNING]
> As of writing this paragraph (14th of November, 2024), we only tested upgrading from Bitnami Postgres v13, v14, v15, v16 to v17. For these versions, we used the latest available container version. Bitnami's script and directory structure could change over time. If you note any issues upgrading from other versions, please provide the exact SHA of the image so we can try to replicate the issue.

# For Developers

## Building the image
Expand Down
Loading