mirror of
https://github.com/bitnami/containers.git
synced 2026-03-27 15:27:48 +08:00
2.2.2-debian-10-r9 release
This commit is contained in:
@@ -10,7 +10,7 @@ ENV BITNAMI_PKG_EXTRA_DIRS="/opt/bitnami/airflow/dags" \
|
||||
COPY prebuildfs /
|
||||
# Install required system packages and dependencies
|
||||
RUN install_packages acl ca-certificates curl gzip libbsd0 libbz2-1.0 libc6 libcom-err2 libcurl4 libedit2 libffi6 libgcc1 libgcrypt20 libgmp10 libgnutls30 libgpg-error0 libgssapi-krb5-2 libhogweed4 libicu63 libidn2-0 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libldap-2.4-2 liblzma5 libmariadb3 libncursesw6 libnettle6 libnghttp2-14 libp11-kit0 libpsl5 libreadline7 librtmp1 libsasl2-2 libsqlite3-0 libssh2-1 libssl1.1 libstdc++6 libtasn1-6 libtinfo6 libunistring2 libuuid1 libxml2 libxslt1.1 locales netbase procps tar zlib1g
|
||||
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "wait-for-port" "1.0.1-1" --checksum 28dc75dff64df07e67b711d20859c24ebc996db0eaac06138553341d0f769299
|
||||
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "wait-for-port" "1.0.1-3" --checksum 9e18c6c3411e702eb16aa60dc77baf3fd9af8d5beb2623936ef3af343d5ffd5b
|
||||
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "python" "3.8.12-5" --checksum 18aaf8247baa258f4e16de86673a3e799cd50bbef2824f0d2ae805c9c2068f11
|
||||
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "postgresql-client" "10.19.0-0" --checksum f32958c288efd50fb29133d614ce19dc46ff40add10fc82254b29c8a46df324c
|
||||
RUN . /opt/bitnami/scripts/libcomponent.sh && component_unpack "ini-file" "1.4.1-0" --checksum 3d189e4b1fcdc330fb84c14a7c6fb296deff37d3142d9a17fe0c9a5dba51ef6d
|
||||
@@ -28,7 +28,7 @@ RUN /opt/bitnami/scripts/airflow/postunpack.sh
|
||||
RUN /opt/bitnami/scripts/locales/add-extra-locales.sh
|
||||
ENV AIRFLOW_HOME="/opt/bitnami/airflow" \
|
||||
BITNAMI_APP_NAME="airflow" \
|
||||
BITNAMI_IMAGE_VERSION="2.2.2-debian-10-r8" \
|
||||
BITNAMI_IMAGE_VERSION="2.2.2-debian-10-r9" \
|
||||
LANG="en_US.UTF-8" \
|
||||
LANGUAGE="en_US:en" \
|
||||
LD_LIBRARY_PATH="/opt/bitnami/python/lib/:/opt/bitnami/airflow/venv/lib/python3.8/site-packages/numpy.libs/:$LD_LIBRARY_PATH" \
|
||||
@@ -36,7 +36,14 @@ ENV AIRFLOW_HOME="/opt/bitnami/airflow" \
|
||||
LNAME="airflow" \
|
||||
NSS_WRAPPER_GROUP="/opt/bitnami/airflow/nss_group" \
|
||||
NSS_WRAPPER_PASSWD="/opt/bitnami/airflow/nss_passwd" \
|
||||
PATH="/opt/bitnami/common/bin:/opt/bitnami/python/bin:/opt/bitnami/postgresql/bin:/opt/bitnami/git/bin:/opt/bitnami/airflow/venv/bin:$PATH"
|
||||
PATH="/opt/bitnami/common/bin:/opt/bitnami/python/bin:/opt/bitnami/postgresql/bin:/opt/bitnami/git/bin:/opt/bitnami/airflow/venv/bin:$PATH" \
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_NAME="" \
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD="" \
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME="" \
|
||||
POSTGRESQL_HOST="postgresql" \
|
||||
POSTGRESQL_PORT_NUMBER="5432" \
|
||||
POSTGRESQL_ROOT_PASSWORD="" \
|
||||
POSTGRESQL_ROOT_USER="postgres"
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@
|
||||
},
|
||||
"wait-for-port": {
|
||||
"arch": "amd64",
|
||||
"digest": "28dc75dff64df07e67b711d20859c24ebc996db0eaac06138553341d0f769299",
|
||||
"digest": "9e18c6c3411e702eb16aa60dc77baf3fd9af8d5beb2623936ef3af343d5ffd5b",
|
||||
"distro": "debian-10",
|
||||
"type": "NAMI",
|
||||
"version": "1.0.1-1"
|
||||
"version": "1.0.1-3"
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ fi
|
||||
|
||||
if [[ "$*" = *"/opt/bitnami/scripts/airflow/run.sh"* || "$*" = *"/run.sh"* ]]; then
|
||||
info "** Starting Airflow setup **"
|
||||
/opt/bitnami/scripts/postgresql-client/setup.sh
|
||||
/opt/bitnami/scripts/airflow/setup.sh
|
||||
info "** Airflow setup finished! **"
|
||||
fi
|
||||
|
||||
@@ -10,6 +10,13 @@ set -o pipefail
|
||||
# Load Airflow environment variables
|
||||
. /opt/bitnami/scripts/airflow-env.sh
|
||||
|
||||
# Load PostgreSQL Client environment for 'postgresql_remote_execute' (after 'airflow-env.sh' so that MODULE is not set to a wrong value)
|
||||
if [[ -f /opt/bitnami/scripts/postgresql-client-env.sh ]]; then
|
||||
. /opt/bitnami/scripts/postgresql-client-env.sh
|
||||
elif [[ -f /opt/bitnami/scripts/postgresql-env.sh ]]; then
|
||||
. /opt/bitnami/scripts/postgresql-env.sh
|
||||
fi
|
||||
|
||||
# Load libraries
|
||||
. /opt/bitnami/scripts/libos.sh
|
||||
. /opt/bitnami/scripts/libfs.sh
|
||||
|
||||
@@ -13,6 +13,13 @@
|
||||
. /opt/bitnami/scripts/libvalidations.sh
|
||||
. /opt/bitnami/scripts/libpersistence.sh
|
||||
|
||||
# Load database library
|
||||
if [[ -f /opt/bitnami/scripts/libpostgresqlclient.sh ]]; then
|
||||
. /opt/bitnami/scripts/libpostgresqlclient.sh
|
||||
elif [[ -f /opt/bitnami/scripts/libpostgresql.sh ]]; then
|
||||
. /opt/bitnami/scripts/libpostgresql.sh
|
||||
fi
|
||||
|
||||
# Functions
|
||||
|
||||
########################
|
||||
@@ -103,13 +110,15 @@ airflow_initialize() {
|
||||
|
||||
# Check if Airflow has already been initialized and persisted in a previous run
|
||||
local -r app_name="airflow"
|
||||
local -a postgresql_remote_execute_args=("$AIRFLOW_DATABASE_HOST" "$AIRFLOW_DATABASE_PORT_NUMBER" "$AIRFLOW_DATABASE_NAME" "$AIRFLOW_DATABASE_USERNAME" "$AIRFLOW_DATABASE_PASSWORD")
|
||||
if ! is_app_initialized "$app_name"; then
|
||||
# Delete pid file
|
||||
rm -f "$AIRFLOW_PID_FILE"
|
||||
|
||||
airflow_wait_for_postgresql "$AIRFLOW_DATABASE_HOST" "$AIRFLOW_DATABASE_PORT_NUMBER"
|
||||
|
||||
# Initialize database
|
||||
info "Trying to connect to the database server"
|
||||
airflow_wait_for_postgresql_connection "${postgresql_remote_execute_args[@]}"
|
||||
info "Populating database"
|
||||
airflow_execute_command "initdb" "db init"
|
||||
|
||||
airflow_create_admin_user
|
||||
@@ -119,13 +128,13 @@ airflow_initialize() {
|
||||
info "Persisting Airflow installation"
|
||||
persist_app "$app_name" "$AIRFLOW_DATA_TO_PERSIST"
|
||||
else
|
||||
# Check database connection
|
||||
airflow_wait_for_postgresql "$AIRFLOW_DATABASE_HOST" "$AIRFLOW_DATABASE_PORT_NUMBER"
|
||||
|
||||
# Restore persisted data
|
||||
info "Restoring persisted Airflow installation"
|
||||
restore_persisted_app "$app_name" "$AIRFLOW_DATA_TO_PERSIST"
|
||||
|
||||
info "Trying to connect to the database server"
|
||||
airflow_wait_for_postgresql_connection "${postgresql_remote_execute_args[@]}"
|
||||
|
||||
# Upgrade database
|
||||
airflow_execute_command "upgradedb" "db upgrade"
|
||||
|
||||
@@ -313,7 +322,7 @@ airflow_webserver_conf_set() {
|
||||
|
||||
local -r file="$AIRFLOW_WEBSERVER_CONF_FILE"
|
||||
local entry
|
||||
is_boolean_yes "$is_literal" && entry="${key} = ${value}" || entry="${key} = '${value}'"
|
||||
is_boolean_yes "$is_literal" && entry="${key} = '${value}'" || entry="${key} = ${value}"
|
||||
# Check if the value was set before
|
||||
if grep -q "^#*\\s*${key} =.*$" "$file"; then
|
||||
# Update the existing key
|
||||
@@ -403,18 +412,31 @@ airflow_configure_celery_executor() {
|
||||
}
|
||||
|
||||
########################
|
||||
# Wait for PostgreSQL
|
||||
# Wait until the database is accessible with the currently-known credentials
|
||||
# Globals:
|
||||
# *
|
||||
# Arguments:
|
||||
# None
|
||||
# $1 - database host
|
||||
# $2 - database port
|
||||
# $3 - database name
|
||||
# $4 - database username
|
||||
# $5 - database user password (optional)
|
||||
# Returns:
|
||||
# None
|
||||
# true if the database connection succeeded, false otherwise
|
||||
#########################
|
||||
airflow_wait_for_postgresql() {
|
||||
local -r postgresql_host="${1?Missing host}"
|
||||
local -r postgresql_port="${2?Missing port}"
|
||||
|
||||
info "Waiting for PostgreSQL to be available at ${postgresql_host}:${postgresql_port}..."
|
||||
wait-for-port --host "$postgresql_host" "$postgresql_port"
|
||||
airflow_wait_for_postgresql_connection() {
|
||||
local -r db_host="${1:?missing database host}"
|
||||
local -r db_port="${2:?missing database port}"
|
||||
local -r db_name="${3:?missing database name}"
|
||||
local -r db_user="${4:?missing database user}"
|
||||
local -r db_pass="${5:-}"
|
||||
check_postgresql_connection() {
|
||||
echo "SELECT 1" | postgresql_remote_execute "$db_host" "$db_port" "$db_name" "$db_user" "$db_pass"
|
||||
}
|
||||
if ! retry_while "check_postgresql_connection"; then
|
||||
error "Could not connect to the database"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
|
||||
@@ -0,0 +1,408 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Bitnami PostgreSQL Client library
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
# Load Generic Libraries
|
||||
. /opt/bitnami/scripts/liblog.sh
|
||||
. /opt/bitnami/scripts/libos.sh
|
||||
. /opt/bitnami/scripts/libvalidations.sh
|
||||
|
||||
########################
|
||||
# Validate settings in POSTGRESQL_CLIENT_* environment variables
|
||||
# Globals:
|
||||
# POSTGRESQL_CLIENT_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_client_validate() {
|
||||
info "Validating settings in POSTGRESQL_CLIENT_* env vars"
|
||||
local error_code=0
|
||||
|
||||
# Auxiliary functions
|
||||
print_validation_error() {
|
||||
error "$1"
|
||||
error_code=1
|
||||
}
|
||||
|
||||
empty_password_enabled_warn() {
|
||||
warn "You set the environment variable ALLOW_EMPTY_PASSWORD=${ALLOW_EMPTY_PASSWORD}. For safety reasons, do not use this flag in a production environment."
|
||||
}
|
||||
empty_password_error() {
|
||||
print_validation_error "The $1 environment variable is empty or not set. Set the environment variable ALLOW_EMPTY_PASSWORD=yes to allow the container to be started with blank passwords. This is recommended only for development."
|
||||
}
|
||||
|
||||
# Only validate environment variables if any action needs to be performed
|
||||
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" || -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAME" ]]; then
|
||||
if is_boolean_yes "$ALLOW_EMPTY_PASSWORD"; then
|
||||
empty_password_enabled_warn
|
||||
else
|
||||
if [[ -z "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
|
||||
fi
|
||||
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" ]] && [[ -z "$POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD" ]]; then
|
||||
empty_password_error "POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# When enabling extensions, the DB name must be provided
|
||||
local -a extensions
|
||||
read -r -a extensions <<< "$(tr ',;' ' ' <<< "$POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS")"
|
||||
if [[ -z "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAME" && "${#extensions[@]}" -gt 0 ]]; then
|
||||
print_validation_error "POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS requires POSTGRESQL_CLIENT_CREATE_DATABASE_NAME to be set."
|
||||
fi
|
||||
return "$error_code"
|
||||
}
|
||||
|
||||
########################
|
||||
# Perform actions to a database
|
||||
# Globals:
|
||||
# POSTGRESQL_CLIENT_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_client_initialize() {
|
||||
# Wait for the database to be accessible if any action needs to be performed
|
||||
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" || -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAME" ]]; then
|
||||
info "Trying to connect to the database server"
|
||||
check_postgresql_connection() {
|
||||
echo "SELECT 1" | postgresql_remote_execute "$POSTGRESQL_CLIENT_DATABASE_HOST" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER" "postgres" "$POSTGRESQL_CLIENT_POSTGRES_USER" "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
|
||||
}
|
||||
if ! retry_while "check_postgresql_connection"; then
|
||||
error "Could not connect to the database server"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
# Ensure a database user exists in the server
|
||||
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" ]]; then
|
||||
info "Creating database user ${POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME}"
|
||||
local -a args=("$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" "--host" "$POSTGRESQL_CLIENT_DATABASE_HOST" "--port" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER")
|
||||
[[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD" ]] && args+=("-p" "$POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD")
|
||||
postgresql_ensure_user_exists "${args[@]}"
|
||||
fi
|
||||
# Ensure a database exists in the server (and that the user has write privileges, if specified)
|
||||
if [[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAME" ]]; then
|
||||
info "Creating database ${POSTGRESQL_CLIENT_CREATE_DATABASE_NAME}"
|
||||
local -a createdb_args=("$POSTGRESQL_CLIENT_CREATE_DATABASE_NAME" "--host" "$POSTGRESQL_CLIENT_DATABASE_HOST" "--port" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER")
|
||||
[[ -n "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME" ]] && createdb_args+=("-u" "$POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME")
|
||||
postgresql_ensure_database_exists "${createdb_args[@]}"
|
||||
# Ensure the list of extensions are enabled in the specified database
|
||||
local -a extensions
|
||||
read -r -a extensions <<< "$(tr ',;' ' ' <<< "$POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS")"
|
||||
if [[ "${#extensions[@]}" -gt 0 ]]; then
|
||||
for extension_to_create in "${extensions[@]}"; do
|
||||
echo "CREATE EXTENSION IF NOT EXISTS ${extension_to_create}" | postgresql_remote_execute "$POSTGRESQL_CLIENT_DATABASE_HOST" "$POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER" "$POSTGRESQL_CLIENT_CREATE_DATABASE_NAME" "$POSTGRESQL_CLIENT_POSTGRES_USER" "$POSTGRESQL_CLIENT_POSTGRES_PASSWORD"
|
||||
done
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Return PostgreSQL major version
|
||||
# Globals:
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# String
|
||||
#########################
|
||||
postgresql_get_major_version() {
|
||||
psql --version | grep -oE "[0-9]+\.[0-9]+" | grep -oE "^[0-9]+"
|
||||
}
|
||||
|
||||
########################
|
||||
# Gets an environment variable name based on the suffix
|
||||
# Arguments:
|
||||
# $1 - environment variable suffix
|
||||
# Returns:
|
||||
# environment variable name
|
||||
#########################
|
||||
get_env_var_value() {
|
||||
local env_var_suffix="${1:?missing suffix}"
|
||||
local env_var_name
|
||||
for env_var_prefix in POSTGRESQL POSTGRESQL_CLIENT; do
|
||||
env_var_name="${env_var_prefix}_${env_var_suffix}"
|
||||
if [[ -n "${!env_var_name:-}" ]]; then
|
||||
echo "${!env_var_name}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
########################
|
||||
# Execute an arbitrary query/queries against the running PostgreSQL service and print the output
|
||||
# Stdin:
|
||||
# Query/queries to execute
|
||||
# Globals:
|
||||
# BITNAMI_DEBUG
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# $1 - Database where to run the queries
|
||||
# $2 - User to run queries
|
||||
# $3 - Password
|
||||
# $4 - Extra options (eg. -tA)
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_execute_print_output() {
|
||||
local -r db="${1:-}"
|
||||
local -r user="${2:-postgres}"
|
||||
local -r pass="${3:-}"
|
||||
local opts
|
||||
read -r -a opts <<<"${@:4}"
|
||||
|
||||
local args=("-U" "$user")
|
||||
[[ -n "$db" ]] && args+=("-d" "$db")
|
||||
[[ "${#opts[@]}" -gt 0 ]] && args+=("${opts[@]}")
|
||||
|
||||
# Obtain the command specified via stdin
|
||||
local sql_cmd
|
||||
sql_cmd="$(</dev/stdin)"
|
||||
debug "Executing SQL command:\n$sql_cmd"
|
||||
PGPASSWORD=$pass psql "${args[@]}" <<<"$sql_cmd"
|
||||
}
|
||||
|
||||
########################
|
||||
# Execute an arbitrary query/queries against the running PostgreSQL service
|
||||
# Stdin:
|
||||
# Query/queries to execute
|
||||
# Globals:
|
||||
# BITNAMI_DEBUG
|
||||
# POSTGRESQL_*
|
||||
# Arguments:
|
||||
# $1 - Database where to run the queries
|
||||
# $2 - User to run queries
|
||||
# $3 - Password
|
||||
# $4 - Extra options (eg. -tA)
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_execute() {
|
||||
if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then
|
||||
"postgresql_execute_print_output" "$@"
|
||||
elif [[ "${NO_ERRORS:-false}" = true ]]; then
|
||||
"postgresql_execute_print_output" "$@" 2>/dev/null
|
||||
else
|
||||
"postgresql_execute_print_output" "$@" >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Execute an arbitrary query/queries against a remote PostgreSQL service and print to stdout
|
||||
# Stdin:
|
||||
# Query/queries to execute
|
||||
# Globals:
|
||||
# BITNAMI_DEBUG
|
||||
# DB_*
|
||||
# Arguments:
|
||||
# $1 - Remote PostgreSQL service hostname
|
||||
# $2 - Remote PostgreSQL service port
|
||||
# $3 - Database where to run the queries
|
||||
# $4 - User to run queries
|
||||
# $5 - Password
|
||||
# $6 - Extra options (eg. -tA)
|
||||
# Returns:
|
||||
# None
|
||||
postgresql_remote_execute_print_output() {
|
||||
local -r hostname="${1:?hostname is required}"
|
||||
local -r port="${2:?port is required}"
|
||||
local -a args=("-h" "$hostname" "-p" "$port")
|
||||
shift 2
|
||||
"postgresql_execute_print_output" "$@" "${args[@]}"
|
||||
}
|
||||
|
||||
########################
|
||||
# Execute an arbitrary query/queries against a remote PostgreSQL service
|
||||
# Stdin:
|
||||
# Query/queries to execute
|
||||
# Globals:
|
||||
# BITNAMI_DEBUG
|
||||
# DB_*
|
||||
# Arguments:
|
||||
# $1 - Remote PostgreSQL service hostname
|
||||
# $2 - Remote PostgreSQL service port
|
||||
# $3 - Database where to run the queries
|
||||
# $4 - User to run queries
|
||||
# $5 - Password
|
||||
# $6 - Extra options (eg. -tA)
|
||||
# Returns:
|
||||
# None
|
||||
postgresql_remote_execute() {
|
||||
if [[ "${BITNAMI_DEBUG:-false}" = true ]]; then
|
||||
"postgresql_remote_execute_print_output" "$@"
|
||||
elif [[ "${NO_ERRORS:-false}" = true ]]; then
|
||||
"postgresql_remote_execute_print_output" "$@" 2>/dev/null
|
||||
else
|
||||
"postgresql_remote_execute_print_output" "$@" >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
########################
|
||||
# Optionally create the given database user
|
||||
# Flags:
|
||||
# -p|--password - database password
|
||||
# --host - database host
|
||||
# --port - database port
|
||||
# Arguments:
|
||||
# $1 - user
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_ensure_user_exists() {
|
||||
local -r user="${1:?user is missing}"
|
||||
local password=""
|
||||
# For accessing an external database
|
||||
local db_host=""
|
||||
local db_port=""
|
||||
|
||||
# Validate arguments
|
||||
shift 1
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-p | --password)
|
||||
shift
|
||||
password="${1:?missing password}"
|
||||
;;
|
||||
--host)
|
||||
shift
|
||||
db_host="${1:?missing database host}"
|
||||
;;
|
||||
--port)
|
||||
shift
|
||||
db_port="${1:?missing database port}"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid command line flag $1" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
local -a postgresql_execute_cmd=("postgresql_execute")
|
||||
[[ -n "$db_host" && -n "$db_port" ]] && postgresql_execute_cmd=("postgresql_remote_execute" "$db_host" "$db_port")
|
||||
local -a postgresql_execute_flags=("postgres" "$(get_env_var_value POSTGRES_USER)" "$(get_env_var_value POSTGRES_PASSWORD)")
|
||||
|
||||
"${postgresql_execute_cmd[@]}" "${postgresql_execute_flags[@]}" <<EOF
|
||||
DO
|
||||
\$do\$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT FROM pg_catalog.pg_roles WHERE rolname = '${user}'
|
||||
) THEN
|
||||
CREATE ROLE "${user}" LOGIN PASSWORD '${password}';
|
||||
END IF;
|
||||
END
|
||||
\$do\$;
|
||||
EOF
|
||||
}
|
||||
|
||||
########################
|
||||
# Ensure a user has all privileges to access a database
|
||||
# Arguments:
|
||||
# $1 - database name
|
||||
# $2 - database user
|
||||
# $3 - database host (optional)
|
||||
# $4 - database port (optional)
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_ensure_user_has_database_privileges() {
|
||||
local -r user="${1:?user is required}"
|
||||
local -r database="${2:?db is required}"
|
||||
local -r db_host="${3:-}"
|
||||
local -r db_port="${4:-}"
|
||||
|
||||
local -a postgresql_execute_cmd=("postgresql_execute")
|
||||
[[ -n "$db_host" && -n "$db_port" ]] && postgresql_execute_cmd=("postgresql_remote_execute" "$db_host" "$db_port")
|
||||
local -a postgresql_execute_flags=("postgres" "$(get_env_var_value POSTGRES_USER)" "$(get_env_var_value POSTGRES_PASSWORD)")
|
||||
|
||||
debug "Providing privileges to username ${user} on database ${database}"
|
||||
"${postgresql_execute_cmd[@]}" "${postgresql_execute_flags[@]}" <<EOF
|
||||
GRANT ALL PRIVILEGES ON DATABASE "${database}" TO "${user}";
|
||||
ALTER DATABASE "${database}" OWNER TO "${user}";
|
||||
EOF
|
||||
}
|
||||
|
||||
########################
|
||||
# Optionally create the given database, and then optionally give a user
|
||||
# full privileges on the database.
|
||||
# Flags:
|
||||
# -u|--user - database user
|
||||
# --host - database host
|
||||
# --port - database port
|
||||
# Arguments:
|
||||
# $1 - database name
|
||||
# Returns:
|
||||
# None
|
||||
#########################
|
||||
postgresql_ensure_database_exists() {
|
||||
local -r database="${1:?database is missing}"
|
||||
local user=""
|
||||
# For accessing an external database
|
||||
local db_host=""
|
||||
local db_port=""
|
||||
|
||||
# Validate arguments
|
||||
shift 1
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
-u | --user)
|
||||
shift
|
||||
user="${1:?missing database user}"
|
||||
;;
|
||||
--host)
|
||||
shift
|
||||
db_host="${1:?missing database host}"
|
||||
;;
|
||||
--port)
|
||||
shift
|
||||
db_port="${1:?missing database port}"
|
||||
;;
|
||||
*)
|
||||
echo "Invalid command line flag $1" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
local -a postgresql_execute_cmd=("postgresql_execute")
|
||||
[[ -n "$db_host" && -n "$db_port" ]] && postgresql_execute_cmd=("postgresql_remote_execute" "$db_host" "$db_port")
|
||||
local -a postgresql_execute_flags=("postgres" "$(get_env_var_value POSTGRES_USER)" "$(get_env_var_value POSTGRES_PASSWORD)")
|
||||
|
||||
"${postgresql_execute_cmd[@]}" "${postgresql_execute_flags[@]}" <<EOF
|
||||
SELECT 'CREATE DATABASE "${database}"'
|
||||
WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '${database}')\gexec
|
||||
EOF
|
||||
if [[ -n "$user" ]]; then
|
||||
local -a grant_flags=("$user" "$database")
|
||||
[[ -n "$db_host" ]] && grant_flags+=("$db_host")
|
||||
[[ -n "$db_port" ]] && grant_flags+=("$db_port")
|
||||
postgresql_ensure_user_has_database_privileges "${grant_flags[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
########################
|
||||
# Retrieves the WAL directory in use by PostgreSQL / to use if not initialized yet
|
||||
# Globals:
|
||||
# REPMGR_*
|
||||
# Arguments:
|
||||
# None
|
||||
# Returns:
|
||||
# the path to the WAL directory, or empty if not set
|
||||
#########################
|
||||
postgresql_get_waldir() {
|
||||
if [[ -L "${POSTGRESQL_DATA_DIR}/pg_wal" && -d "${POSTGRESQL_DATA_DIR}/pg_wal" ]]; then
|
||||
readlink -f "${POSTGRESQL_DATA_DIR}/pg_wal"
|
||||
else
|
||||
# Uninitialized - using value from $POSTGRESQL_INITDB_WAL_DIR if set
|
||||
echo "$POSTGRESQL_INITDB_WAL_DIR"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Environment configuration for postgresql-client
|
||||
|
||||
# The values for all environment variables will be set in the below order of precedence
|
||||
# 1. Custom environment variables defined below after Bitnami defaults
|
||||
# 2. Constants defined in this file (environment variables with no default), i.e. BITNAMI_ROOT_DIR
|
||||
# 3. Environment variables overridden via external files using *_FILE variables (see below)
|
||||
# 4. Environment variables set externally (i.e. current Bash context/Dockerfile/userdata)
|
||||
|
||||
# Load logging library
|
||||
. /opt/bitnami/scripts/liblog.sh
|
||||
|
||||
export BITNAMI_ROOT_DIR="/opt/bitnami"
|
||||
export BITNAMI_VOLUME_DIR="/bitnami"
|
||||
|
||||
# Logging configuration
|
||||
export MODULE="${MODULE:-postgresql-client}"
|
||||
export BITNAMI_DEBUG="${BITNAMI_DEBUG:-false}"
|
||||
|
||||
# By setting an environment variable matching *_FILE to a file path, the prefixed environment
|
||||
# variable will be overridden with the value specified in that file
|
||||
postgresql_client_env_vars=(
|
||||
ALLOW_EMPTY_PASSWORD
|
||||
POSTGRESQL_CLIENT_DATABASE_HOST
|
||||
POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER
|
||||
POSTGRESQL_CLIENT_POSTGRES_USER
|
||||
POSTGRESQL_CLIENT_POSTGRES_PASSWORD
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_NAME
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS
|
||||
POSTGRESQL_HOST
|
||||
POSTGRESQL_PORT_NUMBER
|
||||
POSTGRESQL_CLIENT_ROOT_USER
|
||||
POSTGRESQL_POSTGRES_USER
|
||||
POSTGRESQL_ROOT_USER
|
||||
POSTGRESQL_CLIENT_ROOT_PASSWORD
|
||||
POSTGRESQL_POSTGRES_PASSWORD
|
||||
POSTGRESQL_ROOT_PASSWORD
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_USER
|
||||
)
|
||||
for env_var in "${postgresql_client_env_vars[@]}"; do
|
||||
file_env_var="${env_var}_FILE"
|
||||
if [[ -n "${!file_env_var:-}" ]]; then
|
||||
if [[ -r "${!file_env_var:-}" ]]; then
|
||||
export "${env_var}=$(< "${!file_env_var}")"
|
||||
unset "${file_env_var}"
|
||||
else
|
||||
warn "Skipping export of '${env_var}'. '${!file_env_var:-}' is not readable."
|
||||
fi
|
||||
fi
|
||||
done
|
||||
unset postgresql_client_env_vars
|
||||
|
||||
# Paths
|
||||
export POSTGRESQL_BASE_DIR="/opt/bitnami/postgresql"
|
||||
export POSTGRESQL_BIN_DIR="$POSTGRESQL_BASE_DIR/bin"
|
||||
export PATH="${POSTGRESQL_BIN_DIR}:${PATH}"
|
||||
|
||||
# PostgreSQL settings
|
||||
export ALLOW_EMPTY_PASSWORD="${ALLOW_EMPTY_PASSWORD:-no}"
|
||||
POSTGRESQL_CLIENT_DATABASE_HOST="${POSTGRESQL_CLIENT_DATABASE_HOST:-"${POSTGRESQL_HOST:-}"}"
|
||||
export POSTGRESQL_CLIENT_DATABASE_HOST="${POSTGRESQL_CLIENT_DATABASE_HOST:-postgresql}"
|
||||
POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER="${POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER:-"${POSTGRESQL_PORT_NUMBER:-}"}"
|
||||
export POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER="${POSTGRESQL_CLIENT_DATABASE_PORT_NUMBER:-5432}"
|
||||
POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-"${POSTGRESQL_CLIENT_ROOT_USER:-}"}"
|
||||
POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-"${POSTGRESQL_POSTGRES_USER:-}"}"
|
||||
POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-"${POSTGRESQL_ROOT_USER:-}"}"
|
||||
export POSTGRESQL_CLIENT_POSTGRES_USER="${POSTGRESQL_CLIENT_POSTGRES_USER:-postgres}" # only used during the first initialization
|
||||
POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-"${POSTGRESQL_CLIENT_ROOT_PASSWORD:-}"}"
|
||||
POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-"${POSTGRESQL_POSTGRES_PASSWORD:-}"}"
|
||||
POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-"${POSTGRESQL_ROOT_PASSWORD:-}"}"
|
||||
export POSTGRESQL_CLIENT_POSTGRES_PASSWORD="${POSTGRESQL_CLIENT_POSTGRES_PASSWORD:-}" # only used during the first initialization
|
||||
export POSTGRESQL_CLIENT_CREATE_DATABASE_NAME="${POSTGRESQL_CLIENT_CREATE_DATABASE_NAME:-}" # only used during the first initialization
|
||||
POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME="${POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME:-"${POSTGRESQL_CLIENT_CREATE_DATABASE_USER:-}"}"
|
||||
export POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME="${POSTGRESQL_CLIENT_CREATE_DATABASE_USERNAME:-}" # only used during the first initialization
|
||||
export POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD="${POSTGRESQL_CLIENT_CREATE_DATABASE_PASSWORD:-}" # only used during the first initialization
|
||||
export POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS="${POSTGRESQL_CLIENT_CREATE_DATABASE_EXTENSIONS:-}" # only used during the first initialization
|
||||
|
||||
# Custom environment variables may be defined below
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# shellcheck disable=SC1091
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
# set -o xtrace # Uncomment this line for debugging purposes
|
||||
|
||||
# Load libraries
|
||||
. /opt/bitnami/scripts/libpostgresqlclient.sh
|
||||
|
||||
# Load PostgreSQL Client environment variables
|
||||
. /opt/bitnami/scripts/postgresql-client-env.sh
|
||||
|
||||
# Ensure PostgreSQL Client environment variables settings are valid
|
||||
postgresql_client_validate
|
||||
# Ensure PostgreSQL Client is initialized
|
||||
postgresql_client_initialize
|
||||
@@ -37,7 +37,7 @@ $ docker-compose up
|
||||
Learn more about the Bitnami tagging policy and the difference between rolling tags and immutable tags [in our documentation page](https://docs.bitnami.com/tutorials/understand-rolling-tags-containers/).
|
||||
|
||||
|
||||
* [`2`, `2-debian-10`, `2.2.2`, `2.2.2-debian-10-r8`, `latest` (2/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-airflow/blob/2.2.2-debian-10-r8/2/debian-10/Dockerfile)
|
||||
* [`2`, `2-debian-10`, `2.2.2`, `2.2.2-debian-10-r9`, `latest` (2/debian-10/Dockerfile)](https://github.com/bitnami/bitnami-docker-airflow/blob/2.2.2-debian-10-r9/2/debian-10/Dockerfile)
|
||||
|
||||
Subscribe to project updates by watching the [bitnami/airflow GitHub repo](https://github.com/bitnami/bitnami-docker-airflow).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user