Merge pull request #15 from kien-cs/feature-add-rm-container

Add option to remove container when it exits
pull/16/head
Marcus Pöhls 2023-07-27 10:38:29 +02:00 committed by GitHub
commit b026ae8b2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View File

@ -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/redis-github-action@1.6.0
with:
redis-version: ${{ matrix.redis-version }}
redis-remove-container: true # false by default
- name: …
```
## License
MIT © [Supercharge](https://superchargejs.com)

View File

@ -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'
@ -31,3 +36,4 @@ runs:
- ${{ inputs.redis-version }}
- ${{ inputs.redis-port }}
- ${{ inputs.redis-container-name }}
- ${{ inputs.redis-remove-container }}

11
start-redis.sh Normal file → Executable file
View File

@ -4,6 +4,7 @@ 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"
@ -11,5 +12,11 @@ if [ -z "$REDIS_VERSION" ]; then
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