diff --git a/bitnami/redis/5.0/debian-9/Dockerfile b/bitnami/redis/5.0/debian-9/Dockerfile index 36127480727e..e4654df87ceb 100644 --- a/bitnami/redis/5.0/debian-9/Dockerfile +++ b/bitnami/redis/5.0/debian-9/Dockerfile @@ -1,4 +1,4 @@ -FROM bitnami/minideb-extras-base:stretch-r62 +FROM bitnami/minideb-extras-base:stretch-r63 LABEL maintainer "Bitnami " ENV BITNAMI_PKG_CHMOD="-R g+rwX" \ @@ -15,7 +15,7 @@ COPY rootfs / RUN /prepare.sh ENV ALLOW_EMPTY_PASSWORD="no" \ BITNAMI_APP_NAME="redis" \ - BITNAMI_IMAGE_VERSION="5.0.0-debian-9-r2" \ + BITNAMI_IMAGE_VERSION="5.0.0-debian-9-r3" \ PATH="/opt/bitnami/redis/bin:$PATH" \ REDIS_DISABLE_COMMANDS="" \ REDIS_MASTER_HOST="" \ diff --git a/bitnami/redis/5.0/debian-9/rootfs/entrypoint.sh b/bitnami/redis/5.0/debian-9/rootfs/entrypoint.sh index 1261833e39e6..a63dab120f3d 100755 --- a/bitnami/redis/5.0/debian-9/rootfs/entrypoint.sh +++ b/bitnami/redis/5.0/debian-9/rootfs/entrypoint.sh @@ -4,15 +4,22 @@ set -o errexit set -o nounset set -o pipefail #set -o xtrace +# shellcheck disable=SC1091 +# Load libraries . /libbitnami.sh -. /libredis.sh && eval "$(redis_env)" +. /libredis.sh + +# Load Redis env. variables +eval "$(redis_env)" print_welcome_page if [[ "$*" = *"/run.sh"* ]]; then + info "** Starting Redis setup **" /setup.sh + info "** Redis setup finished! **" fi - +echo "" exec "$@" diff --git a/bitnami/redis/5.0/debian-9/rootfs/libredis.sh b/bitnami/redis/5.0/debian-9/rootfs/libredis.sh index c8a8f537cad7..4bd81d49f532 100644 --- a/bitnami/redis/5.0/debian-9/rootfs/libredis.sh +++ b/bitnami/redis/5.0/debian-9/rootfs/libredis.sh @@ -1,223 +1,145 @@ -#!/bin/bash -e +#!/bin/bash +# +# Bitnami Redis library +# shellcheck disable=SC1091 + +# Load Generic Libraries . /libfile.sh . /liblog.sh . /libos.sh . /libservice.sh . /libvalidations.sh -# Echo env vars for redis global configuration. -redis_env() { - cat <<"EOF" -export REDIS_EXTRAS_DIR=/opt/bitnami/extra/redis -export REDIS_TEMPLATES_DIR=$REDIS_EXTRAS_DIR/templates -export REDIS_BASEDIR=/opt/bitnami/redis -export REDIS_VOLUME=/bitnami/redis -export REDIS_TMPDIR=$REDIS_BASEDIR/tmp -export REDIS_LOGDIR=$REDIS_BASEDIR/logs -export PATH=$REDIS_BASEDIR/bin:$PATH -export REDIS_DAEMON_USER=redis -export REDIS_DAEMON_GROUP=redis -EOF +# Functions + +######################## +# Retrieve a configuration setting value +# Globals: +# REDIS_BASEDIR +# Arguments: +# $1 - key +# Returns: +# None +######################### +redis_conf_get() { + local key="${1:?missing key}" + + grep -E "^\s*$key " "${REDIS_BASEDIR}/etc/redis.conf" | awk '{print $2}' } -# Validate settings in REDIS_* env vars. -redis_validate() { - 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() { - 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." - exit 1 - } - - for var in REDIS_MASTER_PORT_NUMBER; do - local value=${!var} - if ! err=$(validate_port "$value"); then - error "The $var environment variable is invalid: $err" - exit 1 - fi - done - if is_boolean_yes "$ALLOW_EMPTY_PASSWORD"; then - empty_password_enabled_warn - else - # Root user - if [[ -z "$REDIS_PASSWORD" ]]; then - empty_password_error REDIS_PASSWORD - fi - # Replication user - if is_redis_replica_node && [[ -z "$REDIS_MASTER_PASSWORD" ]]; then - empty_password_error REDIS_MASTER_PASSWORD - fi - fi -} - -# Ensure the redis volume is initialised. -redis_initialize() { - if [ -e "$REDIS_BASEDIR/etc/redis.conf" ]; then - if [ -e "$REDIS_BASEDIR/etc/redis-default.conf" ]; then - rm "$REDIS_BASEDIR/etc/redis-default.conf" - fi - return - fi - - for dir in "$REDIS_VOLUME/data" "$REDIS_BASEDIR/tmp" "$REDIS_LOGDIR"; do - ensure_dir_exists "$dir" - if am_i_root; then - chown "$REDIS_DAEMON_USER:$REDIS_DAEMON_GROUP" "$dir" - fi - done - - mv "$REDIS_BASEDIR/etc/redis-default.conf" "$REDIS_BASEDIR/etc/redis.conf" - - # Redis config - redis_conf_set dir "$REDIS_VOLUME/data" - # Log to stdout - redis_conf_set logfile "" - redis_conf_set pidfile "$REDIS_BASEDIR/tmp/redis.pid" - redis_conf_set daemonize yes - - # Allow remote connections - redis_conf_set bind 0.0.0.0 - - # Enable AOF https://redis.io/topics/persistence#append-only-file - # Leave default fsync (every second) - redis_conf_set appendonly yes - - # Disable RDB persistence, AOF persistence already enabled. - # Ref: https://redis.io/topics/persistence#interactions-between-aof-and-rdb-persistence - redis_conf_set save "" - - if [ -n "$REDIS_PASSWORD" ]; then - redis_conf_set requirepass "$REDIS_PASSWORD" - else - redis_conf_unset requirepass - fi - if [ -n "$REDIS_DISABLE_COMMANDS" ]; then - # The current syntax gets a comma separated list of commands, we split them - # before passing to redis_disable_unsafe_commands - redis_disable_unsafe_commands $(tr ',' ' ' <<<"$REDIS_DISABLE_COMMANDS") - fi - - if [ -n "$REDIS_REPLICATION_MODE" ]; then - redis_configure_replication - fi -} - -redis_disable_unsafe_commands() { - info "Disabling commands: $*" - for cmd in "$@"; do - if egrep -q "^\s*rename-command\s+$cmd\s+\"\"\s*$" "$REDIS_BASEDIR/etc/redis.conf" ; then - info "$cmd was already disabled" - continue - fi - cat >> "$REDIS_BASEDIR/etc/redis.conf" <> "$REDIS_BASEDIR/etc/redis.conf" + done +} + +######################## +# Ensure Redis is initialized +# Globals: +# REDIS_* +# Arguments: +# None +# Returns: +# None +######################### +redis_initialize() { + info "Initializing Redis..." + + # User injected custom configuration + if [[ -e "$REDIS_BASEDIR/etc/redis.conf" ]]; then + [[ -e "$REDIS_BASEDIR/etc/redis-default.conf" ]] && rm "${REDIS_BASEDIR}/etc/redis-default.conf" + else + debug "Ensuring expected directories/files exist..." + for dir in "${REDIS_VOLUME}/data" "${REDIS_BASEDIR}/tmp" "${REDIS_LOGDIR}"; do + ensure_dir_exists "$dir" + if am_i_root; then + chown "$REDIS_DAEMON_USER:$REDIS_DAEMON_GROUP" "$dir" + fi + done + mv "$REDIS_BASEDIR/etc/redis-default.conf" "$REDIS_BASEDIR/etc/redis.conf" + + # Redis config + debug "Setting Redis config file..." + redis_conf_set dir "${REDIS_VOLUME}/data" + redis_conf_set logfile "" # Log to stdout + redis_conf_set pidfile "${REDIS_BASEDIR}/tmp/redis.pid" + redis_conf_set daemonize yes + redis_conf_set bind 0.0.0.0 # Allow remote connections + # Enable AOF https://redis.io/topics/persistence#append-only-file + # Leave default fsync (every second) + redis_conf_set appendonly yes + # Disable RDB persistence, AOF persistence already enabled. + # Ref: https://redis.io/topics/persistence#interactions-between-aof-and-rdb-persistence + redis_conf_set save "" + if [[ -n "$REDIS_PASSWORD" ]]; then + redis_conf_set requirepass "$REDIS_PASSWORD" + else + redis_conf_unset requirepass + fi + if [[ -n "$REDIS_DISABLE_COMMANDS" ]]; then + redis_disable_unsafe_commands + fi + # Configure Replication mode + if [[ -n "$REDIS_REPLICATION_MODE" ]]; then + redis_configure_replication + fi + fi +} diff --git a/bitnami/redis/5.0/debian-9/rootfs/prepare.sh b/bitnami/redis/5.0/debian-9/rootfs/prepare.sh index 89658b81e23b..d29f6d88be6b 100755 --- a/bitnami/redis/5.0/debian-9/rootfs/prepare.sh +++ b/bitnami/redis/5.0/debian-9/rootfs/prepare.sh @@ -1,13 +1,15 @@ #!/bin/bash +# shellcheck disable=SC1091 + +# Load libraries . /libredis.sh . /libfs.sh +# Load Redis env. variables eval "$(redis_env)" -for dir in "$REDIS_VOLUME" "$REDIS_VOLUME/data" ; do +for dir in "$REDIS_VOLUME" "${REDIS_VOLUME}/data" ; do ensure_dir_exists "$dir" done - chmod -R g+rwX /bitnami "$REDIS_VOLUME" "$REDIS_BASEDIR" - diff --git a/bitnami/redis/5.0/debian-9/rootfs/run.sh b/bitnami/redis/5.0/debian-9/rootfs/run.sh index 2f2dbf36f074..72bbbd3dc7a8 100755 --- a/bitnami/redis/5.0/debian-9/rootfs/run.sh +++ b/bitnami/redis/5.0/debian-9/rootfs/run.sh @@ -3,28 +3,30 @@ set -o errexit set -o nounset set -o pipefail -#set -o xtrace +# set -o xtrace +# shellcheck disable=SC1091 -. /libredis.sh +# Load libraries . /libos.sh +. /libredis.sh + +# Load Redis env. variables eval "$(redis_env)" - -DAEMON=redis-server -EXEC=$(which $DAEMON) -ARGS="$REDIS_BASEDIR/etc/redis.conf --daemonize no $@" +# Constants REDIS_EXTRA_FLAGS=${REDIS_EXTRA_FLAGS:-} +EXEC=$(command -v redis-server) +args=("$REDIS_BASEDIR/etc/redis.conf" "--daemonize" "no" "$@") # configure extra command line flags if [[ -n "$REDIS_EXTRA_FLAGS" ]]; then warn "REDIS_EXTRA_FLAGS is deprecated. Please specify any extra-flag using '/run.sh $REDIS_EXTRA_FLAGS' as command instead" - ARGS+=" $REDIS_EXTRA_FLAGS" + ARGS+=("$REDIS_EXTRA_FLAGS") fi - -# If container is started as `root` user +info "** Starting Redis **" if am_i_root; then - exec gosu "$REDIS_DAEMON_USER" "$EXEC" $ARGS + exec gosu "$REDIS_DAEMON_USER" "$EXEC" "${args[@]}" else - exec "$EXEC" $ARGS + exec "$EXEC" "${args[@]}" fi diff --git a/bitnami/redis/5.0/debian-9/rootfs/setup.sh b/bitnami/redis/5.0/debian-9/rootfs/setup.sh index f6ccc5c913a3..4337ee2703de 100755 --- a/bitnami/redis/5.0/debian-9/rootfs/setup.sh +++ b/bitnami/redis/5.0/debian-9/rootfs/setup.sh @@ -4,23 +4,20 @@ set -o errexit set -o nounset set -o pipefail #set -o xtrace +# shellcheck disable=SC1091 +# Load libraries . /libos.sh . /libfs.sh . /libredis.sh +# Load Redis env. variables eval "$(redis_env)" -# ensure redis env var settings are valid +# Ensure Redis env. variables settings are valid redis_validate - -# ensure redis is stopped when this script ends. +# Ensure Redis is stopped when this script ends trap "redis_stop" EXIT - -if am_i_root; then - ensure_user_exists "$REDIS_DAEMON_USER" "$REDIS_DAEMON_GROUP" -fi - -# ensure redis is initialized +am_i_root && ensure_user_exists "$REDIS_DAEMON_USER" "$REDIS_DAEMON_GROUP" +# Ensure Redis is initialized redis_initialize - diff --git a/bitnami/redis/README.md b/bitnami/redis/README.md index f94f2755f233..f28dd2b59749 100644 --- a/bitnami/redis/README.md +++ b/bitnami/redis/README.md @@ -50,7 +50,7 @@ Learn more about the Bitnami tagging policy and the difference between rolling t * [`5.0-ol-7`, `5.0.0-ol-7-r2` (5.0/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-redis/blob/5.0.0-ol-7-r2/5.0/ol-7/Dockerfile) -* [`5.0-debian-9`, `5.0.0-debian-9-r2`, `5.0`, `5.0.0`, `5.0.0-r2` (5.0/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-redis/blob/5.0.0-debian-9-r2/5.0/debian-9/Dockerfile) +* [`5.0-debian-9`, `5.0.0-debian-9-r3`, `5.0`, `5.0.0`, `5.0.0-r3` (5.0/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-redis/blob/5.0.0-debian-9-r3/5.0/debian-9/Dockerfile) * [`4.0-ol-7`, `4.0.11-ol-7-r91` (4.0/ol-7/Dockerfile)](https://github.com/bitnami/bitnami-docker-redis/blob/4.0.11-ol-7-r91/4.0/ol-7/Dockerfile) * [`4.0-debian-9`, `4.0.11-debian-9-r81`, `4.0`, `4.0.11`, `4.0.11-r81`, `latest` (4.0/debian-9/Dockerfile)](https://github.com/bitnami/bitnami-docker-redis/blob/4.0.11-debian-9-r81/4.0/debian-9/Dockerfile)