Skip to content

Commit

Permalink
Add env-file as attribute (#4)
Browse files Browse the repository at this point in the history
Also add state=up

Updated
  • Loading branch information
dstam authored Jan 9, 2023
1 parent 7239afa commit dbe73ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion promise-types/docker_compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 22 additions & 4 deletions promise-types/docker_compose/docker_compose.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
required_attributes="state"
optional_attributes=""
optional_attributes="envfile"
all_attributes_are_valid="no"


Expand All @@ -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"

Expand All @@ -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')
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dbe73ab

Please sign in to comment.