diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c26785f63ed4cd1b4b233dcf763ac577b4c0e8c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +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" + +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 bash + +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}* + +COPY entrypoint.sh /usr/bin/entrypoint.sh + +VOLUME ["/data"] + +WORKDIR /data + +EXPOSE 6379 + +ENTRYPOINT ["/usr/bin/entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000000000000000000000000000000000000..47668cc587a194529e622a5b2015facbc5efad2f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,53 @@ +#!/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_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() { + generate_common_config + set_redis_password + redis_mode_setup + start_redis +} + +main_function