Skip to content

Commit

Permalink
cluster script fixes to support future cluster versions and redis uns…
Browse files Browse the repository at this point in the history
…table (#1900)
  • Loading branch information
chayim committed Jan 26, 2022
1 parent 26491dc commit 9292e56
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
4 changes: 3 additions & 1 deletion docker/base/Dockerfile.cluster
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ RUN chmod +x /create_cluster.sh

EXPOSE 16379 16380 16381 16382 16383 16384

CMD /create_cluster.sh 16379 16384
ENV START_PORT=16379
ENV END_PORT=16384
CMD /create_cluster.sh
4 changes: 3 additions & 1 deletion docker/base/Dockerfile.unstable_cluster
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ RUN chmod +x /create_cluster.sh

EXPOSE 6372 6373 6374 6375 6376 6377

CMD /create_cluster.sh 6372 6377
ENV START_PORT=6372
ENV END_PORT=6377
CMD ["/create_cluster.sh"]
17 changes: 17 additions & 0 deletions docker/base/Dockerfile.unstable_sentinel
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# produces redisfab/redis-py-sentinel:unstable
FROM ubuntu:bionic as builder
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y build-essential git
RUN mkdir /build
WORKDIR /build
RUN git clone https://github.com/redis/redis
WORKDIR /build/redis
RUN make

FROM ubuntu:bionic as runner
COPY --from=builder /build/redis/src/redis-server /usr/bin/redis-server
COPY --from=builder /build/redis/src/redis-cli /usr/bin/redis-cli
COPY --from=builder /build/redis/src/redis-sentinel /usr/bin/redis-sentinel

CMD ["redis-sentinel", "/sentinel.conf"]
28 changes: 23 additions & 5 deletions docker/base/create_cluster.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
#! /bin/bash

mkdir -p /nodes
touch /nodes/nodemap
START_NODE=$1
END_NODE=$2
for PORT in `seq ${START_NODE} ${END_NODE}`; do
if [ -z ${START_PORT} ]; then
START_PORT=16379
fi
if [ -z ${END_PORT} ]; then
END_PORT=16384
fi
if [ ! -z "$3" ]; then
START_PORT=$2
START_PORT=$3
fi
echo "STARTING: ${START_PORT}"
echo "ENDING: ${END_PORT}"

for PORT in `seq ${START_PORT} ${END_PORT}`; do
mkdir -p /nodes/$PORT
if [[ -e /redis.conf ]]; then
cp /redis.conf /nodes/$PORT/redis.conf
Expand All @@ -17,12 +29,18 @@ daemonize yes
logfile /redis.log
dir /nodes/$PORT
EOF

set -x
redis-server /nodes/$PORT/redis.conf
if [ $? -ne 0 ]; then
echo "Redis failed to start, exiting."
exit 3
continue
fi
echo 127.0.0.1:$PORT >> /nodes/nodemap
done
echo yes | redis-cli --cluster create $(seq -f 127.0.0.1:%g ${START_NODE} ${END_NODE}) --cluster-replicas 1
if [ -z "${REDIS_PASSWORD}" ]; then
echo yes | redis-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
else
echo yes | redis-cli -a ${REDIS_PASSWORD} --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
fi
tail -f /redis.log

0 comments on commit 9292e56

Please sign in to comment.