forked from supercharge/redis-github-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-redis.sh
More file actions
executable file
·34 lines (28 loc) · 1 KB
/
start-redis.sh
File metadata and controls
executable file
·34 lines (28 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/sh
REDIS_IMAGE=$1
REDIS_VERSION=$2
REDIS_PORT=$3
REDIS_PASSWORD=$4
REDIS_CONTAINER_NAME=$5
REDIS_REMOVE_CONTAINER_ON_EXIT=$6
# 🛡️ Default version fallback
if [ -z "$REDIS_VERSION" ]; then
echo "Missing Redis version in the [redis-version] input. Received value: $REDIS_VERSION"
echo "Falling back to Redis version [latest]"
REDIS_VERSION='latest'
fi
# 🛠️ Build docker run args
DOCKER_RUN_ARGS="--name $REDIS_CONTAINER_NAME --publish $REDIS_PORT:6379 --detach"
# 🗑️ If remove flag is true, run container with --rm (auto-remove on exit)
if [ "$REDIS_REMOVE_CONTAINER_ON_EXIT" = "true" ]; then
DOCKER_RUN_ARGS="--rm $DOCKER_RUN_ARGS"
fi
# 🔐 Add password if provided
if [ -n "$REDIS_PASSWORD" ]; then
DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS $REDIS_IMAGE:$REDIS_VERSION redis-server --requirepass $REDIS_PASSWORD"
else
DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS $REDIS_IMAGE:$REDIS_VERSION"
fi
# 🚀 Start Redis
echo "Starting single-node Redis instance: $DOCKER_RUN_ARGS"
docker run $DOCKER_RUN_ARGS