Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Feature/new redis #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions redis/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
FROM fedora
MAINTAINER http://fedoraproject.org/wiki/Cloud

RUN dnf -y update && dnf clean all
RUN dnf -y install redis && dnf clean all
LABEL io.k8s.description="Redis is an open source, in-memory data structure store, used as database, cache and message broker." \
io.k8s.display-name="Redis 3.0.6-1.fc23" \
io.openshift.expose-services="6379:redis" \
io.openshift.tags="database,redis,redis28"

LABEL Name="fedora-cloud/redis-28" \
Version="3.0.6" \
Release="1" \
Architecture="x86_64"

RUN dnf -y --setopt=tsflags=nodocs update && \
dnf -y --setopt=tsflags=nodocs install redis && \
dnf clean all

COPY redis-master.conf /redis-master/redis.conf
COPY redis-slave.conf /redis-slave/redis.conf
COPY entrypoint /entrypoint
RUN mkdir /redis-master-data && \
chmod 755 /entrypoint /redis-master-data && \
chown 997 /redis-master-data

EXPOSE 6379

CMD [ "redis-server" ]
# By default will run as random user on openshift and the redis user (997)
# everywhere else
USER 997

CMD [ "/entrypoint" ]
ENTRYPOINT [ "sh", "-c" ]
6 changes: 3 additions & 3 deletions redis/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
dockerfiles-fedora-redis
========================

Fedora dockerfile for redis
Fedora Dockerfile for Redis, it implements a master and a sentinel (as shown by
Kubernetes examples).

To build:

Expand All @@ -11,9 +12,8 @@ Copy the sources down -

To run:

# docker run -d -p 6379:6379 <username>/redis
# docker run -d -p 6379:6379 -e MASTER=true <username>/redis

To test:

# nc localhost 6379

84 changes: 84 additions & 0 deletions redis/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# Copyright 2014 The Kubernetes Authors All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function launchmaster() {
if [[ ! -e /redis-master-data ]]; then
echo "Redis master data doesn't exist, data won't be persistent!"
mkdir /redis-master-data
fi
redis-server /redis-master/redis.conf
}

function launchsentinel() {
while true; do
master=$(redis-cli -h ${REDIS_SENTINEL_SERVICE_HOST} -p ${REDIS_SENTINEL_SERVICE_PORT} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
master="${master//\"}"
else
master=$(hostname -i)
fi

redis-cli -h ${master} INFO
if [[ "$?" == "0" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
sleep 10
done

sentinel_conf=sentinel.conf

echo "sentinel monitor mymaster ${master} 6379 2" > ${sentinel_conf}
echo "sentinel down-after-milliseconds mymaster 60000" >> ${sentinel_conf}
echo "sentinel failover-timeout mymaster 180000" >> ${sentinel_conf}
echo "sentinel parallel-syncs mymaster 1" >> ${sentinel_conf}

redis-sentinel ${sentinel_conf}
}

function launchslave() {
while true; do
master=$(redis-cli -h ${REDIS_SENTINEL_SERVICE_HOST} -p ${REDIS_SENTINEL_SERVICE_PORT} --csv SENTINEL get-master-addr-by-name mymaster | tr ',' ' ' | cut -d' ' -f1)
if [[ -n ${master} ]]; then
master="${master//\"}"
else
echo "Failed to find master."
sleep 60
exit 1
fi
redis-cli -h ${master} INFO
if [[ "$?" == "0" ]]; then
break
fi
echo "Connecting to master failed. Waiting..."
sleep 10
done
perl -pi -e "s/%master-ip%/${master}/" /redis-slave/redis.conf
perl -pi -e "s/%master-port%/6379/" /redis-slave/redis.conf
redis-server /redis-slave/redis.conf
}

if [[ "${MASTER}" == "true" ]]; then
launchmaster
exit 0
fi

if [[ "${SENTINEL}" == "true" ]]; then
launchsentinel
exit 0
fi

launchslave
Loading