feat: generate Debian (12) Bookworm images (#62)

Add Debian 12 images and the related ClusterImageCatalog
---------

Signed-off-by: Niccolò Fei <niccolo.fei@enterprisedb.com>
Signed-off-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
Signed-off-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
Co-authored-by: Jonathan Gonzalez V <jonathan.gonzalez@enterprisedb.com>
Co-authored-by: Francesco Canovai <francesco.canovai@enterprisedb.com>
This commit is contained in:
Niccolò Fei
2024-05-09 18:41:06 +02:00
committed by GitHub
parent 4b7c4b1835
commit baed8316c7
43 changed files with 3473 additions and 243 deletions

View File

@@ -19,150 +19,73 @@ set -Eeuo pipefail
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"
LIBDIR="$(pwd)/../lib"
source "$LIBDIR/repo_funcs.sh"
# Defaults
DISTRO=""
usage(){
echo "Fetch new updates of the CNPG container images."
echo "Usage: $(basename "$0") [options]"
echo "Options"
echo " -d, --distro the distro to update"
echo " -h, --help display this message end exit"
}
OPTS=$(getopt \
--long help,distro: \
-n "$(basename "$0")" \
-o hd: \
-- "$@")
eval set -- "$OPTS"
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-d|--distro)
DISTRO=$2
if ! [[ "$DISTRO" =~ (bullseye|bookworm) ]]; then
echo "The supported distributions are: bullseye, bookworm"
exit 1
fi
shift 2
;;
--)
shift
break
;;
*)
echo "Unrecognized parameter $1"
usage
exit 1
;;
esac
done
versions=("$@")
if [ ${#versions[@]} -eq 0 ]; then
for version in */; do
[[ $version = src/ ]] && continue
versions+=("$version")
done
fi
versions=("${versions[@]%/}")
# Get the last postgres base image tag and update time
fetch_postgres_image_version() {
local suite="$1";
local item="$2";
curl -SsL "https://registry.hub.docker.com/v2/repositories/library/postgres/tags/?name=bullseye&ordering=last_updated&page_size=20" | \
jq -c ".results[] | select( .name | match(\"^${suite}.[a-z0-9]+-bullseye\"))" | \
jq -r ".${item}" | \
head -n1
}
requirements=$(update_requirements)
# Get the latest Barman version
latest_barman_version=
_raw_get_latest_barman_version() {
curl -s https://pypi.org/pypi/barman/json | jq -r '.releases | keys[]' | sort -Vr | head -n1
}
get_latest_barman_version() {
if [ -z "$latest_barman_version" ]; then
latest_barman_version=$(_raw_get_latest_barman_version)
fi
echo "$latest_barman_version"
}
# record_version(versionFile, component, componentVersion)
# Parameters:
# versionFile: the file containing the version of each component
# component: the component to be updated
# componentVersion: the new component version to be set
record_version() {
local versionFile="$1"; shift
local component="$1"; shift
local componentVersion="$1"; shift
jq -S --arg component "${component}" \
--arg componentVersion "${componentVersion}" \
'.[$component] = $componentVersion' <"${versionFile}" >>"${versionFile}.new"
mv "${versionFile}.new" "${versionFile}"
}
generate_postgres() {
local version="$1"; shift
versionFile="${version}/.versions.json"
imageReleaseVersion=1
postgresImageVersion=$(fetch_postgres_image_version "${version}" "name")
if [ -z "$postgresImageVersion" ]; then
echo "Unable to retrieve latest postgres ${version} image version"
exit 1
fi
postgresImageLastUpdate=$(fetch_postgres_image_version "${version}" "last_updated")
if [ -z "$postgresImageLastUpdate" ]; then
echo "Unable to retrieve latest postgres ${version} image version last update time"
exit 1
fi
barmanVersion=$(get_latest_barman_version)
if [ -z "$barmanVersion" ]; then
echo "Unable to retrieve latest barman-cli-cloud version"
exit 1
fi
if [ -f "${versionFile}" ]; then
oldImageReleaseVersion=$(jq -r '.IMAGE_RELEASE_VERSION' "${versionFile}")
oldBarmanVersion=$(jq -r '.BARMAN_VERSION' "${versionFile}")
oldPostgresImageLastUpdate=$(jq -r '.POSTGRES_IMAGE_LAST_UPDATED' "${versionFile}")
oldPostgresImageVersion=$(jq -r '.POSTGRES_IMAGE_VERSION' "${versionFile}")
imageReleaseVersion=$oldImageReleaseVersion
else
imageReleaseVersion=1
echo "{}" > "${versionFile}"
record_version "${versionFile}" "IMAGE_RELEASE_VERSION" "${imageReleaseVersion}"
record_version "${versionFile}" "BARMAN_VERSION" "${barmanVersion}"
record_version "${versionFile}" "POSTGRES_IMAGE_LAST_UPDATED" "${postgresImageLastUpdate}"
record_version "${versionFile}" "POSTGRES_IMAGE_VERSION" "${postgresImageVersion}"
return
fi
newRelease="false"
# Detect if postgres image updated
if [ "$oldPostgresImageLastUpdate" != "$postgresImageLastUpdate" ]; then
echo "Debian Image changed from $oldPostgresImageLastUpdate to $postgresImageLastUpdate"
newRelease="true"
record_version "${versionFile}" "POSTGRES_IMAGE_LAST_UPDATED" "${postgresImageLastUpdate}"
fi
# Detect an update of Barman
if [ "$oldBarmanVersion" != "$barmanVersion" ]; then
echo "Barman changed from $oldBarmanVersion to $barmanVersion"
newRelease="true"
record_version "${versionFile}" "BARMAN_VERSION" "${barmanVersion}"
fi
if [ "$oldPostgresImageVersion" != "$postgresImageVersion" ]; then
echo "PostgreSQL base image changed from $oldPostgresImageVersion to $postgresImageVersion"
record_version "${versionFile}" "IMAGE_RELEASE_VERSION" 1
record_version "${versionFile}" "POSTGRES_IMAGE_VERSION" "${postgresImageVersion}"
imageReleaseVersion=1
elif [ "$newRelease" = "true" ]; then
imageReleaseVersion=$((oldImageReleaseVersion + 1))
record_version "${versionFile}" "IMAGE_RELEASE_VERSION" $imageReleaseVersion
fi
dockerTemplate="Dockerfile.template"
if [ "${version}" -gt '16' ]; then
dockerTemplate="Dockerfile-beta.template"
fi
cp -r src/* "$version/"
sed -e 's/%%POSTGRES_IMAGE_VERSION%%/'"$postgresImageVersion"'/g' \
-e 's/%%IMAGE_RELEASE_VERSION%%/'"$imageReleaseVersion"'/g' \
${dockerTemplate} \
> "$version/Dockerfile"
}
update_requirements() {
barmanVersion=$(get_latest_barman_version)
# If there's a new version we need to recreate the requirements files
echo "barman[cloud,azure,snappy,google] == $barmanVersion" > requirements.in
# This will take the requirements.in file and generate a file
# requirements.txt with the hashes for the required packages
pip-compile --generate-hashes 2> /dev/null
# Removes psycopg from the list of packages to install
sed -i '/psycopg/{:a;N;/barman/!ba};/via barman/d' requirements.txt
# Then the file needs to be moved into the src/root/ that will
# be added to every container later
mv requirements.txt src/
}
update_requirements
for version in "${versions[@]}"; do
generate_postgres "${version}"
done
case "$DISTRO" in
bullseye|bookworm)
for version in "${versions[@]}"; do
generate_postgres "${version}" "${DISTRO}" "${requirements}"
done
;;
*)
for version in "${versions[@]}"; do
generate_postgres "${version}" "bullseye" "${requirements}"
generate_postgres "${version}" "bookworm" "${requirements}"
done
;;
esac