Merge pull request #1090 from samalba/stdlib-docker-run-recreate
stdlib/docker: #Run checks if the container exists and can optionnally recreate it
This commit is contained in:
commit
33685f9bbf
@ -90,10 +90,11 @@ Push a docker image to a remote registry
|
||||
|
||||
### docker.#Run Inputs
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*ref* | `string` |Image reference (e.g: nginx:alpine) |
|
||||
|*run.env.IMAGE_REF* | `string` |- |
|
||||
| Name | Type | Description |
|
||||
| ------------- |:-------------: |:-------------: |
|
||||
|*ref* | `string` |Image reference (e.g: nginx:alpine) |
|
||||
|*recreate* | `*true \| bool` |Recreate container? |
|
||||
|*run.env.IMAGE_REF* | `string` |- |
|
||||
|
||||
### docker.#Run Outputs
|
||||
|
||||
|
@ -200,6 +200,9 @@ import (
|
||||
// Container name
|
||||
name?: dagger.#Input & {string}
|
||||
|
||||
// Recreate container?
|
||||
recreate: dagger.#Input & {bool | *true}
|
||||
|
||||
// Image registry
|
||||
registry?: {
|
||||
target: string
|
||||
@ -216,6 +219,16 @@ import (
|
||||
|
||||
if [ ! -z "$CONTAINER_NAME" ]; then
|
||||
OPTS="$OPTS --name $CONTAINER_NAME"
|
||||
docker inspect "$CONTAINER_NAME" >/dev/null && {
|
||||
# Container already exists
|
||||
if [ ! -z "$CONTAINER_RECREATE" ]; then
|
||||
echo "Replacing container $CONTAINER_NAME"
|
||||
docker stop "$CONTAINER_NAME"
|
||||
docker rm "$CONTAINER_NAME"
|
||||
else
|
||||
echo "$CONTAINER_NAME already exists"
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
||||
if [ ! -z "$CONTAINER_PORTS" ]; then
|
||||
@ -240,6 +253,10 @@ import (
|
||||
CONTAINER_NAME: name
|
||||
}
|
||||
|
||||
if recreate {
|
||||
CONTAINER_RECREATE: "true"
|
||||
}
|
||||
|
||||
if ports != _|_ {
|
||||
CONTAINER_PORTS: strings.Join(ports, " -p ")
|
||||
}
|
||||
|
Reference in New Issue
Block a user