From 4eb86fc2ecae36db39df761b9e4ddcc3fc85f62e Mon Sep 17 00:00:00 2001 From: iamabhishek-dubey Date: Mon, 16 Mar 2020 20:13:46 +0530 Subject: [PATCH] Added entrypoint.sh to support cluster and standalone --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ entrypoint.sh | 39 +++++++++++++++++++++++++++++++++++++++ redis.conf | 8 ++++++++ 3 files changed, 83 insertions(+) create mode 100644 Dockerfile create mode 100755 entrypoint.sh create mode 100644 redis.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4318bb4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +FROM alpine:3.9 + +MAINTAINER Opstree Solutions + +LABEL VERSION=1.0 \ + ARCH=AMD64 \ + DESCRIPTION="A production grade performance tuned docker image created by Opstree Solutions" + +ARG REDIS_DOWNLOAD_URL="http://download.redis.io/" + +ARG REDIS_VERSION="stable" + +COPY redis.conf /etc/redis/redis.conf + +COPY entrypoint.sh /usr/bin/entrypoint.sh + +RUN addgroup -S -g 1000 redis && adduser -S -G redis -u 999 redis && \ + apk add --no-cache su-exec tzdata make curl build-base linux-headers + +RUN curl -fL -Lo /tmp/redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_VERSION}.tar.gz && \ + cd /tmp && \ + tar xvzf redis-${REDIS_VERSION}.tar.gz && \ + cd redis-${REDIS_VERSION} && \ + make && \ + make install && \ + mkdir -p /etc/redis && \ + cp -f *.conf /etc/redis && \ + rm -rf /tmp/redis-${REDIS_VERSION}* + +VOLUME ["/data"] + +WORKDIR /data + +EXPOSE 6379 + +ENTRYPOINT ["/usr/bin/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..1045258 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +set -eu + +set_redis_password() { + if [ -z "${REDIS_PASSWORD}" ]; then + echo "Redis is running without password which is not recommended" + else + { + echo masterauth "${REDIS_PASSWORD}" + echo requirepass "${REDIS_PASSWORD}" + } >> /etc/redis/redis.conf + fi +} + +redis_mode_setup() { + if [ "${SETUP_MODE}" = "cluster" ]; then + { + echo cluster-enabled yes + echo cluster-config-file nodes.conf + echo cluster-node-timeout 5000 + } >> /etc/redis/redis.conf + else + echo "Setting up redis in standalone mode" + fi +} + +start_redis() { + echo "Starting redis service " + redis-server /etc/redis/redis.conf +} + +main_function() { + set_redis_password + redis_mode_setup + start_redis +} + +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 -- 2.26.0