1- # vim:set ft=dockerfile:
2- #
3- # Copyright The CloudNativePG Contributors
4- #
5- # Licensed under the Apache License, Version 2.0 (the "License");
6- # you may not use this file except in compliance with the License.
7- # You may obtain a copy of the License at
8- #
9- # http://www.apache.org/licenses/LICENSE-2.0
10- #
11- # Unless required by applicable law or agreed to in writing, software
12- # distributed under the License is distributed on an "AS IS" BASIS,
13- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- # See the License for the specific language governing permissions and
15- # limitations under the License.
16- #
17- FROM debian:bookworm-slim
1+ ARG BASE=debian:bookworm-slim
2+
3+ FROM $BASE AS build-layer
184
195ARG PG_REPO=https://git.postgresql.org/git/postgresql.git
206ARG PG_BRANCH=master
217ARG PG_MAJOR=18
228
23- # Do not split the description, otherwise we will see a blank space in the labels
24- LABEL name="PostgreSQL Container Images" \
25- vendor="The CloudNativePG Contributors" \
26- version="$PG_MAJOR-devel" \
27- summary="PostgreSQL Container images." \
28- description="This Docker image contains a snapshot image of PostgreSQL compiled from Master and Barman Cloud based on Debian bookworm-slim."
29-
309COPY build-deps.txt /
3110
3211# Install runtime and build dependencies
@@ -38,19 +17,17 @@ RUN apt-get update && \
3817 locales-all \
3918 ssl-cert \
4019 libnss-wrapper \
20+ libgssapi-krb5-2 \
4121 libxml2 \
4222 libllvm16 \
4323 libxslt1.1 \
4424 xz-utils \
4525 zstd \
26+ postgresql-common \
4627 $(cat /build-deps.txt) && \
4728 rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/*
4829
49- # explicitly set user/group IDs
50- RUN groupadd -r postgres --gid=999 && \
51- useradd -r -g postgres --uid=26 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres && \
52- mkdir -p /var/lib/postgresql && \
53- chown -R postgres:postgres /var/lib/postgresql
30+ RUN usermod -u 26 postgres
5431
5532ENV PG_MAJOR=$PG_MAJOR
5633ENV PATH=/usr/lib/postgresql/$PG_MAJOR/bin:$PATH
@@ -112,6 +89,16 @@ RUN mkdir -p /usr/src/postgresql && \
11289 make install-world-bin && \
11390 rm -rf /usr/src/postgresql
11491
92+ # DoD 2.3 - remove setuid/setgid from any binary that not strictly requires it, and before doing that list them on the stdout
93+ RUN find / -not -path "/proc/*" -perm /6000 -type f -exec ls -ld {} \; -exec chmod a-s {} \; || true
94+
95+
96+ FROM build-layer AS minimal
97+ RUN apt-get purge -y --auto-remove $(cat /build-deps.txt) && \
98+ rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/*
99+ USER 26
100+
101+ FROM build-layer AS standard
115102# TODO: re-enable once https://github.com/pgaudit/pgaudit/issues/257 is fixed
116103# Build PgAudit
117104# See to https://github.com/pgaudit/pgaudit/blob/master/README.md#compile-and-install
@@ -121,30 +108,42 @@ RUN mkdir -p /usr/src/postgresql && \
121108# make install USE_PGXS=1 PG_CONFIG=/usr/lib/postgresql/$PG_MAJOR/bin/pg_config && \
122109# rm -rf /usr/src/pgaudit
123110
124- # Purge build dependencies
125- RUN apt-get purge -y --autoremove $(cat /build-deps.txt)
126-
127111# Install barman-cloud
128- RUN key='B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8' && \
129- export GNUPGHOME="$(mktemp -d)" && \
130- mkdir -p /usr/local/share/keyrings/ && \
131- gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" && \
132- gpg --batch --export --armor "$key" > /usr/local/share/keyrings/postgres.gpg.asc && \
133- gpgconf --kill all && \
134- rm -rf "$GNUPGHOME" && \
135- aptRepo="[ signed-by=/usr/local/share/keyrings/postgres.gpg.asc ] http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main $PG_MAJOR" && \
136- echo "deb $aptRepo" > /etc/apt/sources.list.d/pgdg.list && \
137- apt-get update && \
112+ RUN apt-get update && \
113+ /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && \
138114 apt-get install -y --no-install-recommends \
139115 python3-pip \
140116 python3-psycopg2 \
141117 python3-setuptools \
142118 && \
143119 pip3 install --break-system-packages --upgrade pip && \
144- pip3 install --break-system-packages barman[cloud,azure,google,snappy,zstandard,lz4]==3.12.1 boto3==1.35.99 && \
120+ pip3 install --break-system-packages barman[cloud,azure,google,snappy,zstandard,lz4]==3.13.2
121+
122+ RUN apt-get purge -y --auto-remove $(cat /build-deps.txt) && \
145123 rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/*
124+ USER 26
146125
147- # DoD 2.3 - remove setuid/setgid from any binary that not strictly requires it, and before doing that list them on the stdout
148- RUN find / -not -path "/proc/*" -perm /6000 -type f -exec ls -ld {} \; -exec chmod a-s {} \; || true
126+ FROM build-layer AS postgis
127+ ARG POSTGIS_REPO=https://github.com/postgis/postgis.git
128+ ARG POSTGIS_BRANCH=master
149129
130+ RUN apt-get update && \
131+ apt-get install -y --no-install-recommends \
132+ libproj25 \
133+ libpq5 \
134+ libgdal32 \
135+ libgeos-c1v5 \
136+ libsfcgal1 \
137+ && \
138+ mkdir -p /usr/src/postgis && \
139+ git clone -b "$POSTGIS_BRANCH" --single-branch "$POSTGIS_REPO" /usr/src/postgis && \
140+ cd /usr/src/postgis && \
141+ ./autogen.sh && \
142+ ./configure --with-pgconfig=/usr/lib/postgresql/$PG_MAJOR/bin/pg_config --with-sfcgal && \
143+ make -j$(nproc) && \
144+ make install && \
145+ rm -rf /usr/src/postgis
146+
147+ RUN apt-get purge -y --auto-remove $(cat /build-deps.txt) && \
148+ rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/*
150149USER 26
0 commit comments