From fac6855936ab3f0dd74bf1c4247874598cfd27ce Mon Sep 17 00:00:00 2001 From: iamabhishek-dubey Date: Mon, 10 Oct 2022 18:02:39 +0530 Subject: [PATCH] Added support for Redis 7 Signed-off-by: iamabhishek-dubey --- Dockerfile | 10 ++-------- Dockerfile.exporter | 2 +- Makefile | 4 ++-- entrypoint.sh | 22 ++++++++++++---------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6da4561..fb576bc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,9 +17,7 @@ RUN curl -fL -Lo /tmp/redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis- tar xvzf redis-${REDIS_VERSION}.tar.gz && \ cd redis-${REDIS_VERSION} && \ make && \ - make install BUILD_TLS=yes && \ - mkdir -p /etc/redis && \ - cp -f *.conf /etc/redis + make install BUILD_TLS=yes FROM alpine:3.15 @@ -31,9 +29,8 @@ LABEL VERSION=1.0 \ COPY --from=builder /usr/local/bin/redis-server /usr/local/bin/redis-server COPY --from=builder /usr/local/bin/redis-cli /usr/local/bin/redis-cli -COPY --from=builder /etc/redis /etc/redis -RUN addgroup -S -g 1001 redis && adduser -S -G redis -u 1001 redis && \ +RUN addgroup -S -g 1000 redis && adduser -S -G redis -u 1000 redis && \ apk add --no-cache bash COPY redis.conf /etc/redis/redis.conf @@ -44,9 +41,6 @@ COPY setupMasterSlave.sh /usr/bin/setupMasterSlave.sh COPY healthcheck.sh /usr/bin/healthcheck.sh -RUN mkdir -p /opt/redis/ && \ - chmod -R g+rwX /etc/redis /opt/redis - VOLUME ["/data"] WORKDIR /data diff --git a/Dockerfile.exporter b/Dockerfile.exporter index 1ec4a21..cd1efc4 100644 --- a/Dockerfile.exporter +++ b/Dockerfile.exporter @@ -2,7 +2,7 @@ FROM alpine:3.15 as builder ARG EXPORTER_URL="https://github.com/oliver006/redis_exporter/releases/download" -ARG REDIS_EXPORTER_VERSION="1.5.2" +ARG REDIS_EXPORTER_VERSION="1.44.0" RUN apk add --no-cache curl ca-certificates && \ curl -fL -Lo /tmp/redis_exporter-v${REDIS_EXPORTER_VERSION}.linux-amd64.tar.gz \ diff --git a/Makefile b/Makefile index ede1763..afaacf0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -REDIS_VERSION ?= 6.2.5 -EXPORTER_VERSION?=1.0 +REDIS_VERSION ?= v7.0.5 +EXPORTER_VERSION ?= v1.44.0 build-redis-image: docker build -t quay.io/opstree/redis:$(REDIS_VERSION) -f Dockerfile . diff --git a/entrypoint.sh b/entrypoint.sh index a623ca4..590e9ce 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,20 +2,17 @@ set -a -CLUSTER_DIRECTORY=${CLUSTER_DIRECTORY:-"/opt/redis"} PERSISTENCE_ENABLED=${PERSISTENCE_ENABLED:-"false"} DATA_DIR=${DATA_DIR:-"/data"} EXTERNAL_CONFIG_FILE=${EXTERNAL_CONFIG_FILE:-"/etc/redis/external.conf.d/redis-external.conf"} +REDIS_MAJOR_VERSION=${REDIS_MAJOR_VERSION:-"v7"} apply_permissions() { - chgrp -R 0 /etc/redis + chgrp -R 1000 /etc/redis chmod -R g=u /etc/redis - chgrp -R 0 /opt - chmod -R g=u /opt } common_operation() { - mkdir -p "${CLUSTER_DIRECTORY}" mkdir -p "${DATA_DIR}" } @@ -40,11 +37,12 @@ redis_mode_setup() { echo cluster-config-file "${DATA_DIR}/nodes.conf" } >> /etc/redis/redis.conf - if [[ -z "${POD_IP}" ]]; then - POD_IP=$(hostname -i) + if [[ "${REDIS_MAJOR_VERSION}" != "v7" ]]; then + if [[ -z "${POD_IP}" ]]; then + POD_IP=$(hostname -i) + fi + sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" "${DATA_DIR}/nodes.conf" fi - - sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" "${DATA_DIR}/nodes.conf" else echo "Setting up redis in standalone mode" fi @@ -95,7 +93,11 @@ external_config() { start_redis() { if [[ "${SETUP_MODE}" == "cluster" ]]; then echo "Starting redis service in cluster mode....." - redis-server /etc/redis/redis.conf --cluster-announce-ip "${POD_IP}" + if [[ "${REDIS_MAJOR_VERSION}" != "v7" ]]; then + redis-server /etc/redis/redis.conf --cluster-announce-ip "${POD_IP}" + else + redis-server /etc/redis/redis.conf + fi else echo "Starting redis service in standalone mode....." redis-server /etc/redis/redis.conf -- 2.26.0