docker-redis - local tests
Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
2
redis/.gitignore
vendored
Normal file
2
redis/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
redis-cluster-init.lock
|
||||
dockerdata/
|
||||
20
redis/Dockerfile
Normal file
20
redis/Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
# Use the official Redis image
|
||||
FROM redis:7.0-alpine
|
||||
|
||||
# Copy the Redis configuration file
|
||||
COPY redis.conf /usr/local/etc/redis/redis.conf
|
||||
|
||||
# Copy the entrypoint script
|
||||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Make the entrypoint script executable
|
||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||
|
||||
# Debugging step: List contents of /usr/local/bin
|
||||
RUN ls -l /usr/local/bin
|
||||
|
||||
# Expose Redis ports
|
||||
EXPOSE 6379 16379
|
||||
|
||||
# Set the entrypoint
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
3
redis/dockerdata/.gitignore
vendored
Normal file
3
redis/dockerdata/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.gitkeep
|
||||
!.gitignore
|
||||
!.gitkeep
|
||||
0
redis/dockerdata/.gitkeep
Normal file
0
redis/dockerdata/.gitkeep
Normal file
30
redis/entrypoint.sh
Normal file
30
redis/entrypoint.sh
Normal file
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
|
||||
LOCK_FILE="redis-cluster-init.lock"
|
||||
|
||||
# Start Redis server in the background
|
||||
redis-server /usr/local/etc/redis/redis.conf &
|
||||
|
||||
# Wait for Redis server to start
|
||||
sleep 5
|
||||
|
||||
# Initialize the cluster only if the lock file does not exist
|
||||
if [ ! -f "$LOCK_FILE" ]; then
|
||||
echo "Initializing Redis Cluster..."
|
||||
|
||||
# Run the Redis cluster initialization
|
||||
yes yes | redis-cli --cluster create \
|
||||
redis-node-1:6379 \
|
||||
redis-node-2:6379 \
|
||||
redis-node-3:6379 \
|
||||
--cluster-replicas 0
|
||||
|
||||
# Create the lock file after initialization
|
||||
touch "$LOCK_FILE"
|
||||
echo "Cluster initialization complete. Lock file created."
|
||||
else
|
||||
echo "Cluster has already been initialized. Skipping initialization."
|
||||
fi
|
||||
|
||||
# Keep the container running
|
||||
tail -f /dev/null
|
||||
6
redis/redis.conf
Normal file
6
redis/redis.conf
Normal file
@@ -0,0 +1,6 @@
|
||||
bind 0.0.0.0
|
||||
port 6379
|
||||
cluster-enabled yes
|
||||
cluster-config-file nodes.conf
|
||||
cluster-node-timeout 5000
|
||||
appendonly yes
|
||||
Reference in New Issue
Block a user