From 23e1fa61812453024f340075c9f003387779f90e Mon Sep 17 00:00:00 2001 From: "Jonathan Gonzalez V." Date: Fri, 23 May 2025 15:14:49 +0200 Subject: [PATCH] chore: add support for PostgreSQL beta versions (#191) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now bake supports beta versions for the list and the building of the images Closes #190 Signed-off-by: Jonathan Gonzalez V Signed-off-by: Niccolò Fei Co-authored-by: Niccolò Fei --- Dockerfile | 11 ++++------- docker-bake.hcl | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5d1fd854..a2ef41f5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,13 @@ ARG BASE=debian:12.11-slim FROM $BASE AS minimal ARG PG_VERSION -ARG PG_MAJOR=${PG_VERSION%%.*} +ARG PG_MAJOR ENV PATH=$PATH:/usr/lib/postgresql/$PG_MAJOR/bin RUN apt-get update && \ apt-get install -y --no-install-recommends postgresql-common ca-certificates gnupg && \ - /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y && \ + /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh -y -c "${PG_MAJOR}" && \ apt-get install -y --no-install-recommends -o Dpkg::::="--force-confdef" -o Dpkg::::="--force-confold" postgresql-common && \ sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf && \ apt-get install -y --no-install-recommends \ @@ -21,13 +21,10 @@ USER 26 FROM minimal AS standard - +ARG EXTENSIONS USER root RUN apt-get update && \ - apt-get install -y --no-install-recommends locales-all \ - "postgresql-${PG_MAJOR}-pgaudit" \ - "postgresql-${PG_MAJOR}-pgvector" \ - "postgresql-${PG_MAJOR}-pg-failover-slots" && \ + apt-get install -y --no-install-recommends locales-all ${EXTENSIONS} && \ apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false && \ rm -rf /var/lib/apt/lists/* /var/cache/* /var/log/* diff --git a/docker-bake.hcl b/docker-bake.hcl index f6e6ea2d..5050c6ff 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -20,6 +20,12 @@ now = timestamp() authors = "The CloudNativePG Contributors" url = "https://github.com/cloudnative-pg/postgres-containers" +extensions = [ + "pgaudit", + "pgvector", + "pg-failover-slots" +] + target "default" { matrix = { tgt = [ @@ -31,7 +37,8 @@ target "default" { "14.18", "15.13", "16.9", - "17.5" + "17.5", + "18~beta1" ] base = [ // renovate: datasource=docker versioning=loose @@ -45,17 +52,19 @@ target "default" { "linux/arm64" ] dockerfile = "Dockerfile" - name = "postgresql-${index(split(".",pgVersion),0)}-${tgt}-${distroVersion(base)}" + name = "postgresql-${index(split(".",cleanVersion(pgVersion)),0)}-${tgt}-${distroVersion(base)}" tags = [ - "${fullname}:${index(split(".",pgVersion),0)}-${tgt}-${distroVersion(base)}", - "${fullname}:${pgVersion}-${tgt}-${distroVersion(base)}", - "${fullname}:${pgVersion}-${formatdate("YYYYMMDDhhmm", now)}-${tgt}-${distroVersion(base)}" + "${fullname}:${index(split(".",cleanVersion(pgVersion)),0)}-${tgt}-${distroVersion(base)}", + "${fullname}:${cleanVersion(pgVersion)}-${tgt}-${distroVersion(base)}", + "${fullname}:${cleanVersion(pgVersion)}-${formatdate("YYYYMMDDhhmm", now)}-${tgt}-${distroVersion(base)}" ] context = "." target = "${tgt}" args = { PG_VERSION = "${pgVersion}" + PG_MAJOR = "${getMajor(pgVersion)}" BASE = "${base}" + EXTENSIONS = "${getExtensionsString(pgVersion, extensions)}" } attest = [ "type=provenance,mode=max", @@ -107,3 +116,23 @@ function digest { params = [ imageNameWithSha ] result = index(split("@", imageNameWithSha), 1) } + +function cleanVersion { + params = [ version ] + result = replace(version, "~", "") +} + +function isBeta { + params = [ version ] + result = length(regexall("[0-9]+~beta.*", version)) > 0 +} + +function getMajor { + params = [ version ] + result = (isBeta(version) == true) ? index(split("~", version),0) : index(split(".", version),0) +} + +function getExtensionsString { + params = [ version, extensions ] + result = (isBeta(version) == true) ? "" : join(" ", formatlist("postgresql-%s-%s", getMajor(version), extensions)) +}