Add option to remove container when it exits
parent
f63fe51625
commit
9c4929a470
25
README.md
25
README.md
|
@ -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)
|
||||
|
|
|
@ -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 }}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue