Skip to content

Commit

Permalink
Add option to remove container when it exits
Browse files Browse the repository at this point in the history
  • Loading branch information
kien-cs committed Jul 25, 2023
1 parent f63fe51 commit 9c4929a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,31 @@ jobs:
- name: …
```

### Remove container when exit
Starting v1.6.0, when running this action on a self-hosted runner, it's helpful to remove the container so its name won't conflict:

```yaml
name: Run tests
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
redis-version: [4, 5, 6]
steps:
- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: ${{ matrix.redis-version }}
redis-remove-container: true # false by default
- name: …
```


## License
MIT © [Supercharge](https://superchargejs.com)
Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ inputs:
description: "Name of the created container. Useful if you run multiple Redis containers"
required: false
default: 'redis'
redis-remove-container:
description: "Remove container after container exit?"
required: false
type: boolean
default: false

runs:
using: 'docker'
Expand All @@ -31,3 +36,4 @@ runs:
- ${{ inputs.redis-version }}
- ${{ inputs.redis-port }}
- ${{ inputs.redis-container-name }}
- ${{ inputs.redis-remove-container }}
11 changes: 9 additions & 2 deletions start-redis.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ REDIS_IMAGE=$1
REDIS_VERSION=$2
REDIS_PORT=$3
REDIS_CONTAINER_NAME=$4
REDIS_REMOVE_CONTAINER=$5

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

echo "Starting single-node Redis instance"
docker run --name $REDIS_CONTAINER_NAME --publish $REDIS_PORT:6379 --detach $REDIS_IMAGE:$REDIS_VERSION
DOCKER_RUN_ARGS="--name $REDIS_CONTAINER_NAME --publish $REDIS_PORT:6379 --detach $REDIS_IMAGE:$REDIS_VERSION"

if [ "$REDIS_REMOVE_CONTAINER" == "true" ] ; then
DOCKER_RUN_ARGS+=" --rm"
fi

echo "Starting single-node Redis instance: $DOCKER_RUN_ARGS"
docker run $DOCKER_RUN_ARGS

0 comments on commit 9c4929a

Please sign in to comment.