Skip to content

Commit 99052d6

Browse files
committed
ci: move the container build process to bake
Signed-off-by: Niccolò Fei <[email protected]>
1 parent d0f1118 commit 99052d6

File tree

3 files changed

+167
-45
lines changed

3 files changed

+167
-45
lines changed

Dockerfile

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,11 @@
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

195
ARG PG_REPO=https://git.postgresql.org/git/postgresql.git
206
ARG PG_BRANCH=master
217
ARG 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-
309
COPY 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

5532
ENV PG_MAJOR=$PG_MAJOR
5633
ENV 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/*
150149
USER 26

build-deps.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,45 @@
1+
autoconf
2+
automake
13
bison
4+
libjson-c-dev
25
build-essential
36
clang-16
7+
cmake
8+
docbook-xml
9+
docbook5-xml
410
flex
511
gettext
612
git
13+
libboost-all-dev
14+
libcunit1-dev
15+
libcurl4-gnutls-dev
716
libedit-dev
17+
libgdal-dev
18+
libgeos-dev
19+
libgmp-dev
820
libipc-run-perl
921
libkrb5-dev
1022
libldap-dev
1123
liblz4-dev
1224
libpam0g-dev
25+
libpcre3-dev
1326
libperl-dev
27+
libproj-dev
28+
libprotobuf-c-dev
1429
libreadline-dev
1530
libselinux1-dev
31+
libsfcgal-dev
32+
libsqlite3-dev
1633
libssl-dev
1734
libsystemd-dev
35+
libtiff-dev
36+
libtool
37+
libxml2-utils
1838
libxslt1-dev
1939
libzstd-dev
2040
llvm-16-dev
2141
pkg-config
42+
protobuf-c-compiler
2243
python3-dev
2344
systemtap-sdt-dev
2445
tcl-dev

docker-bake.hcl

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
variable "environment" {
2+
default = "testing"
3+
validation {
4+
condition = contains(["testing", "production"], environment)
5+
error_message = "environment must be either testing or production"
6+
}
7+
}
8+
9+
variable "registry" {
10+
default = "localhost:5000"
11+
}
12+
13+
variable "insecure" {
14+
default = "false"
15+
}
16+
17+
// Use the revision variable to identify the commit that generated the image
18+
variable "revision" {
19+
default = "1"
20+
}
21+
22+
fullname = ( environment == "testing") ? "${registry}/postgresql-trunk-testing" : "${registry}/postgresql-trunk"
23+
now = timestamp()
24+
title = "PostgreSQL Trunk Containers"
25+
description = "PostgreSQL Trunk Containers for CloudNativePG operator"
26+
authors = "The CloudNativePG Contributors"
27+
url = "https://github.com/cloudnative-pg/postgres-trunk-containers"
28+
29+
target "default" {
30+
matrix = {
31+
tgt = [
32+
"minimal",
33+
"standard",
34+
"postgis"
35+
]
36+
pgMajor = ["18"]
37+
base = ["debian:bookworm-slim"]
38+
}
39+
40+
platforms = [
41+
"linux/amd64"
42+
]
43+
44+
dockerfile = "Dockerfile"
45+
name = "postgresql-${pgMajor}-${tgt}-${distroVersion(base)}"
46+
tags = [
47+
"${fullname}:${pgMajor}-${tgt}-${distroVersion(base)}",
48+
"${fullname}:${pgMajor}-${formatdate("YYYYMMDDhhmm", now)}-${tgt}-${distroVersion(base)}"
49+
]
50+
context = "."
51+
target = "${tgt}"
52+
args = {
53+
PG_MAJOR = "${pgMajor}"
54+
BASE = "${base}"
55+
}
56+
57+
output = [
58+
"type=image,registry.insecure=${insecure}",
59+
]
60+
attest = [
61+
"type=provenance,mode=max",
62+
"type=sbom"
63+
]
64+
annotations = [
65+
"index,manifest:org.opencontainers.image.created=${now}",
66+
"index,manifest:org.opencontainers.image.url=${url}",
67+
"index,manifest:org.opencontainers.image.source=${url}",
68+
"index,manifest:org.opencontainers.image.version=${pgMajor}",
69+
"index,manifest:org.opencontainers.image.revision=${revision}",
70+
"index,manifest:org.opencontainers.image.vendor=${authors}",
71+
"index,manifest:org.opencontainers.image.title=CloudNativePG PostgreSQL ${pgMajor} ${tgt}",
72+
"index,manifest:org.opencontainers.image.description=A ${tgt} PostgreSQL ${pgMajor} container image",
73+
"index,manifest:org.opencontainers.image.documentation=${url}",
74+
"index,manifest:org.opencontainers.image.authors=${authors}",
75+
"index,manifest:org.opencontainers.image.licenses=Apache-2.0",
76+
"index,manifest:org.opencontainers.image.base.name=docker.io/library/${tag(base)}",
77+
]
78+
labels = {
79+
"org.opencontainers.image.created" = "${now}",
80+
"org.opencontainers.image.url" = "${url}",
81+
"org.opencontainers.image.source" = "${url}",
82+
"org.opencontainers.image.version" = "${pgMajor}",
83+
"org.opencontainers.image.revision" = "${revision}",
84+
"org.opencontainers.image.vendor" = "${authors}",
85+
"org.opencontainers.image.title" = "CloudNativePG PostgreSQL ${pgMajor} ${tgt}",
86+
"org.opencontainers.image.description" = "A ${tgt} PostgreSQL ${pgMajor} container image",
87+
"org.opencontainers.image.documentation" = "${url}",
88+
"org.opencontainers.image.authors" = "${authors}",
89+
"org.opencontainers.image.licenses" = "Apache-2.0"
90+
"org.opencontainers.image.base.name" = "docker.io/library/debian:${tag(base)}"
91+
}
92+
}
93+
94+
function tag {
95+
params = [ imageName ]
96+
result = index(split(":", imageName), 1)
97+
}
98+
99+
function distroVersion {
100+
params = [ imageName ]
101+
result = index(split("-", tag(imageName)), 0)
102+
}

0 commit comments

Comments
 (0)