From 5dde7c8e286317814e6d1176f8874030aacffa4a Mon Sep 17 00:00:00 2001 From: 0x1def <0x1def@flakybit.net> Date: Sun, 1 Sep 2024 20:56:02 +0300 Subject: [PATCH] Refactored Bitnami base - restructured directories - removed unused libraries - removed welcome message - refactored docker file --- Dockerfile | 56 ++- prebuildfs/opt/bitnami/licenses/licenses.txt | 2 - prebuildfs/opt/bitnami/scripts/libbitnami.sh | 53 -- prebuildfs/opt/bitnami/scripts/libhook.sh | 18 - .../opt/bitnami/scripts/libpersistence.sh | 124 ----- prebuildfs/opt/bitnami/scripts/libversion.sh | 51 -- .../opt/bitnami/scripts/libwebserver.sh | 476 ------------------ .../mongodb => mongodb/scripts}/entrypoint.sh | 11 +- .../{ => mongodb}/scripts/libmongodb.sh | 0 .../{ => mongodb}/scripts/mongodb-env.sh | 0 .../mongodb => mongodb/scripts}/postunpack.sh | 4 +- .../mongodb => mongodb/scripts}/run.sh | 4 +- .../mongodb => mongodb/scripts}/setup.sh | 4 +- .../opt/bitnami/scripts/libfile.sh | 0 .../opt/bitnami/scripts/libfs.sh | 0 .../opt/bitnami/scripts/liblog.sh | 0 .../opt/bitnami/scripts/libnet.sh | 0 .../opt/bitnami/scripts/libos.sh | 0 .../opt/bitnami/scripts/libservice.sh | 0 .../opt/bitnami/scripts/libvalidations.sh | 0 .../usr/sbin/install_packages | 0 {prebuildfs => rootfs}/usr/sbin/run-script | 0 22 files changed, 41 insertions(+), 762 deletions(-) delete mode 100644 prebuildfs/opt/bitnami/licenses/licenses.txt delete mode 100755 prebuildfs/opt/bitnami/scripts/libbitnami.sh delete mode 100755 prebuildfs/opt/bitnami/scripts/libhook.sh delete mode 100755 prebuildfs/opt/bitnami/scripts/libpersistence.sh delete mode 100755 prebuildfs/opt/bitnami/scripts/libversion.sh delete mode 100755 prebuildfs/opt/bitnami/scripts/libwebserver.sh rename rootfs/opt/bitnami/{scripts/mongodb => mongodb/scripts}/entrypoint.sh (75%) rename rootfs/opt/bitnami/{ => mongodb}/scripts/libmongodb.sh (100%) rename rootfs/opt/bitnami/{ => mongodb}/scripts/mongodb-env.sh (100%) rename rootfs/opt/bitnami/{scripts/mongodb => mongodb/scripts}/postunpack.sh (94%) rename rootfs/opt/bitnami/{scripts/mongodb => mongodb/scripts}/run.sh (91%) rename rootfs/opt/bitnami/{scripts/mongodb => mongodb/scripts}/setup.sh (94%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/libfile.sh (100%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/libfs.sh (100%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/liblog.sh (100%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/libnet.sh (100%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/libos.sh (100%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/libservice.sh (100%) rename {prebuildfs => rootfs}/opt/bitnami/scripts/libvalidations.sh (100%) rename {prebuildfs => rootfs}/usr/sbin/install_packages (100%) rename {prebuildfs => rootfs}/usr/sbin/run-script (100%) diff --git a/Dockerfile b/Dockerfile index 83c8d45..4b91b10 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,34 @@ FROM docker.io/bitnami/minideb:bookworm -ARG VERSION -LABEL org.opencontainers.image.base.name="docker.io/bitnami/minideb:bookworm" \ - org.opencontainers.image.title="mongodb" \ - org.opencontainers.image.version="${VERSION}" - -ENV HOME="/" \ +ENV APP_NAME="mongodb" \ + APP_VERSION="7.0.10" \ + HOME="/opt/bitnami/mongodb" \ OS_ARCH="amd64" \ OS_FLAVOUR="debian-12" \ OS_NAME="linux" \ UID=1001 \ GID=1001 -COPY prebuildfs / +LABEL org.opencontainers.image.base.name="docker.io/bitnami/minideb:bookworm" \ + org.opencontainers.image.title="${APP_NAME}" \ + org.opencontainers.image.version="${APP_VERSION}" \ + org.opencontainers.image.licenses="Apache-2.0" + +COPY rootfs / SHELL ["/bin/bash", "-o", "errexit", "-o", "nounset", "-o", "pipefail", "-c"] -# Install required system packages and dependencies -RUN install_packages ca-certificates curl libbrotli1 libcom-err2 libcurl4 libffi8 libgcc-s1 libgcrypt20 libgmp10 libgnutls30 \ +RUN groupadd --gid $GID mongo && \ + useradd --uid $UID --gid $GID --no-create-home --home-dir $HOME mongo + +# Update and install required system packages and dependencies +RUN apt-get update && apt-get upgrade -y && \ + install_packages ca-certificates curl libbrotli1 libcom-err2 libcurl4 libffi8 libgcc-s1 libgcrypt20 libgmp10 libgnutls30 \ libgpg-error0 libgssapi-krb5-2 libhogweed6 libidn2-0 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.5-0 liblzma5 \ libnettle8 libnghttp2-14 libp11-kit0 libpsl5 librtmp1 libsasl2-2 libssh2-1 libssl3 libtasn1-6 libunistring2 numactl procps zlib1g + +# Install required system packages and dependencies RUN mkdir -p /tmp/bitnami/pkg/cache/ ; \ cd /tmp/bitnami/pkg/cache/ ; \ + # Install Bitnami components BITNAMI_COMPONENTS=( \ "mongodb-shell-2.2.5-0-linux-${OS_ARCH}-${OS_FLAVOUR}" \ "yq-4.43.1-1-linux-${OS_ARCH}-${OS_FLAVOUR}" \ @@ -35,8 +44,9 @@ RUN mkdir -p /tmp/bitnami/pkg/cache/ ; \ tar -zxf "${COMPONENT}.tar.gz" -C /opt/bitnami --strip-components=2 --no-same-owner --wildcards '*/files' ; \ rm -rf "${COMPONENT}".tar.gz{,.sha256} ; \ done ; \ + # Install custom MongoDB and tools COMPONENTS=( \ - "mongodb-${VERSION}-0-linux-${OS_ARCH}-${OS_FLAVOUR}" \ + "mongodb-${APP_VERSION}-0-linux-${OS_ARCH}-${OS_FLAVOUR}" \ "mongo-tools-100.9.4-linux-${OS_ARCH}" \ ) ; \ for COMPONENT in "${COMPONENTS[@]}"; do \ @@ -48,25 +58,21 @@ RUN mkdir -p /tmp/bitnami/pkg/cache/ ; \ tar -zxf "${COMPONENT}.tar.gz" -C /opt/bitnami/mongodb/bin --no-same-owner ; \ rm -rf "${COMPONENT}".tar.gz{,.sha256} ; \ done ; \ + # Install rust-ping curl -SsLf "https://github.com/syndikat7/mongodb-rust-ping/releases/download/v0.2.1/mongodb-rust-ping-linux-x64.tar.gz" -O ; \ tar -zxf "mongodb-rust-ping-linux-x64.tar.gz" -C /usr/bin --no-same-owner ; \ rm -rf "mongodb-rust-ping-linux-x64.tar.gz" + +# Remove unused packages and clean APT cache RUN apt-get autoremove --purge -y curl && \ - apt-get update && apt-get upgrade -y && \ - apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives -RUN chmod g+rwX /opt/bitnami -RUN find / -perm /6000 -type f -exec chmod a-s {} \; || true + apt-get clean && rm -rf /var/lib/apt/lists /var/cache/apt/archives /tmp/bitnami/pkg/cache -COPY rootfs / -RUN groupadd --gid $GID mongo && \ - useradd --uid $UID --gid $GID --no-create-home --home-dir /opt/bitnami/mongodb mongo -RUN /opt/bitnami/scripts/mongodb/postunpack.sh -ENV APP_VERSION="${VERSION}" \ - BITNAMI_APP_NAME="mongodb" \ - PATH="/opt/bitnami/common/bin:/opt/bitnami/mongodb/bin:$PATH" - -EXPOSE 27017 +# Fix permissions +RUN chmod g+rwX /opt/bitnami ; \ + find / -perm /6000 -type f -exec chmod a-s {} \; || true ; \ + /opt/bitnami/mongodb/scripts/postunpack.sh USER $UID:$GID -ENTRYPOINT [ "/opt/bitnami/scripts/mongodb/entrypoint.sh" ] -CMD [ "/opt/bitnami/scripts/mongodb/run.sh" ] +EXPOSE 27017 +ENTRYPOINT [ "/opt/bitnami/mongodb/scripts/entrypoint.sh" ] +CMD [ "/opt/bitnami/mongodb/scripts/run.sh" ] diff --git a/prebuildfs/opt/bitnami/licenses/licenses.txt b/prebuildfs/opt/bitnami/licenses/licenses.txt deleted file mode 100644 index 76956b3..0000000 --- a/prebuildfs/opt/bitnami/licenses/licenses.txt +++ /dev/null @@ -1,2 +0,0 @@ -Bitnami containers ship with software bundles. You can find the licenses under: -/opt/bitnami/[name-of-bundle]/licenses/[bundle-version].txt diff --git a/prebuildfs/opt/bitnami/scripts/libbitnami.sh b/prebuildfs/opt/bitnami/scripts/libbitnami.sh deleted file mode 100755 index 3853c78..0000000 --- a/prebuildfs/opt/bitnami/scripts/libbitnami.sh +++ /dev/null @@ -1,53 +0,0 @@ -#!/bin/bash -# Copyright VMware, Inc. -# SPDX-License-Identifier: APACHE-2.0 -# -# Bitnami custom library - -# shellcheck disable=SC1091 - -# Load Generic Libraries -. /opt/bitnami/scripts/liblog.sh - -# Constants -BOLD='\033[1m' - -# Functions - -######################## -# Print the welcome page -# Globals: -# DISABLE_WELCOME_MESSAGE -# BITNAMI_APP_NAME -# Arguments: -# None -# Returns: -# None -######################### -print_welcome_page() { - if [[ -z "${DISABLE_WELCOME_MESSAGE:-}" ]]; then - if [[ -n "$BITNAMI_APP_NAME" ]]; then - print_image_welcome_page - fi - fi -} - -######################## -# Print the welcome page for a Bitnami Docker image -# Globals: -# BITNAMI_APP_NAME -# Arguments: -# None -# Returns: -# None -######################### -print_image_welcome_page() { - local github_url="https://github.com/bitnami/containers" - - info "" - info "${BOLD}Welcome to the Bitnami ${BITNAMI_APP_NAME} container${RESET}" - info "Subscribe to project updates by watching ${BOLD}${github_url}${RESET}" - info "Submit issues and feature requests at ${BOLD}${github_url}/issues${RESET}" - info "" -} - diff --git a/prebuildfs/opt/bitnami/scripts/libhook.sh b/prebuildfs/opt/bitnami/scripts/libhook.sh deleted file mode 100755 index dadd061..0000000 --- a/prebuildfs/opt/bitnami/scripts/libhook.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# Copyright VMware, Inc. -# SPDX-License-Identifier: APACHE-2.0 -# -# Library to use for scripts expected to be used as Kubernetes lifecycle hooks - -# shellcheck disable=SC1091 - -# Load generic libraries -. /opt/bitnami/scripts/liblog.sh -. /opt/bitnami/scripts/libos.sh - -# Override functions that log to stdout/stderr of the current process, so they print to process 1 -for function_to_override in stderr_print debug_execute; do - # Output is sent to output of process 1 and thus end up in the container log - # The hook output in general isn't saved - eval "$(declare -f "$function_to_override") >/proc/1/fd/1 2>/proc/1/fd/2" -done diff --git a/prebuildfs/opt/bitnami/scripts/libpersistence.sh b/prebuildfs/opt/bitnami/scripts/libpersistence.sh deleted file mode 100755 index af6af64..0000000 --- a/prebuildfs/opt/bitnami/scripts/libpersistence.sh +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/bash -# Copyright VMware, Inc. -# SPDX-License-Identifier: APACHE-2.0 -# -# 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/libos.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 <<< "$(tr ',;:' ' ' <<< "$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[@]}" -le 0 ]]; then - warn "No files are configured to be persisted" - return - fi - pushd "$install_dir" >/dev/null || exit - local file_to_persist_relative file_to_persist_destination file_to_persist_destination_folder - local -r tmp_file="/tmp/perms.acl" - for file_to_persist in "${files_to_persist[@]}"; do - if [[ ! -f "$file_to_persist" && ! -d "$file_to_persist" ]]; then - error "Cannot persist '${file_to_persist}' because it does not exist" - return 1 - fi - file_to_persist_relative="$(relativize "$file_to_persist" "$install_dir")" - file_to_persist_destination="${persist_dir}/${file_to_persist_relative}" - file_to_persist_destination_folder="$(dirname "$file_to_persist_destination")" - # Get original permissions for existing files, which will be applied later - # Exclude the root directory with 'sed', to avoid issues when copying the entirety of it to a volume - getfacl -R "$file_to_persist_relative" | sed -E '/# file: (\..+|[^.])/,$!d' > "$tmp_file" - # Copy directories to the volume - ensure_dir_exists "$file_to_persist_destination_folder" - cp -Lr --preserve=links "$file_to_persist_relative" "$file_to_persist_destination_folder" - # Restore permissions - pushd "$persist_dir" >/dev/null || exit - if am_i_root; then - setfacl --restore="$tmp_file" - else - # When running as non-root, don't change ownership - setfacl --restore=<(grep -E -v '^# (owner|group):' "$tmp_file") - fi - popd >/dev/null || exit - done - popd >/dev/null || exit - rm -f "$tmp_file" - # 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 <<< "$(tr ',;:' ' ' <<< "$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[@]}" -le 0 ]]; then - warn "No persisted files are configured to be restored" - return - fi - local file_to_restore_relative file_to_restore_origin file_to_restore_destination - for file_to_restore in "${files_to_restore[@]}"; do - file_to_restore_relative="$(relativize "$file_to_restore" "$install_dir")" - # We use 'realpath --no-symlinks' to ensure that the case of '.' is covered and the directory is removed - file_to_restore_origin="$(realpath --no-symlinks "${install_dir}/${file_to_restore_relative}")" - file_to_restore_destination="$(realpath --no-symlinks "${persist_dir}/${file_to_restore_relative}")" - 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/prebuildfs/opt/bitnami/scripts/libversion.sh b/prebuildfs/opt/bitnami/scripts/libversion.sh deleted file mode 100755 index 6ca71ac..0000000 --- a/prebuildfs/opt/bitnami/scripts/libversion.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -# Copyright VMware, Inc. -# SPDX-License-Identifier: APACHE-2.0 -# -# Library for managing versions strings - -# shellcheck disable=SC1091 - -# Load Generic Libraries -. /opt/bitnami/scripts/liblog.sh - -# Functions -######################## -# Gets semantic version -# Arguments: -# $1 - version: string to extract major.minor.patch -# $2 - section: 1 to extract major, 2 to extract minor, 3 to extract patch -# Returns: -# array with the major, minor and release -######################### -get_sematic_version () { - local version="${1:?version is required}" - local section="${2:?section is required}" - local -a version_sections - - #Regex to parse versions: x.y.z - local -r regex='([0-9]+)(\.([0-9]+)(\.([0-9]+))?)?' - - if [[ "$version" =~ $regex ]]; then - local i=1 - local j=1 - local n=${#BASH_REMATCH[*]} - - while [[ $i -lt $n ]]; do - if [[ -n "${BASH_REMATCH[$i]}" ]] && [[ "${BASH_REMATCH[$i]:0:1}" != '.' ]]; then - version_sections[j]="${BASH_REMATCH[$i]}" - ((j++)) - fi - ((i++)) - done - - local number_regex='^[0-9]+$' - if [[ "$section" =~ $number_regex ]] && (( section > 0 )) && (( section <= 3 )); then - echo "${version_sections[$section]}" - return - else - stderr_print "Section allowed values are: 1, 2, and 3" - return 1 - fi - fi -} diff --git a/prebuildfs/opt/bitnami/scripts/libwebserver.sh b/prebuildfs/opt/bitnami/scripts/libwebserver.sh deleted file mode 100755 index 8023f9b..0000000 --- a/prebuildfs/opt/bitnami/scripts/libwebserver.sh +++ /dev/null @@ -1,476 +0,0 @@ -#!/bin/bash -# Copyright VMware, Inc. -# SPDX-License-Identifier: APACHE-2.0 -# -# Bitnami web server handler library - -# shellcheck disable=SC1090,SC1091 - -# Load generic libraries -. /opt/bitnami/scripts/liblog.sh - -######################## -# Execute a command (or list of commands) with the web server environment and library loaded -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_execute() { - local -r web_server="${1:?missing web server}" - shift - # Run program in sub-shell to avoid web server environment getting loaded when not necessary - ( - . "/opt/bitnami/scripts/lib${web_server}.sh" - . "/opt/bitnami/scripts/${web_server}-env.sh" - "$@" - ) -} - -######################## -# Prints the list of enabled web servers -# Globals: -# None -# Arguments: -# None -# Returns: -# None -######################### -web_server_list() { - local -r -a supported_web_servers=(apache nginx) - local -a existing_web_servers=() - for web_server in "${supported_web_servers[@]}"; do - [[ -f "/opt/bitnami/scripts/${web_server}-env.sh" ]] && existing_web_servers+=("$web_server") - done - echo "${existing_web_servers[@]:-}" -} - -######################## -# Prints the currently-enabled web server type (only one, in order of preference) -# Globals: -# None -# Arguments: -# None -# Returns: -# None -######################### -web_server_type() { - local -a web_servers - read -r -a web_servers <<< "$(web_server_list)" - echo "${web_servers[0]:-}" -} - -######################## -# Validate that a supported web server is configured -# Globals: -# None -# Arguments: -# None -# Returns: -# None -######################### -web_server_validate() { - local error_code=0 - local supported_web_servers=("apache" "nginx") - - # Auxiliary functions - print_validation_error() { - error "$1" - error_code=1 - } - - if [[ -z "$(web_server_type)" || ! " ${supported_web_servers[*]} " == *" $(web_server_type) "* ]]; then - print_validation_error "Could not detect any supported web servers. It must be one of: ${supported_web_servers[*]}" - elif ! web_server_execute "$(web_server_type)" type -t "is_$(web_server_type)_running" >/dev/null; then - print_validation_error "Could not load the $(web_server_type) web server library from /opt/bitnami/scripts. Check that it exists and is readable." - fi - - return "$error_code" -} - -######################## -# Check whether the web server is running -# Globals: -# * -# Arguments: -# None -# Returns: -# true if the web server is running, false otherwise -######################### -is_web_server_running() { - "is_$(web_server_type)_running" -} - -######################## -# Start web server -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_start() { - info "Starting $(web_server_type) in background" - if [[ "${BITNAMI_SERVICE_MANAGER:-}" = "systemd" ]]; then - systemctl start "bitnami.$(web_server_type).service" - else - "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/start.sh" - fi -} - -######################## -# Stop web server -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_stop() { - info "Stopping $(web_server_type)" - if [[ "${BITNAMI_SERVICE_MANAGER:-}" = "systemd" ]]; then - systemctl stop "bitnami.$(web_server_type).service" - else - "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/stop.sh" - fi -} - -######################## -# Restart web server -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_restart() { - info "Restarting $(web_server_type)" - if [[ "${BITNAMI_SERVICE_MANAGER:-}" = "systemd" ]]; then - systemctl restart "bitnami.$(web_server_type).service" - else - "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/restart.sh" - fi -} - -######################## -# Reload web server -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_reload() { - if [[ "${BITNAMI_SERVICE_MANAGER:-}" = "systemd" ]]; then - systemctl reload "bitnami.$(web_server_type).service" - else - "${BITNAMI_ROOT_DIR}/scripts/$(web_server_type)/reload.sh" - fi -} - -######################## -# Ensure a web server application configuration exists (i.e. Apache virtual host format or NGINX server block) -# It serves as a wrapper for the specific web server function -# Globals: -# * -# Arguments: -# $1 - App name -# Flags: -# --type - Application type, which has an effect on which configuration template to use -# --hosts - Host listen addresses -# --server-name - Server name -# --server-aliases - Server aliases -# --allow-remote-connections - Whether to allow remote connections or to require local connections -# --disable - Whether to render server configurations with a .disabled prefix -# --disable-http - Whether to render the app's HTTP server configuration with a .disabled prefix -# --disable-https - Whether to render the app's HTTPS server configuration with a .disabled prefix -# --http-port - HTTP port number -# --https-port - HTTPS port number -# --document-root - Path to document root directory -# Apache-specific flags: -# --apache-additional-configuration - Additional vhost configuration (no default) -# --apache-additional-http-configuration - Additional HTTP vhost configuration (no default) -# --apache-additional-https-configuration - Additional HTTPS vhost configuration (no default) -# --apache-before-vhost-configuration - Configuration to add before the directive (no default) -# --apache-allow-override - Whether to allow .htaccess files (only allowed when --move-htaccess is set to 'no' and type is not defined) -# --apache-extra-directory-configuration - Extra configuration for the document root directory -# --apache-proxy-address - Address where to proxy requests -# --apache-proxy-configuration - Extra configuration for the proxy -# --apache-proxy-http-configuration - Extra configuration for the proxy HTTP vhost -# --apache-proxy-https-configuration - Extra configuration for the proxy HTTPS vhost -# --apache-move-htaccess - Move .htaccess files to a common place so they can be loaded during Apache startup (only allowed when type is not defined) -# NGINX-specific flags: -# --nginx-additional-configuration - Additional server block configuration (no default) -# --nginx-external-configuration - Configuration external to server block (no default) -# Returns: -# true if the configuration was enabled, false otherwise -######################## -ensure_web_server_app_configuration_exists() { - local app="${1:?missing app}" - shift - local -a apache_args nginx_args web_servers args_var - apache_args=("$app") - nginx_args=("$app") - # Validate arguments - while [[ "$#" -gt 0 ]]; do - case "$1" in - # Common flags - --disable \ - | --disable-http \ - | --disable-https \ - ) - apache_args+=("$1") - nginx_args+=("$1") - ;; - --hosts \ - | --server-name \ - | --server-aliases \ - | --type \ - | --allow-remote-connections \ - | --http-port \ - | --https-port \ - | --document-root \ - ) - apache_args+=("$1" "${2:?missing value}") - nginx_args+=("$1" "${2:?missing value}") - shift - ;; - - # Specific Apache flags - --apache-additional-configuration \ - | --apache-additional-http-configuration \ - | --apache-additional-https-configuration \ - | --apache-before-vhost-configuration \ - | --apache-allow-override \ - | --apache-extra-directory-configuration \ - | --apache-proxy-address \ - | --apache-proxy-configuration \ - | --apache-proxy-http-configuration \ - | --apache-proxy-https-configuration \ - | --apache-move-htaccess \ - ) - apache_args+=("${1//apache-/}" "${2:?missing value}") - shift - ;; - - # Specific NGINX flags - --nginx-additional-configuration \ - | --nginx-external-configuration) - nginx_args+=("${1//nginx-/}" "${2:?missing value}") - shift - ;; - - *) - echo "Invalid command line flag $1" >&2 - return 1 - ;; - esac - shift - done - read -r -a web_servers <<< "$(web_server_list)" - for web_server in "${web_servers[@]}"; do - args_var="${web_server}_args[@]" - web_server_execute "$web_server" "ensure_${web_server}_app_configuration_exists" "${!args_var}" - done -} - -######################## -# Ensure a web server application configuration does not exist anymore (i.e. Apache virtual host format or NGINX server block) -# It serves as a wrapper for the specific web server function -# Globals: -# * -# Arguments: -# $1 - App name -# Returns: -# true if the configuration was disabled, false otherwise -######################## -ensure_web_server_app_configuration_not_exists() { - local app="${1:?missing app}" - local -a web_servers - read -r -a web_servers <<< "$(web_server_list)" - for web_server in "${web_servers[@]}"; do - web_server_execute "$web_server" "ensure_${web_server}_app_configuration_not_exists" "$app" - done -} - -######################## -# Ensure the web server loads the configuration for an application in a URL prefix -# It serves as a wrapper for the specific web server function -# Globals: -# * -# Arguments: -# $1 - App name -# Flags: -# --allow-remote-connections - Whether to allow remote connections or to require local connections -# --document-root - Path to document root directory -# --prefix - URL prefix from where it will be accessible (i.e. /myapp) -# --type - Application type, which has an effect on what configuration template will be used -# Apache-specific flags: -# --apache-additional-configuration - Additional vhost configuration (no default) -# --apache-allow-override - Whether to allow .htaccess files (only allowed when --move-htaccess is set to 'no') -# --apache-extra-directory-configuration - Extra configuration for the document root directory -# --apache-move-htaccess - Move .htaccess files to a common place so they can be loaded during Apache startup -# NGINX-specific flags: -# --nginx-additional-configuration - Additional server block configuration (no default) -# Returns: -# true if the configuration was enabled, false otherwise -######################## -ensure_web_server_prefix_configuration_exists() { - local app="${1:?missing app}" - shift - local -a apache_args nginx_args web_servers args_var - apache_args=("$app") - nginx_args=("$app") - # Validate arguments - while [[ "$#" -gt 0 ]]; do - case "$1" in - # Common flags - --allow-remote-connections \ - | --document-root \ - | --prefix \ - | --type \ - ) - apache_args+=("$1" "${2:?missing value}") - nginx_args+=("$1" "${2:?missing value}") - shift - ;; - - # Specific Apache flags - --apache-additional-configuration \ - | --apache-allow-override \ - | --apache-extra-directory-configuration \ - | --apache-move-htaccess \ - ) - apache_args+=("${1//apache-/}" "$2") - shift - ;; - - # Specific NGINX flags - --nginx-additional-configuration) - nginx_args+=("${1//nginx-/}" "$2") - shift - ;; - - *) - echo "Invalid command line flag $1" >&2 - return 1 - ;; - esac - shift - done - read -r -a web_servers <<< "$(web_server_list)" - for web_server in "${web_servers[@]}"; do - args_var="${web_server}_args[@]" - web_server_execute "$web_server" "ensure_${web_server}_prefix_configuration_exists" "${!args_var}" - done -} - -######################## -# Ensure a web server application configuration is updated with the runtime configuration (i.e. ports) -# It serves as a wrapper for the specific web server function -# Globals: -# * -# Arguments: -# $1 - App name -# Flags: -# --hosts - Host listen addresses -# --server-name - Server name -# --server-aliases - Server aliases -# --enable-http - Enable HTTP app configuration (if not enabled already) -# --enable-https - Enable HTTPS app configuration (if not enabled already) -# --disable-http - Disable HTTP app configuration (if not disabled already) -# --disable-https - Disable HTTPS app configuration (if not disabled already) -# --http-port - HTTP port number -# --https-port - HTTPS port number -# Returns: -# true if the configuration was updated, false otherwise -######################## -web_server_update_app_configuration() { - local app="${1:?missing app}" - shift - local -a args web_servers - args=("$app") - # Validate arguments - while [[ "$#" -gt 0 ]]; do - case "$1" in - # Common flags - --enable-http \ - | --enable-https \ - | --disable-http \ - | --disable-https \ - ) - args+=("$1") - ;; - --hosts \ - | --server-name \ - | --server-aliases \ - | --http-port \ - | --https-port \ - ) - args+=("$1" "${2:?missing value}") - shift - ;; - - *) - echo "Invalid command line flag $1" >&2 - return 1 - ;; - esac - shift - done - read -r -a web_servers <<< "$(web_server_list)" - for web_server in "${web_servers[@]}"; do - web_server_execute "$web_server" "${web_server}_update_app_configuration" "${args[@]}" - done -} - -######################## -# Enable loading page, which shows users that the initialization process is not yet completed -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_enable_loading_page() { - ensure_web_server_app_configuration_exists "__loading" --hosts "_default_" \ - --apache-additional-configuration " -# Show a HTTP 503 Service Unavailable page by default -RedirectMatch 503 ^/$ -# Show index.html if server is answering with 404 Not Found or 503 Service Unavailable status codes -ErrorDocument 404 /index.html -ErrorDocument 503 /index.html" \ - --nginx-additional-configuration " -# Show a HTTP 503 Service Unavailable page by default -location / { - return 503; -} -# Show index.html if server is answering with 404 Not Found or 503 Service Unavailable status codes -error_page 404 @installing; -error_page 503 @installing; -location @installing { - rewrite ^(.*)$ /index.html break; -}" - web_server_reload -} - -######################## -# Enable loading page, which shows users that the initialization process is not yet completed -# Globals: -# * -# Arguments: -# None -# Returns: -# None -######################### -web_server_disable_install_page() { - ensure_web_server_app_configuration_not_exists "__loading" - web_server_reload -} diff --git a/rootfs/opt/bitnami/scripts/mongodb/entrypoint.sh b/rootfs/opt/bitnami/mongodb/scripts/entrypoint.sh similarity index 75% rename from rootfs/opt/bitnami/scripts/mongodb/entrypoint.sh rename to rootfs/opt/bitnami/mongodb/scripts/entrypoint.sh index dbc13b7..b995893 100755 --- a/rootfs/opt/bitnami/scripts/mongodb/entrypoint.sh +++ b/rootfs/opt/bitnami/mongodb/scripts/entrypoint.sh @@ -10,13 +10,10 @@ set -o pipefail # set -o xtrace # Uncomment this line for debugging purposes # Load libraries -. /opt/bitnami/scripts/libbitnami.sh -. /opt/bitnami/scripts/libmongodb.sh +. /opt/bitnami/mongodb/scripts/libmongodb.sh # Load environment -. /opt/bitnami/scripts/mongodb-env.sh - -print_welcome_page +. /opt/bitnami/mongodb/scripts/mongodb-env.sh # We add the copy from default config in the entrypoint to not break users # bypassing the setup.sh logic. If the file already exists do not overwrite (in @@ -24,9 +21,9 @@ print_welcome_page debug "Copying files from $MONGODB_DEFAULT_CONF_DIR to $MONGODB_CONF_DIR" cp -nr "$MONGODB_DEFAULT_CONF_DIR"/. "$MONGODB_CONF_DIR" -if [[ "$1" = "/opt/bitnami/scripts/mongodb/run.sh" ]]; then +if [[ "$1" = "/opt/bitnami/mongodb/scripts/run.sh" ]]; then info "** Starting MongoDB setup **" - /opt/bitnami/scripts/mongodb/setup.sh + /opt/bitnami/mongodb/scripts/setup.sh info "** MongoDB setup finished! **" fi diff --git a/rootfs/opt/bitnami/scripts/libmongodb.sh b/rootfs/opt/bitnami/mongodb/scripts/libmongodb.sh similarity index 100% rename from rootfs/opt/bitnami/scripts/libmongodb.sh rename to rootfs/opt/bitnami/mongodb/scripts/libmongodb.sh diff --git a/rootfs/opt/bitnami/scripts/mongodb-env.sh b/rootfs/opt/bitnami/mongodb/scripts/mongodb-env.sh similarity index 100% rename from rootfs/opt/bitnami/scripts/mongodb-env.sh rename to rootfs/opt/bitnami/mongodb/scripts/mongodb-env.sh diff --git a/rootfs/opt/bitnami/scripts/mongodb/postunpack.sh b/rootfs/opt/bitnami/mongodb/scripts/postunpack.sh similarity index 94% rename from rootfs/opt/bitnami/scripts/mongodb/postunpack.sh rename to rootfs/opt/bitnami/mongodb/scripts/postunpack.sh index 850da9a..2973428 100755 --- a/rootfs/opt/bitnami/scripts/mongodb/postunpack.sh +++ b/rootfs/opt/bitnami/mongodb/scripts/postunpack.sh @@ -12,10 +12,10 @@ set -o pipefail # Load libraries . /opt/bitnami/scripts/libfs.sh . /opt/bitnami/scripts/liblog.sh -. /opt/bitnami/scripts/libmongodb.sh +. /opt/bitnami/mongodb/scripts/libmongodb.sh # Load environment -. /opt/bitnami/scripts/mongodb-env.sh +. /opt/bitnami/mongodb/scripts/mongodb-env.sh for dir in "$MONGODB_TMP_DIR" "$MONGODB_LOG_DIR" "$MONGODB_CONF_DIR" "$MONGODB_DEFAULT_CONF_DIR" "$MONGODB_DATA_DIR" "$MONGODB_VOLUME_DIR" "$MONGODB_INITSCRIPTS_DIR"; do ensure_dir_exists "$dir" diff --git a/rootfs/opt/bitnami/scripts/mongodb/run.sh b/rootfs/opt/bitnami/mongodb/scripts/run.sh similarity index 91% rename from rootfs/opt/bitnami/scripts/mongodb/run.sh rename to rootfs/opt/bitnami/mongodb/scripts/run.sh index 926773c..de6f117 100755 --- a/rootfs/opt/bitnami/scripts/mongodb/run.sh +++ b/rootfs/opt/bitnami/mongodb/scripts/run.sh @@ -10,11 +10,11 @@ set -o pipefail # set -o xtrace # Uncomment this line for debugging purposes # Load libraries -. /opt/bitnami/scripts/libmongodb.sh +. /opt/bitnami/mongodb/scripts/libmongodb.sh . /opt/bitnami/scripts/libos.sh # Load environment -. /opt/bitnami/scripts/mongodb-env.sh +. /opt/bitnami/mongodb/scripts/mongodb-env.sh cmd=$(command -v mongod) diff --git a/rootfs/opt/bitnami/scripts/mongodb/setup.sh b/rootfs/opt/bitnami/mongodb/scripts/setup.sh similarity index 94% rename from rootfs/opt/bitnami/scripts/mongodb/setup.sh rename to rootfs/opt/bitnami/mongodb/scripts/setup.sh index 2e9e813..a880703 100755 --- a/rootfs/opt/bitnami/scripts/mongodb/setup.sh +++ b/rootfs/opt/bitnami/mongodb/scripts/setup.sh @@ -12,10 +12,10 @@ set -o pipefail # Load libraries . /opt/bitnami/scripts/libfs.sh . /opt/bitnami/scripts/libos.sh -. /opt/bitnami/scripts/libmongodb.sh +. /opt/bitnami/mongodb/scripts/libmongodb.sh # Load environment -. /opt/bitnami/scripts/mongodb-env.sh +. /opt/bitnami/mongodb/scripts/mongodb-env.sh is_boolean_yes "$MONGODB_DISABLE_SYSTEM_LOG" && MONGODB_DISABLE_SYSTEM_LOG="true" || MONGODB_DISABLE_SYSTEM_LOG="false" is_boolean_yes "$MONGODB_ENABLE_DIRECTORY_PER_DB" && MONGODB_ENABLE_DIRECTORY_PER_DB="true" || MONGODB_ENABLE_DIRECTORY_PER_DB="false" diff --git a/prebuildfs/opt/bitnami/scripts/libfile.sh b/rootfs/opt/bitnami/scripts/libfile.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/libfile.sh rename to rootfs/opt/bitnami/scripts/libfile.sh diff --git a/prebuildfs/opt/bitnami/scripts/libfs.sh b/rootfs/opt/bitnami/scripts/libfs.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/libfs.sh rename to rootfs/opt/bitnami/scripts/libfs.sh diff --git a/prebuildfs/opt/bitnami/scripts/liblog.sh b/rootfs/opt/bitnami/scripts/liblog.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/liblog.sh rename to rootfs/opt/bitnami/scripts/liblog.sh diff --git a/prebuildfs/opt/bitnami/scripts/libnet.sh b/rootfs/opt/bitnami/scripts/libnet.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/libnet.sh rename to rootfs/opt/bitnami/scripts/libnet.sh diff --git a/prebuildfs/opt/bitnami/scripts/libos.sh b/rootfs/opt/bitnami/scripts/libos.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/libos.sh rename to rootfs/opt/bitnami/scripts/libos.sh diff --git a/prebuildfs/opt/bitnami/scripts/libservice.sh b/rootfs/opt/bitnami/scripts/libservice.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/libservice.sh rename to rootfs/opt/bitnami/scripts/libservice.sh diff --git a/prebuildfs/opt/bitnami/scripts/libvalidations.sh b/rootfs/opt/bitnami/scripts/libvalidations.sh similarity index 100% rename from prebuildfs/opt/bitnami/scripts/libvalidations.sh rename to rootfs/opt/bitnami/scripts/libvalidations.sh diff --git a/prebuildfs/usr/sbin/install_packages b/rootfs/usr/sbin/install_packages similarity index 100% rename from prebuildfs/usr/sbin/install_packages rename to rootfs/usr/sbin/install_packages diff --git a/prebuildfs/usr/sbin/run-script b/rootfs/usr/sbin/run-script similarity index 100% rename from prebuildfs/usr/sbin/run-script rename to rootfs/usr/sbin/run-script