From c2db2e12c80e8ebc7544caa781d1ce8e7a4a17ad Mon Sep 17 00:00:00 2001 From: I539231 Date: Wed, 22 Nov 2023 10:46:01 +0100 Subject: [PATCH 1/3] *feat: Make it possible to define the used PostgreSQL version *feat: Adjust the docs and the release process --- README.md | 1 + ci/pipeline.yml | 20 ++++++++++- ci/tasks/bump-postgres-packages/task.sh | 11 ++---- ci/tasks/bump-yq-packages/task.sh | 34 +++++++++++++++++++ ci/tasks/bump-yq-packages/task.yml | 17 ++++++++++ ci/tasks/create-final-release/task.sh | 8 +++-- ci/tasks/run-acceptance-tests/task.sh | 10 +++++- jobs/bbr-postgres-db/spec | 1 + jobs/bbr-postgres-db/templates/config.sh.erb | 5 +-- jobs/postgres/spec | 5 +++ jobs/postgres/templates/pgconfig.sh.erb | 6 ++-- .../templates/used_postgresql_versions.yml | 11 ++++++ packages/yq-4/packaging | 17 ++++++++++ packages/yq-4/spec | 4 +++ 14 files changed, 133 insertions(+), 17 deletions(-) create mode 100755 ci/tasks/bump-yq-packages/task.sh create mode 100644 ci/tasks/bump-yq-packages/task.yml create mode 100644 jobs/postgres/templates/used_postgresql_versions.yml create mode 100644 packages/yq-4/packaging create mode 100644 packages/yq-4/spec diff --git a/README.md b/README.md index 5e553d96..072c7ecd 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,7 @@ The complete list of available properties can be found in the [spec](jobs/postgr Property | Description -------- | ------------- +databases.version | Define the used PostgreSQL major version. Default: 15 databases.port | The database port. Default: 5432 databases.databases | A list of databases and associated properties to create when Postgres starts databases.databases[n].name | Database name diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 40e581d6..ac739674 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -86,6 +86,18 @@ jobs: options: access_key_id: ((postgres-release-blobstore-user.username)) secret_access_key: ((postgres-release-blobstore-user.password)) + - task: bump-yq-package + file: postgres-release/ci/tasks/bump-yq-packages/task.yml + image: bosh-cli-registry-image + input_mapping: + yq-src: yq-4-src + params: + MAJOR_VERSION: 1 + PRIVATE_YML: | + blobstore: + options: + access_key_id: ((postgres-release-blobstore-user.username)) + secret_access_key: ((postgres-release-blobstore-user.password)) - put: postgres-release params: repository: postgres-release @@ -232,6 +244,13 @@ resources: regex: 'href="v(?P16\.[0-9.]+)/"' uri: "https://ftp.postgresql.org/pub/source/v{version}/postgresql-{version}.tar.gz" + - name: yq-4-src + type: http-resource + source: + index: "https://api.github.com/repos/mikefarah/yq/releases" + regex: '"tag_name":"v(?P4\.[0-9.]+)/"' + uri: "https://github.com/mikefarah/yq/releases/download/v{version}/yq_linux_amd64" + - name: postgres-release type: git source: @@ -263,4 +282,3 @@ resource_types: type: docker-image source: repository: aequitas/http-resource - diff --git a/ci/tasks/bump-postgres-packages/task.sh b/ci/tasks/bump-postgres-packages/task.sh index ad9c7dc7..bb1f3117 100755 --- a/ci/tasks/bump-postgres-packages/task.sh +++ b/ci/tasks/bump-postgres-packages/task.sh @@ -19,14 +19,9 @@ pushd postgres-release fi if ${NEED_COMMIT}; then - eval $(grep "^current_version=" jobs/postgres/templates/pgconfig.sh.erb) - new_version=$(echo "${FILENAME}" | egrep -o "[0-9.]+[0-9]") - - # If new version is greater than current version, update the current_version variables - if printf '%s\n' "$current_version" "$new_version" | sort -V -C; then - sed -i "s/^current_version=.*/current_version=\"${new_version}\"/" jobs/postgres/templates/pgconfig.sh.erb - sed -i "s/^current_version=.*/current_version=\"${new_version}\"/" jobs/bbr-postgres-db/templates/config.sh.erb - fi + echo "-----> $(date): Update the PostgreSQL version inside the used_postgresql_versions.yml file" + current_minor_version=$(cat config/blobs.yml | grep "postgresql-${MAJOR_VERSION}" | cut -f1 -d: | sed "s/postgres\/postgresql-//g" | sed "s/.tar.gz//g") + CURRENT_MINOR_VERSION=$current_minor_version /tmp/yq -i '.postgresql.major_version[env(MAJOR_VERSION)].minor_version = strenv(CURRENT_MINOR_VERSION)' jobs/postgres/config/used_postgresql_versions.yml echo "-----> $(date): Creating git commit" git config user.name "$GIT_USER_NAME" diff --git a/ci/tasks/bump-yq-packages/task.sh b/ci/tasks/bump-yq-packages/task.sh new file mode 100755 index 00000000..4dcf36d4 --- /dev/null +++ b/ci/tasks/bump-yq-packages/task.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +NEED_COMMIT=false + +set -euo pipefail + +echo "${PRIVATE_YML}" > postgres-release/config/private.yml + +pushd postgres-release + CURRENT_BLOBS=$(bosh blobs) + CURRENT_VERSION=$(curl -s -L https://api.github.com/repos/mikefarah/yq/releases/latest | grep "tag_name" | sed s/\"tag_name\":\//g | sed s/\"//g | sed s/\,//g | sed s/v//g | xargs) + mv ../yq-src/yq_darwin_amd64 ../yq-src/yq-${CURRENT_VERSION} + BLOB_PATH=$(ls ../yq-src/yq-${CURRENT_VERSION}) + FILENAME=$( basename ${BLOB_PATH} ) + OLD_BLOB_PATH=$(cat config/blobs.yml | grep "yq-${MAJOR_VERSION}" | cut -f1 -d:) + if ! echo "${CURRENT_BLOBS}" | grep "${FILENAME}" ; then + NEED_COMMIT=true + echo "adding ${FILENAME}" + bosh add-blob --sha2 "${BLOB_PATH}" "yq/${FILENAME}" + bosh remove-blob ${OLD_BLOB_PATH} + bosh upload-blobs + fi + + if ${NEED_COMMIT}; then + echo "-----> $(date): Creating git commit" + git config user.name "$GIT_USER_NAME" + git config user.email "$GIT_USER_EMAIL" + git add . + + git --no-pager diff --cached + if [[ "$( git status --porcelain )" != "" ]]; then + git commit -am "Bump packages" + fi + fi +popd diff --git a/ci/tasks/bump-yq-packages/task.yml b/ci/tasks/bump-yq-packages/task.yml new file mode 100644 index 00000000..375b9c0c --- /dev/null +++ b/ci/tasks/bump-yq-packages/task.yml @@ -0,0 +1,17 @@ +--- +platform: linux + +inputs: +- name: yq-src + +outputs: +- name: postgres-release + +run: + path: postgres-release/ci/tasks/bump-yq-packages/task.sh + +params: + PRIVATE_YML: + MAJOR_VERSION: + GIT_USER_NAME: CI Bot + GIT_USER_EMAIL: bots@cloudfoundry.org diff --git a/ci/tasks/create-final-release/task.sh b/ci/tasks/create-final-release/task.sh index 1b7d9a47..a7de4c86 100755 --- a/ci/tasks/create-final-release/task.sh +++ b/ci/tasks/create-final-release/task.sh @@ -8,11 +8,15 @@ set +x echo "$RELEASE_PRIVATE_YML" >> "config/private.yml" set -x +latest_yq_version=$(curl -s -L https://api.github.com/repos/mikefarah/yq/releases/latest | grep "tag_name" | sed s/\"tag_name\":\//g | sed s/\"//g | sed s/\,//g | sed s/v//g | xargs) +curl -s -L https://github.com/mikefarah/yq/releases/download/v${latest_yq_version}/yq_linux_amd64 -o /tmp/yq && chmod +x /tmp/yq + bosh -n create-release --final new_release_version="$(find releases -regex ".*postgres-[0-9]*.yml" | egrep -o "[0-9]+" | sort -n | tail -n 1)" -eval $(grep "^current_version=" jobs/postgres/templates/pgconfig.sh.erb) -sed -i "/^versions:/a\ \ ${new_release_version}: \"PostgreSQL ${current_version}\"" versions.yml +current_major_version=$(/tmp/yq '.postgresql.default' jobs/postgres/config/used_postgresql_versions.yml) +current_minor_version=$(CURRENT_MAJOR_VERSION=$current_major_version /tmp/yq '.postgresql.major_version[env(CURRENT_MAJOR_VERSION)].minor_version' jobs/postgres/config/used_postgresql_versions.yml) +sed -i "/^versions:/a\ \ ${new_release_version}: \"PostgreSQL ${current_minor_version}\"" versions.yml git add versions.yml git add .final_builds releases diff --git a/ci/tasks/run-acceptance-tests/task.sh b/ci/tasks/run-acceptance-tests/task.sh index c77086f8..84899f5f 100755 --- a/ci/tasks/run-acceptance-tests/task.sh +++ b/ci/tasks/run-acceptance-tests/task.sh @@ -2,6 +2,11 @@ root="${PWD}" +function setup_yq() { + latest_yq_version=$(curl -s -L https://api.github.com/repos/mikefarah/yq/releases/latest | grep "tag_name" | sed s/\"tag_name\":\//g | sed s/\"//g | sed s/\,//g | sed s/v//g | xargs) + curl -s -L https://github.com/mikefarah/yq/releases/download/v${latest_yq_version}/yq_linux_amd64 -o /tmp/yq && chmod +x /tmp/yq +} + function setup_bosh() { source start-bosh source /tmp/local-bosh/director/env @@ -43,10 +48,13 @@ function upload_release() { function main() { setup_bosh + setup_yq install_bbr upload_release bosh upload-stemcell stemcell/stemcell.tgz - cat ${root}/postgres-release/jobs/postgres/templates/pgconfig.sh.erb | grep current_version > ${root}/pgconfig.sh + current_major_version=$(/tmp/yq '.postgresql.default' jobs/postgres/config/used_postgresql_versions.yml) + current_minor_version=$(CURRENT_MAJOR_VERSION=$current_major_version /tmp/yq '.postgresql.major_version[env(CURRENT_MAJOR_VERSION)].minor_version' jobs/postgres/config/used_postgresql_versions.yml) + echo "current_version=${current_minor_version}" > ${root}/pgconfig.sh source ${root}/pgconfig.sh config_file="${root}/pgats_config.yml" create_config_file > $config_file diff --git a/jobs/bbr-postgres-db/spec b/jobs/bbr-postgres-db/spec index 3704439a..34bcf79e 100644 --- a/jobs/bbr-postgres-db/spec +++ b/jobs/bbr-postgres-db/spec @@ -18,6 +18,7 @@ packages: - postgres-13 - postgres-15 - postgres-16 + - yq-4 consumes: - name: database diff --git a/jobs/bbr-postgres-db/templates/config.sh.erb b/jobs/bbr-postgres-db/templates/config.sh.erb index 9e89347b..f424a211 100755 --- a/jobs/bbr-postgres-db/templates/config.sh.erb +++ b/jobs/bbr-postgres-db/templates/config.sh.erb @@ -22,9 +22,10 @@ if_link("database") do |data| end %> -current_version="16.3" + +current_version=postgres-$(MAJOR_VERSION=<%=p('databases.version')%> ${JOB_DIR}/packages/yq-4/bin/yq '.postgresql.major_version[env(MAJOR_VERSION)].minor_version' /var/vcap/jobs/postgres/config/used_postgresql_versions.yml) JOB_DIR="/var/vcap/jobs/bbr-postgres-db" -PACKAGE_DIR="/var/vcap/packages/postgres-${current_version%.*}" +PACKAGE_DIR="/var/vcap/packages/${current_version%.*}" PORT="<%= port %>" DATABASES=(<%= databases.map{|d| d["name"]}.join(' ')%>) DBHOST=<%= dbhost %> diff --git a/jobs/postgres/spec b/jobs/postgres/spec index e2df5ab2..271da342 100644 --- a/jobs/postgres/spec +++ b/jobs/postgres/spec @@ -24,6 +24,7 @@ templates: hooks/postgres-pre-stop.sh.erb: bin/hooks/postgres-pre-stop.sh hooks/postgres-post-start.sh.erb: bin/hooks/postgres-post-start.sh hooks/postgres-post-stop.sh.erb: bin/hooks/postgres-post-stop.sh + used_postgresql_versions.yml: config/used_postgresql_versions.yml packages: - postgres-common @@ -31,6 +32,7 @@ packages: - postgres-13 - postgres-15 - postgres-16 + - yq-4 provides: - name: postgres @@ -42,6 +44,9 @@ provides: - databases.tls.ca properties: + databases.version: + description: "The database version e.g. 11, 13, 15 or 16" + default: "16" databases.port: description: "The database port" default: 5432 diff --git a/jobs/postgres/templates/pgconfig.sh.erb b/jobs/postgres/templates/pgconfig.sh.erb index 42c9b06d..cf020737 100644 --- a/jobs/postgres/templates/pgconfig.sh.erb +++ b/jobs/postgres/templates/pgconfig.sh.erb @@ -6,10 +6,10 @@ set -x # if you want tracing disabled, set 'databases.enable_traces: false' in t ENABLE_TRACE=0 # set -x # uncomment it if you want to enable tracing in all control scripts <% end %> -current_version="16.3" -pgversion_current="postgres-${current_version}" - JOB_DIR=/var/vcap/jobs/postgres +current_version="<%=p('databases.version')%>" +pgversion_current=postgres-$(MAJOR_VERSION=<%=p('databases.version')%> ${JOB_DIR}/packages/yq-4/bin/yq '.postgresql.major_version[env(MAJOR_VERSION)].minor_version' /var/vcap/jobs/postgres/config/used_postgresql_versions.yml) + PACKAGE_DIR="/var/vcap/packages/${pgversion_current%.*}" STORE_DIR=/var/vcap/store PG_STORE_DIR=${STORE_DIR}/postgres diff --git a/jobs/postgres/templates/used_postgresql_versions.yml b/jobs/postgres/templates/used_postgresql_versions.yml new file mode 100644 index 00000000..f9bee9ea --- /dev/null +++ b/jobs/postgres/templates/used_postgresql_versions.yml @@ -0,0 +1,11 @@ +postgresql: + default: 16 + major_version: + 16: + minor_version: "16.3" + 15: + minor_version: "15.6" + 13: + minor_version: "13.14" + 11: + minor_version: "11.22" diff --git a/packages/yq-4/packaging b/packages/yq-4/packaging new file mode 100644 index 00000000..b90708a2 --- /dev/null +++ b/packages/yq-4/packaging @@ -0,0 +1,17 @@ +#!/bin/bash -exu + +function main() { + install + +} + +function install() { + + echo "Install yq..." + mkdir -p "${BOSH_INSTALL_TARGET}/bin" + cp -a yq/yq-4.* "${BOSH_INSTALL_TARGET}/bin/yq" + chmod +x "${BOSH_INSTALL_TARGET}/bin/yq" + +} + +main diff --git a/packages/yq-4/spec b/packages/yq-4/spec new file mode 100644 index 00000000..7fe7a8db --- /dev/null +++ b/packages/yq-4/spec @@ -0,0 +1,4 @@ +--- +name: yq-4 +files: + - yq/yq-4.* From d21e98540893de4b608866e438c60018c1806ac5 Mon Sep 17 00:00:00 2001 From: I539231 Date: Tue, 21 May 2024 12:11:00 +0000 Subject: [PATCH 2/3] fix: Rename the package and adapt the CI jobs --- ci/pipeline.yml | 6 +++--- ci/tasks/bump-postgres-packages/task.sh | 3 +++ ci/tasks/bump-yq-packages/task.sh | 10 +++++----- jobs/bbr-postgres-db/spec | 2 +- jobs/bbr-postgres-db/templates/config.sh.erb | 3 ++- jobs/postgres/spec | 6 +++--- jobs/postgres/templates/pgconfig.sh.erb | 2 +- packages/{yq-4 => postgres-yq-4}/packaging | 2 +- packages/postgres-yq-4/spec | 4 ++++ packages/yq-4/spec | 4 ---- 10 files changed, 23 insertions(+), 19 deletions(-) rename packages/{yq-4 => postgres-yq-4}/packaging (76%) create mode 100644 packages/postgres-yq-4/spec delete mode 100644 packages/yq-4/spec diff --git a/ci/pipeline.yml b/ci/pipeline.yml index ac739674..41656bf5 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -90,9 +90,9 @@ jobs: file: postgres-release/ci/tasks/bump-yq-packages/task.yml image: bosh-cli-registry-image input_mapping: - yq-src: yq-4-src + yq-src: postgres-yq-4-src params: - MAJOR_VERSION: 1 + MAJOR_VERSION: 4 PRIVATE_YML: | blobstore: options: @@ -244,7 +244,7 @@ resources: regex: 'href="v(?P16\.[0-9.]+)/"' uri: "https://ftp.postgresql.org/pub/source/v{version}/postgresql-{version}.tar.gz" - - name: yq-4-src + - name: postgres-yq-4-src type: http-resource source: index: "https://api.github.com/repos/mikefarah/yq/releases" diff --git a/ci/tasks/bump-postgres-packages/task.sh b/ci/tasks/bump-postgres-packages/task.sh index bb1f3117..ace87ce7 100755 --- a/ci/tasks/bump-postgres-packages/task.sh +++ b/ci/tasks/bump-postgres-packages/task.sh @@ -19,6 +19,9 @@ pushd postgres-release fi if ${NEED_COMMIT}; then + latest_yq_version=$(curl -s -L https://api.github.com/repos/mikefarah/yq/releases/latest | grep "tag_name" | sed s/\"tag_name\":\//g | sed s/\"//g | sed s/\,//g | sed s/v//g | xargs) + curl -s -L https://github.com/mikefarah/yq/releases/download/v${latest_yq_version}/yq_linux_amd64 -o /tmp/yq && chmod +x /tmp/yq + echo "-----> $(date): Update the PostgreSQL version inside the used_postgresql_versions.yml file" current_minor_version=$(cat config/blobs.yml | grep "postgresql-${MAJOR_VERSION}" | cut -f1 -d: | sed "s/postgres\/postgresql-//g" | sed "s/.tar.gz//g") CURRENT_MINOR_VERSION=$current_minor_version /tmp/yq -i '.postgresql.major_version[env(MAJOR_VERSION)].minor_version = strenv(CURRENT_MINOR_VERSION)' jobs/postgres/config/used_postgresql_versions.yml diff --git a/ci/tasks/bump-yq-packages/task.sh b/ci/tasks/bump-yq-packages/task.sh index 4dcf36d4..29a176c6 100755 --- a/ci/tasks/bump-yq-packages/task.sh +++ b/ci/tasks/bump-yq-packages/task.sh @@ -7,15 +7,15 @@ echo "${PRIVATE_YML}" > postgres-release/config/private.yml pushd postgres-release CURRENT_BLOBS=$(bosh blobs) - CURRENT_VERSION=$(curl -s -L https://api.github.com/repos/mikefarah/yq/releases/latest | grep "tag_name" | sed s/\"tag_name\":\//g | sed s/\"//g | sed s/\,//g | sed s/v//g | xargs) - mv ../yq-src/yq_darwin_amd64 ../yq-src/yq-${CURRENT_VERSION} - BLOB_PATH=$(ls ../yq-src/yq-${CURRENT_VERSION}) + CURRENT_VERSION=$(cat ../yq-src/version) + mv ../yq-src/yq_linux_amd64 ../yq-src/postgres-yq-${CURRENT_VERSION} + BLOB_PATH=$(ls ../yq-src/postgres-yq-${CURRENT_VERSION}) FILENAME=$( basename ${BLOB_PATH} ) - OLD_BLOB_PATH=$(cat config/blobs.yml | grep "yq-${MAJOR_VERSION}" | cut -f1 -d:) + OLD_BLOB_PATH=$(cat config/blobs.yml | grep "postgres-yq-${MAJOR_VERSION}" | cut -f1 -d:) if ! echo "${CURRENT_BLOBS}" | grep "${FILENAME}" ; then NEED_COMMIT=true echo "adding ${FILENAME}" - bosh add-blob --sha2 "${BLOB_PATH}" "yq/${FILENAME}" + bosh add-blob --sha2 "${BLOB_PATH}" "yq/postgres-${FILENAME}" bosh remove-blob ${OLD_BLOB_PATH} bosh upload-blobs fi diff --git a/jobs/bbr-postgres-db/spec b/jobs/bbr-postgres-db/spec index 34bcf79e..01f0b619 100644 --- a/jobs/bbr-postgres-db/spec +++ b/jobs/bbr-postgres-db/spec @@ -18,7 +18,7 @@ packages: - postgres-13 - postgres-15 - postgres-16 - - yq-4 + - postgres-yq-4 consumes: - name: database diff --git a/jobs/bbr-postgres-db/templates/config.sh.erb b/jobs/bbr-postgres-db/templates/config.sh.erb index f424a211..592a5f89 100755 --- a/jobs/bbr-postgres-db/templates/config.sh.erb +++ b/jobs/bbr-postgres-db/templates/config.sh.erb @@ -23,8 +23,9 @@ end %> -current_version=postgres-$(MAJOR_VERSION=<%=p('databases.version')%> ${JOB_DIR}/packages/yq-4/bin/yq '.postgresql.major_version[env(MAJOR_VERSION)].minor_version' /var/vcap/jobs/postgres/config/used_postgresql_versions.yml) JOB_DIR="/var/vcap/jobs/bbr-postgres-db" +current_version=postgres-$(MAJOR_VERSION=<%=p('databases.version')%> ${JOB_DIR}/packages/postgres-yq-4/bin/yq '.postgresql.major_version[env(MAJOR_VERSION)].minor_version' /var/vcap/jobs/postgres/config/used_postgresql_versions.yml) + PACKAGE_DIR="/var/vcap/packages/${current_version%.*}" PORT="<%= port %>" DATABASES=(<%= databases.map{|d| d["name"]}.join(' ')%>) diff --git a/jobs/postgres/spec b/jobs/postgres/spec index 271da342..4ef2df9f 100644 --- a/jobs/postgres/spec +++ b/jobs/postgres/spec @@ -32,7 +32,7 @@ packages: - postgres-13 - postgres-15 - postgres-16 - - yq-4 + - postgres-yq-4 provides: - name: postgres @@ -45,8 +45,8 @@ provides: properties: databases.version: - description: "The database version e.g. 11, 13, 15 or 16" - default: "16" + description: "The database version e.g. 11, 13, 15 or 16" + default: "16" databases.port: description: "The database port" default: 5432 diff --git a/jobs/postgres/templates/pgconfig.sh.erb b/jobs/postgres/templates/pgconfig.sh.erb index cf020737..29fd87e8 100644 --- a/jobs/postgres/templates/pgconfig.sh.erb +++ b/jobs/postgres/templates/pgconfig.sh.erb @@ -8,7 +8,7 @@ ENABLE_TRACE=0 <% end %> JOB_DIR=/var/vcap/jobs/postgres current_version="<%=p('databases.version')%>" -pgversion_current=postgres-$(MAJOR_VERSION=<%=p('databases.version')%> ${JOB_DIR}/packages/yq-4/bin/yq '.postgresql.major_version[env(MAJOR_VERSION)].minor_version' /var/vcap/jobs/postgres/config/used_postgresql_versions.yml) +pgversion_current=postgres-$(MAJOR_VERSION=<%=p('databases.version')%> ${JOB_DIR}/packages/postgres-yq-4/bin/yq '.postgresql.major_version[env(MAJOR_VERSION)].minor_version' /var/vcap/jobs/postgres/config/used_postgresql_versions.yml) PACKAGE_DIR="/var/vcap/packages/${pgversion_current%.*}" STORE_DIR=/var/vcap/store diff --git a/packages/yq-4/packaging b/packages/postgres-yq-4/packaging similarity index 76% rename from packages/yq-4/packaging rename to packages/postgres-yq-4/packaging index b90708a2..1b0b4f79 100644 --- a/packages/yq-4/packaging +++ b/packages/postgres-yq-4/packaging @@ -9,7 +9,7 @@ function install() { echo "Install yq..." mkdir -p "${BOSH_INSTALL_TARGET}/bin" - cp -a yq/yq-4.* "${BOSH_INSTALL_TARGET}/bin/yq" + cp -a yq/postgres-yq-4.* "${BOSH_INSTALL_TARGET}/bin/yq" chmod +x "${BOSH_INSTALL_TARGET}/bin/yq" } diff --git a/packages/postgres-yq-4/spec b/packages/postgres-yq-4/spec new file mode 100644 index 00000000..4775dbcb --- /dev/null +++ b/packages/postgres-yq-4/spec @@ -0,0 +1,4 @@ +--- +name: postgres-yq-4 +files: + - yq/postgres-yq-4.* diff --git a/packages/yq-4/spec b/packages/yq-4/spec deleted file mode 100644 index 7fe7a8db..00000000 --- a/packages/yq-4/spec +++ /dev/null @@ -1,4 +0,0 @@ ---- -name: yq-4 -files: - - yq/yq-4.* From 69346f0d21408458896eab37abe3ba6ecbb0dbae Mon Sep 17 00:00:00 2001 From: I539231 Date: Fri, 24 May 2024 10:58:21 +0200 Subject: [PATCH 3/3] feat: Add the check to make the downgrade not possible --- README.md | 2 +- jobs/postgres/spec | 2 +- jobs/postgres/templates/utils.sh.erb | 11 +++++++++-- test/test_major_or_minor_version.sh | 10 +++++++++- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 072c7ecd..e1419a5d 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ The complete list of available properties can be found in the [spec](jobs/postgr Property | Description -------- | ------------- -databases.version | Define the used PostgreSQL major version. Default: 15 +databases.version | Define the used PostgreSQL major version. Default: 16 databases.port | The database port. Default: 5432 databases.databases | A list of databases and associated properties to create when Postgres starts databases.databases[n].name | Database name diff --git a/jobs/postgres/spec b/jobs/postgres/spec index 4ef2df9f..33f3dfe0 100644 --- a/jobs/postgres/spec +++ b/jobs/postgres/spec @@ -46,7 +46,7 @@ provides: properties: databases.version: description: "The database version e.g. 11, 13, 15 or 16" - default: "16" + default: 16 databases.port: description: "The database port" default: 5432 diff --git a/jobs/postgres/templates/utils.sh.erb b/jobs/postgres/templates/utils.sh.erb index 95759ad9..2d973522 100644 --- a/jobs/postgres/templates/utils.sh.erb +++ b/jobs/postgres/templates/utils.sh.erb @@ -68,6 +68,13 @@ function is_major() { [ "${pgversion_current%.*}" != "${pgversion_upgrade_from%.*}" ] } +function check_postgresql_versions(){ + if [[ $(echo -e "$pgversion_upgrade_from\n$pgversion_current" | sort --version-sort | head --lines=1) != $pgversion_upgrade_from ]]; then + echo "The downgrade of the database instance is not supported." + exit 1 + fi +} + function init_data_dir(){ if [ ! -f "${DATA_DIR}/postgresql.conf" ]; then # initdb creates data directories @@ -77,7 +84,7 @@ function init_data_dir(){ } function run_major_upgrade(){ - if is_major; then + if is_major && check_postgresql_versions; then rm -rf ${DATA_DIR_PREVIOUS} echo "Running a PostgreSQL major upgrade from ${pgversion_upgrade_from} to ${pgversion_current}" touch "$POSTGRES_UPGRADE_LOCK" @@ -105,7 +112,7 @@ EOF fi } function run_minor_upgrade(){ - if ! is_major; then + if ! is_major && check_postgresql_versions; then rm -rf ${DATA_DIR_PREVIOUS} echo "Running a PostgreSQL minor upgrade from ${pgversion_upgrade_from} to ${pgversion_current}" <% if p("databases.skip_data_copy_in_minor") %> diff --git a/test/test_major_or_minor_version.sh b/test/test_major_or_minor_version.sh index ea534cca..b1f4f0ca 100755 --- a/test/test_major_or_minor_version.sh +++ b/test/test_major_or_minor_version.sh @@ -5,10 +5,18 @@ pgversion_current=$2 # From postgres-x.y.z, it's major if x and y are not the same # in $pgversion_current and $pgversion_upgrade_from +function check_postgresql_versions(){ + if [[ $(echo -e "$pgversion_upgrade_from\n$pgversion_current" | sort --version-sort | head --lines=1) != $pgversion_upgrade_from ]]; then + echo "The downgrade of the database instance is not supported." + exit 1 + fi +} + function is_major() { [ "${pgversion_current%.*}" != "${pgversion_upgrade_from%.*}" ] } -if is_major; then + +if is_major && check_postgresql_versions; then echo is major else echo is minor