Skip to content

Commit

Permalink
Build and test Debian image
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Jul 10, 2024
1 parent 6968989 commit e0588f8
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
matrix:
operating_system:
- alpine
- debian
pg_version:
- "9.5"
- "9.6"
Expand Down Expand Up @@ -78,6 +79,8 @@ jobs:
operating_system:
- flavor: "alpine"
version: "3.19"
- flavor: "debian"
version: "bookworm"
pg_target:
- "12"
- "13"
Expand Down
174 changes: 174 additions & 0 deletions Dockerfile.debian
Original file line number Diff line number Diff line change
@@ -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 icu-devtools icu-data libicu-dev linux-headers-$(uname -r) liblz4-dev locales tzdata zlib1g-dev libzstd-dev && \
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 icu-data 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"]
9 changes: 7 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0588f8

Please sign in to comment.