docker-redis - local tests

Signed-off-by: Dave Richer <dave@imexsystems.ca>
This commit is contained in:
Dave Richer
2024-10-02 00:27:11 -04:00
parent b7423aebf6
commit 04dec6d91c
14 changed files with 456 additions and 18 deletions

2
redis/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
redis-cluster-init.lock
dockerdata/

20
redis/Dockerfile Normal file
View 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
View File

@@ -0,0 +1,3 @@
.gitkeep
!.gitignore
!.gitkeep

View File

30
redis/entrypoint.sh Normal file
View 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
View 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