diff --git a/bitnami/postgresql/9.6/debian-10/Dockerfile b/bitnami/postgresql/9.6/debian-10/Dockerfile index 65cc6cac1214..d6a1ca4f883c 100644 --- a/bitnami/postgresql/9.6/debian-10/Dockerfile +++ b/bitnami/postgresql/9.6/debian-10/Dockerfile @@ -22,7 +22,7 @@ RUN echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen && locale-gen COPY rootfs / RUN /opt/bitnami/scripts/postgresql/postunpack.sh ENV BITNAMI_APP_NAME="postgresql" \ - BITNAMI_IMAGE_VERSION="9.6.18-debian-10-r32" \ + BITNAMI_IMAGE_VERSION="9.6.18-debian-10-r33" \ LANG="en_US.UTF-8" \ LANGUAGE="en_US:en" \ NSS_WRAPPER_LIB="/opt/bitnami/common/lib/libnss_wrapper.so" \ diff --git a/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh b/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh index 251a47dc7052..c7c94c3ba988 100644 --- a/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh +++ b/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libfs.sh @@ -59,6 +59,23 @@ is_dir_empty() { fi } +######################## +# Checks whether a mounted directory is empty or not +# arguments: +# $1 - directory +# returns: +# boolean +######################### +is_mounted_dir_empty() { + local dir="${1:?missing directory}" + + if is_dir_empty "$dir" || find "$dir" -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" -exec false {} +; then + true + else + false + fi +} + ######################## # Checks whether a file can be written to or not # arguments: diff --git a/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libpersistence.sh b/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libpersistence.sh new file mode 100644 index 000000000000..d4a0b32e1132 --- /dev/null +++ b/bitnami/postgresql/9.6/debian-10/prebuildfs/opt/bitnami/scripts/libpersistence.sh @@ -0,0 +1,99 @@ +#!/bin/bash +# +# Bitnami persistence library +# Used for bringing persistence capabilities to applications that don't have clear separation of data and logic + +# shellcheck disable=SC1091 + +# Load Generic Libraries +. /opt/bitnami/scripts/libfs.sh +. /opt/bitnami/scripts/liblog.sh +. /opt/bitnami/scripts/libversion.sh + +# Functions + +######################## +# Persist an application directory +# Globals: +# BITNAMI_ROOT_DIR +# BITNAMI_VOLUME_DIR +# Arguments: +# $1 - App folder name +# $2 - List of app files to persist +# Returns: +# true if all steps succeeded, false otherwise +######################### +persist_app() { + local -r app="${1:?missing app}" + local -a files_to_restore + read -r -a files_to_persist <<< "$2" + local -r install_dir="${BITNAMI_ROOT_DIR}/${app}" + local -r persist_dir="${BITNAMI_VOLUME_DIR}/${app}" + # Persist the individual files + if [[ "${#files_to_persist[@]}" -lt 0 ]]; then + warn "No files are configured to be persisted" + return + fi + local file_to_persist_origin file_to_persist_destination file_to_persist_destination_folder + for file_to_persist in "${files_to_persist[@]}"; do + file_to_persist_origin="${install_dir}/${file_to_persist}" + file_to_persist_destination="${persist_dir}/${file_to_persist}" + file_to_persist_destination_folder="$(dirname "$file_to_persist_destination")" + mkdir -p "$file_to_persist_destination_folder" + cp -Lr "$file_to_persist_origin" "$file_to_persist_destination_folder" + done + # Install the persisted files into the installation directory, via symlinks + restore_persisted_app "$@" +} + +######################## +# Restore a persisted application directory +# Globals: +# BITNAMI_ROOT_DIR +# BITNAMI_VOLUME_DIR +# FORCE_MAJOR_UPGRADE +# Arguments: +# $1 - App folder name +# $2 - List of app files to restore +# Returns: +# true if all steps succeeded, false otherwise +######################### +restore_persisted_app() { + local -r app="${1:?missing app}" + local -a files_to_restore + read -r -a files_to_restore <<< "$2" + local -r install_dir="${BITNAMI_ROOT_DIR}/${app}" + local -r persist_dir="${BITNAMI_VOLUME_DIR}/${app}" + # Restore the individual persisted files + if [[ "${#files_to_restore[@]}" -lt 0 ]]; then + warn "No persisted files are configured to be restored" + return + fi + local file_to_restore_origin file_to_restore_destination + for file_to_restore in "${files_to_restore[@]}"; do + # We use realpath to ensure that the case of '.' is covered and the directory is removed + file_to_restore_origin="$(realpath "${install_dir}/${file_to_restore}")" + file_to_restore_destination="$(realpath "${persist_dir}/${file_to_restore}")" + rm -rf "$file_to_restore_origin" + ln -sfn "$file_to_restore_destination" "$file_to_restore_origin" + done +} + +######################## +# Check if an application directory was already persisted +# Globals: +# BITNAMI_VOLUME_DIR +# Arguments: +# $1 - App folder name +# Returns: +# true if all steps succeeded, false otherwise +######################### +is_app_initialized() { + local -r app="${1:?missing app}" + local -r persist_dir="${BITNAMI_VOLUME_DIR}/${app}" + if ! is_mounted_dir_empty "$persist_dir"; then + true + else + false + fi +} diff --git a/bitnami/postgresql/README.md b/bitnami/postgresql/README.md index e207e3503d78..077b5d72bf8f 100644 --- a/bitnami/postgresql/README.md +++ b/bitnami/postgresql/README.md @@ -45,7 +45,7 @@ Learn more about the Bitnami tagging policy and the difference between rolling t * [`12-debian-10`, `12.3.0-debian-10-r30`, `12`, `12.3.0` (12/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/12.3.0-debian-10-r30/12/debian-10/Dockerfile) * [`11-debian-10`, `11.8.0-debian-10-r33`, `11`, `11.8.0`, `latest` (11/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/11.8.0-debian-10-r33/11/debian-10/Dockerfile) * [`10-debian-10`, `10.13.0-debian-10-r31`, `10`, `10.13.0` (10/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/10.13.0-debian-10-r31/10/debian-10/Dockerfile) -* [`9.6-debian-10`, `9.6.18-debian-10-r32`, `9.6`, `9.6.18` (9.6/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/9.6.18-debian-10-r32/9.6/debian-10/Dockerfile) +* [`9.6-debian-10`, `9.6.18-debian-10-r33`, `9.6`, `9.6.18` (9.6/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-postgresql/blob/9.6.18-debian-10-r33/9.6/debian-10/Dockerfile) Subscribe to project updates by watching the [bitnami/postgresql GitHub repo](https://github.com/bitnami/bitnami-docker-postgresql).