diff --git a/.dockerignore b/.dockerignore index 9daeafb..486605b 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,4 @@ test + +Dockerfile.alpine +Dockerfile.debian diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 021c1d6..c660ba2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,7 @@ jobs: matrix: operating_system: - alpine + - debian pg_version: - "9.5" - "9.6" @@ -78,6 +79,8 @@ jobs: operating_system: - flavor: "alpine" version: "3.19" + - flavor: "debian" + version: "bookworm" pg_target: - "12" - "13" diff --git a/Dockerfile.debian b/Dockerfile.debian new file mode 100644 index 0000000..271ad53 --- /dev/null +++ b/Dockerfile.debian @@ -0,0 +1,174 @@ +ARG PGTARGET=16 + +### Things we need in all build containers +FROM debian:bookworm as base-build + +# The versions of PostgreSQL to use +ENV PG95=9.5.25 +ENV PG96=9.6.24 +ENV PG10=10.23 +ENV PG11=11.22 +ENV PG12=12.19 +ENV PG13=13.15 +ENV PG14=14.12 +ENV PG15=15.7 +ENV PG16=16.3 + +# Where we'll do all our compiling and similar +ENV BUILD_ROOT /buildroot + +# Make the directory for building, and set it as the default for the following Docker commands +RUN mkdir ${BUILD_ROOT} +WORKDIR ${BUILD_ROOT} + +# Install things needed for development +# We might want to install "alpine-sdk" instead of "build-base", if build-base +# doesn't have everything we need +RUN apt update && \ + apt upgrade && \ + apt install -y build-essential libicu-dev liblz4-dev locales tzdata zlib1g-dev libzstd-dev wget pkg-config && \ + apt clean + +### PostgreSQL 9.5 +FROM base-build as build-9.5 + +RUN wget https://ftp.postgresql.org/pub/source/v${PG95}/postgresql-${PG95}.tar.bz2 && \ + tar -xf postgresql-9.5*.tar.bz2 + +RUN cd postgresql-9.5.* && \ + ./configure --prefix=/usr/local-pg9.5 --with-openssl=no --without-readline --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg9.5/include + +### PostgreSQL 9.6 +FROM base-build as build-9.6 + +RUN wget https://ftp.postgresql.org/pub/source/v${PG96}/postgresql-${PG96}.tar.bz2 && \ + tar -xf postgresql-9.6*.tar.bz2 + +RUN cd postgresql-9.6.* && \ + ./configure --prefix=/usr/local-pg9.6 --with-openssl=no --without-readline --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg9.6/include + +### PostgreSQL 10 +FROM base-build as build-10 +RUN wget https://ftp.postgresql.org/pub/source/v${PG10}/postgresql-${PG10}.tar.bz2 && \ + tar -xf postgresql-10*.tar.bz2 + +RUN cd postgresql-10.* && \ + ./configure --prefix=/usr/local-pg10 --with-openssl=no --without-readline --with-icu --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg10/include + +### PostgreSQL 11 +FROM base-build as build-11 +RUN wget https://ftp.postgresql.org/pub/source/v${PG11}/postgresql-${PG11}.tar.bz2 && \ + tar -xf postgresql-11*.tar.bz2 + +RUN cd postgresql-11.* && \ + ./configure --prefix=/usr/local-pg11 --with-openssl=no --without-readline --with-icu --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg11/include + +### PostgreSQL 12 +FROM base-build as build-12 +RUN wget https://ftp.postgresql.org/pub/source/v${PG12}/postgresql-${PG12}.tar.bz2 && \ + tar -xf postgresql-12*.tar.bz2 + +RUN cd postgresql-12.* && \ + ./configure --prefix=/usr/local-pg12 --with-openssl=no --without-readline --with-icu --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg12/include + +### PostgreSQL 13 +FROM base-build as build-13 + +RUN wget https://ftp.postgresql.org/pub/source/v${PG13}/postgresql-${PG13}.tar.bz2 && \ + tar -xf postgresql-13*.tar.bz2 + +RUN cd postgresql-13.* && \ + ./configure --prefix=/usr/local-pg13 --with-openssl=no --without-readline --with-icu --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg13/include + +### PostgreSQL 14 +FROM base-build as build-14 + +RUN wget https://ftp.postgresql.org/pub/source/v${PG14}/postgresql-${PG14}.tar.bz2 && \ + tar -xf postgresql-14*.tar.bz2 + +RUN cd postgresql-14.* && \ + ./configure --prefix=/usr/local-pg14 --with-openssl=no --without-readline --with-icu --with-lz4 --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg14/include + +### PostgreSQL 15 +FROM base-build as build-15 + +RUN wget https://ftp.postgresql.org/pub/source/v${PG15}/postgresql-${PG15}.tar.bz2 && \ + tar -xf postgresql-15*.tar.bz2 + +RUN cd postgresql-15.* && \ + ./configure --prefix=/usr/local-pg15 --with-openssl=no --without-readline --with-icu --with-lz4 --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg15/include + +### PostgreSQL 16 +FROM base-build as build-16 + +RUN wget https://ftp.postgresql.org/pub/source/v${PG16}/postgresql-${PG16}.tar.gz && \ + tar -xf postgresql-16*.tar.gz + +RUN cd postgresql-16.* && \ + ./configure --prefix=/usr/local-pg16 --with-openssl=no --without-readline --with-icu --with-lz4 --with-system-tzdata=/usr/share/zoneinfo --enable-debug=no CFLAGS="-Os" && \ + make -j $(nproc) && \ + make install-world && \ + rm -rf /usr/local-pg16/include + +# Use the PostgreSQL Alpine image as our output image base +FROM postgres:${PGTARGET}-bookworm + +# We need to define this here, to make the above PGTARGET available after the FROM +ARG PGTARGET + +# Copy across our compiled files +COPY --from=build-9.5 /usr/local-pg9.5 /usr/local-pg9.5 +COPY --from=build-9.6 /usr/local-pg9.6 /usr/local-pg9.6 +COPY --from=build-10 /usr/local-pg10 /usr/local-pg10 +COPY --from=build-11 /usr/local-pg11 /usr/local-pg11 +COPY --from=build-12 /usr/local-pg12 /usr/local-pg12 +COPY --from=build-13 /usr/local-pg13 /usr/local-pg13 +COPY --from=build-14 /usr/local-pg14 /usr/local-pg14 +COPY --from=build-15 /usr/local-pg15 /usr/local-pg15 +COPY --from=build-16 /usr/local-pg16 /usr/local-pg16 + +# Remove any left over PG directory stubs. Doesn't help with image size, just with clarity on what's in the image. +RUN if [ "${PGTARGET}" -eq 12 ]; then rm -rf /usr/local-pg12 /usr/local-pg13 /usr/local-pg14 /usr/local-pg15 /usr/local-pg16; fi +RUN if [ "${PGTARGET}" -eq 13 ]; then rm -rf /usr/local-pg13 /usr/local-pg14 /usr/local-pg15 /usr/local-pg16; fi +RUN if [ "${PGTARGET}" -eq 14 ]; then rm -rf /usr/local-pg14 /usr/local-pg15 /usr/local-pg16; fi +RUN if [ "${PGTARGET}" -eq 15 ]; then rm -rf /usr/local-pg15 /usr/local-pg16; fi +RUN if [ "${PGTARGET}" -eq 16 ]; then rm -rf /usr/local-pg16; fi + +# Install locale +RUN apt update && \ + apt install -y icu-devtools locales tzdata && \ + apt clean + +# Pass the PG build target through to the running image +ENV PGTARGET=${PGTARGET} + +# 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"] + +CMD ["postgres"] \ No newline at end of file diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 17a0bf3..b7ff859 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -310,8 +310,13 @@ _main() { # setup data directories and permissions (when run as root) docker_create_db_directories if [ "$(id -u)" = '0' ]; then - # then restart script as postgres user - exec su-exec postgres "$BASH_SOURCE" "$@" + if [ -f /etc/alpine-release ]; then + # If running on Alpine, use su-exec + exec su-exec postgres "$BASH_SOURCE" "$@" + else + # Otherwise, use gosu + exec gosu postgres "$BASH_SOURCE" "$@" + fi fi # only run initialization on an empty data directory