fixup! fixup! WIP WORLD

This commit is contained in:
decentral1se 2021-06-19 20:46:19 +02:00
parent 848cfff268
commit 9ee73d75ea
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

50
abra
View File

@ -794,52 +794,44 @@ output_version_summary() {
}
ensure_stack_deployed() {
local stack=$1
local deployed=false
SERVICES=$($YQ e '.services | keys | .[]' "${APP_DIR}/${COMPOSE}" | tr '\n' ' ')
debug "Detected the following services: $(echo ${SERVICES})"
local -a UNHEALTHY # mapping
local -a HEALTHY # mapping
local -a UNKNOWN # mapping
local -a MISSING # mapping
services=$(docker stack services "${STACK_NAME}" --format "{{.ID}}" | tr '\n' ' ')
debug "Detected the following service IDs: $(echo $services)"
without_health_checks = $(docker inspect --format)
# TODO: this tells you if shit is missing
docker inspect --format "{{ json .State }}" traefik_app.1.rnpar574ozsn6oi2ouo5s84jn | jq "try(.Health.Status // \"missing\")"
while [ ! "${#HEALTHY[@]}" -eq "$(( ${#SERVICES[@]} + 1 ))" ]; do
debug "Number of services expected to be healthy: $(( ${#SERVICES[@]} + 1 ))"
debug "Number of services actually healthy: ${#HEALTHY[@]}"
IFS=' ' read -r -a SERVICES <<< $(docker stack services "${STACK_NAME}" --format "{{.ID}}" | tr '\n' ' ')
debug "Detected the following services: ${SERVICES}"
while [ ! $(( ${#HEALTHY[@]} + ${#MISSING[@]} )) -eq ${#SERVICES[@]} ]; do
for service in $(docker ps -f "name=$STACK_NAME" -q); do
local status=$(docker inspect --format "{{ .State.Health.Status }}" "$service")
local name=$(docker inspect --format '{{ index .Config.Labels "com.docker.swarm.service.name" }}' $service)
healthcheck=$(docker inspect --format "{{ json .State }}" "$service" | jq "try(.Health.Status // \"missing\")")
name=$(docker inspect --format '{{ index .Config.Labels "com.docker.swarm.service.name" }}' "$service")
debug "Processing $name (status: $status)..."
if [[ ${UNHEALTHY[*]} =~ ${name} ]] || [[ ${MISSING[*]} =~ ${name} ]]; then
debug "Already reported $name as failing/missing healthcheck, skipping..."
continue
fi
if [[ "$status" == "unhealthy" ]]; then
local logs=$(docker inspect --format "{{ json .State.Health.Log }}" "$service")
local exitcode="$(echo $logs | $JQ '.[-1] | .ExitCode')"
if [[ "$healthcheck" == *"missing"* ]] && [[ ! "${MISSING[*]}" =~ $name ]]; then
debug "$name has no healthcheck, skipping..."
MISSING+=("$name")
continue
fi
if [[ "$healthcheck" == *"unhealthy"* ]]; then
logs=$(docker inspect --format "{{ json .State.Health.Log }}" "$service")
exitcode="$(echo $logs | $JQ '.[-1] | .ExitCode')"
warning "Healthcheck for new instance of $name is failing (exit code: $exitcode)"
warning "$(echo $logs | $JQ -r '.[-1] | .Output')"
debug "Placing $name in UNHEALTHY mapping..."
UNHEALTHY+=("$name")
continue
fi
if [[ ${UNHEALTHY[*]} =~ ${name} ]]; then
debug "Already reported $name as failing, skipping..."
continue
elif [[ "$status" == "healthy" ]] && [[ ! "${HEALTHY[*]}" =~ $name ]]; then
if [[ "$healthcheck" == *"healthy"* ]] && [[ ! "${HEALTHY[*]}" =~ $name ]]; then
debug "$name is healthy, skipping..."
HEALTHY+=("$name")
continue
fi
done
sleep 1
done