Skip to content

Commit f7760cc

Browse files
committed
[FIX] - Correct '--rm' argument placement in docker run (#26)
- Fixes issue #26 where the '--rm' flag was applied after the image argument. - Adds a new CI workflow 'container-remove-flag.yml' to test this scenario.
1 parent 0bc8516 commit f7760cc

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Start Redis server with remove container flag
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
redis-action:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
redis-version: [5, 6, 7]
11+
12+
name: Start Redis Server v${{ matrix.redis-version }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Start Redis Server
18+
uses: ./
19+
with:
20+
redis-version: ${{ matrix.redis-version }}
21+
redis-remove-container: true # false by default

start-redis.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@ REDIS_PASSWORD=$4
77
REDIS_CONTAINER_NAME=$5
88
REDIS_REMOVE_CONTAINER=$6
99

10+
# 🛡️ Default version fallback
1011
if [ -z "$REDIS_VERSION" ]; then
1112
echo "Missing Redis version in the [redis-version] input. Received value: $REDIS_VERSION"
1213
echo "Falling back to Redis version [latest]"
1314
REDIS_VERSION='latest'
1415
fi
1516

16-
DOCKER_RUN_ARGS="--name $REDIS_CONTAINER_NAME --publish $REDIS_PORT:6379 --detach $REDIS_IMAGE:$REDIS_VERSION"
17+
# 🛠️ Build docker run args
18+
DOCKER_RUN_ARGS="--name $REDIS_CONTAINER_NAME --publish $REDIS_PORT:6379 --detach"
1719

18-
if [ "$REDIS_REMOVE_CONTAINER" == "true" ]; then
19-
DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS --rm"
20+
# 🗑️ If remove flag is true, run container with --rm (auto-remove on exit)
21+
if [ "$REDIS_REMOVE_CONTAINER" = "true" ]; then
22+
DOCKER_RUN_ARGS="--rm $DOCKER_RUN_ARGS"
2023
fi
2124

25+
# 🔐 Add password if provided
2226
if [ -n "$REDIS_PASSWORD" ]; then
23-
DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS redis-server --requirepass $REDIS_PASSWORD"
27+
DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS $REDIS_IMAGE:$REDIS_VERSION redis-server --requirepass $REDIS_PASSWORD"
28+
else
29+
DOCKER_RUN_ARGS="$DOCKER_RUN_ARGS $REDIS_IMAGE:$REDIS_VERSION"
2430
fi
2531

32+
# 🚀 Start Redis
2633
echo "Starting single-node Redis instance: $DOCKER_RUN_ARGS"
2734
docker run $DOCKER_RUN_ARGS

0 commit comments

Comments
 (0)