From dbe73abc21488acd10df16afe4465321e8f6676a Mon Sep 17 00:00:00 2001 From: Dennis Stam Date: Mon, 9 Jan 2023 16:20:17 +0100 Subject: [PATCH] Add env-file as attribute (#4) Also add state=up Updated --- promise-types/docker_compose/README.md | 3 ++- .../docker_compose/docker_compose.sh | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/promise-types/docker_compose/README.md b/promise-types/docker_compose/README.md index 0bce972..760d824 100644 --- a/promise-types/docker_compose/README.md +++ b/promise-types/docker_compose/README.md @@ -16,7 +16,8 @@ | Name | Type | Description | Mandatory | Default | | --------------- | --------- | ----------------------------------------------------------------------------------------------------------------------- | --------- | -------- | | `file` | `string` | Docker compose yaml file | Yes | Promiser | -| `state` | `string` | Stete of the ddocker images: start, stop, restart, kill | Yes | - | +| `state` | `string` | State of the docker images: start, stop, restart, kill, up | Yes | - | +| `envfile` | `string` | Specify which env-file needs to be included | Yes | - | ## Examples diff --git a/promise-types/docker_compose/docker_compose.sh b/promise-types/docker_compose/docker_compose.sh index 5228b49..4edb55d 100755 --- a/promise-types/docker_compose/docker_compose.sh +++ b/promise-types/docker_compose/docker_compose.sh @@ -1,5 +1,5 @@ required_attributes="state" -optional_attributes="" +optional_attributes="envfile" all_attributes_are_valid="no" @@ -8,6 +8,7 @@ LOG_PREFIX="${0##*/}" declare -A DOCKER_STATES DOCKER_STATES["start"]="running" DOCKER_STATES["restart"]="running" +DOCKER_STATES["up"]="running" DOCKER_STATES["stop"]="exited" DOCKER_STATES["kill"]="exited" @@ -31,12 +32,16 @@ do_evaluate() { # Default the promise is alwasys 'kept' response_result="kept" + if [[ -n ${request_attribute_envfile} ]] + then + docker_envfile="--env-file ${request_attribute_envfile}" + else + docker_envfile="" + fi - docker_cmd="docker compose --file=${request_promiser}" + docker_cmd="docker compose --file=${request_promiser} ${docker_envfile}" docker_up="${docker_cmd} up --detach" - - log debug "${LOG_PREFIX}:${request_promiser}" docker_status=$(${docker_cmd} ps --format=json | jq -r '.[] | .Name + ":" + .State + ":" + .Health + ":" + .Service') @@ -68,6 +73,19 @@ do_evaluate() { ;; esac + elif [[ ${request_attribute_state} == "up" ]] + then + + log info "${LOG_PREFIX}:Recreate all containers with:'${docker_cmd} up'" + result=$(${docker_up}) + if [[ $? -ne 0 ]] + then + log error "${LOG_PREFIX}:'${docker_up}' failed with:'${result}'" + response_result="not_kept" + else + log info "${LOG_PREFIX}:Started all containers with:'${docker_up}'" + response_result="repaired" + fi elif [[ ${request_attribute_state} == "restart" ]] then