From 5c5c7946bcb8ecee002c69c68c5bedb0b8130bf6 Mon Sep 17 00:00:00 2001 From: iamabhishek-dubey Date: Wed, 18 Mar 2020 23:14:11 +0530 Subject: [PATCH] Changed image architecture --- Dockerfile | 11 +++++++++-- entrypoint.sh | 23 +++++------------------ redis.conf | 8 ++++++++ run.sh | 18 ++++++++++++++++++ 4 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 redis.conf create mode 100755 run.sh diff --git a/Dockerfile b/Dockerfile index c26785f..9fe0799 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,7 @@ ARG REDIS_DOWNLOAD_URL="http://download.redis.io/" ARG REDIS_VERSION="stable" -RUN addgroup -S -g 1000 redis && adduser -S -G redis -u 999 redis && \ +RUN addgroup -S -g 1001 redis && adduser -S -G redis -u 1001 redis && \ apk add --no-cache su-exec tzdata make curl build-base linux-headers bash RUN curl -fL -Lo /tmp/redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_VERSION}.tar.gz && \ @@ -21,14 +21,21 @@ RUN curl -fL -Lo /tmp/redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis- make install && \ mkdir -p /etc/redis && \ cp -f *.conf /etc/redis && \ - rm -rf /tmp/redis-${REDIS_VERSION}* + rm -rf /tmp/redis-${REDIS_VERSION}* && \ + apk del curl make + +COPY redis.conf /etc/redis/redis.conf COPY entrypoint.sh /usr/bin/entrypoint.sh +COPY run.sh /usr/bin/run.sh + VOLUME ["/data"] WORKDIR /data +USER redis + EXPOSE 6379 ENTRYPOINT ["/usr/bin/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 47668cc..8f4dbb0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,22 +1,9 @@ #!/bin/bash -set -eu - -generate_common_config() { - { - echo "bind 0.0.0.0" - echo protected-mode yes - echo tcp-backlog 511 - echo timeout 0 - echo tcp-keepalive 300 - echo daemonize no - echo supervised no - echo pidfile /var/run/redis.pid - } > /etc/redis/redis.conf -} +set -ex set_redis_password() { - if [ -z "${REDIS_PASSWORD}" ]; then + if [[ -z "${REDIS_PASSWORD}" ]]; then echo "Redis is running without password which is not recommended" else { @@ -27,7 +14,7 @@ set_redis_password() { } redis_mode_setup() { - if [ "${SETUP_MODE}" = "cluster" ]; then + if [[ "${SETUP_MODE}" == "cluster" ]]; then { echo cluster-enabled yes echo cluster-config-file nodes.conf @@ -39,15 +26,15 @@ redis_mode_setup() { } start_redis() { - echo "Starting redis service " + echo "Starting redis service....." redis-server /etc/redis/redis.conf } main_function() { - generate_common_config set_redis_password redis_mode_setup start_redis + redis_server_mode } main_function diff --git a/redis.conf b/redis.conf new file mode 100644 index 0000000..ddfa540 --- /dev/null +++ b/redis.conf @@ -0,0 +1,8 @@ +bind 0.0.0.0 +protected-mode yes +tcp-backlog 511 +timeout 0 +tcp-keepalive 300 +daemonize no +supervised no +pidfile /var/run/redis.pid diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..03bb794 --- /dev/null +++ b/run.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +redis_server_mode() { + if [[ "${SERVER_MODE}" == "master" ]]; then + echo "Redis server mode is master" + elif [[ "${SERVER_MODE}" == "slave" ]]; then + echo "Redis server mode is slave" + if [[ -z "${REDIS_PASSWORD}" ]]; then + redis-cli --add-node "${SLAVE_IP}" "${MASTER_IP}" --cluster-slave + else + redis-cli --add-node "${SLAVE_IP}" "${MASTER_IP}" --cluster-slave -a "${REDIS_PASSWORD}" + fi + else + echo "Redis server mode is standalone" + fi +} + +redis_server_mode -- 2.26.0