WIP WORLD
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
decentral1se 2021-06-09 10:10:16 +02:00
parent a019417fd2
commit f151018f10
No known key found for this signature in database
GPG Key ID: 92DAD76BD9567B8A
4 changed files with 61 additions and 37 deletions

61
abra
View File

@ -787,49 +787,36 @@ output_version_summary() {
fi
}
# Note(decentral1se): inspired by https://github.com/vitalets/docker-stack-wait-deploy
ensure_stack_deployed() {
STACK_NAME=$1
local stack=$1
local deployed=false
warning "Polling deploy state to check for success"
warning "Waiting for new services to come up..."
local -a UNHEALTHY # mapping
services=$(docker stack services "${STACK_NAME}" --format "{{.ID}}")
echo "$services"
while true; do
all_services_done=1
has_errors=0
for service in $(docker ps -f "name=$STACK_NAME" -q); do
local logs=$(docker inspect --format "{{ if (eq .State.Health.Status \"unhealthy\") }} {{json .State.Health.Log}} {{end}}" "$service")
local name=$(docker inspect --format '{{ index .Config.Labels "com.docker.swarm.service.name"}}' $service)
service_ids=$(docker stack services -q "$STACK_NAME")
debug "Processing $service ($name)..."
for service_id in $service_ids; do
# see: https://github.com/moby/moby/issues/28012
service_state=$(docker service inspect --format "{{if .UpdateStatus}}{{.UpdateStatus.State}}{{else}}created{{end}}" "$service_id")
debug "$service_id has state: $service_state"
case "$service_state" in
created|completed)
;;
paused|rollback_completed)
has_errors=1
;;
*)
all_services_done=0
;;
esac
done
if [ "$all_services_done" == "1" ]; then
if [ "$has_errors" == "1" ]; then
warning "Deployment appears to have failed"
warning "Run \"abra app ${STACK_NAME} logs \" to see app logs"
warning "Run \"abra app ${STACK_NAME} ps \" to see app status"
break
else
warning "Deployment appears to have suceeded"
break
if [[ ${UNHEALTHY_SEEN[*]} =~ ${service} ]]; then
debug "Already reported $name as failing, skipping..."
continue
fi
else
sleep 1
fi
if [[ -n "$logs" ]]; then
local 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')"
fi
done
sleep 1
done
}
@ -865,7 +852,7 @@ load_instance() {
APP="$abra__app_"
# load all files matching "$APP.env" into ENV_FILES array
mapfile -t ENV_FILES < <(find -L "$ABRA_DIR" -name "$APP.env")
mapfile -t ENV_FILES < <(find -L "$ABRA_DIR/servers/" -name "$APP.env")
# FIXME 3wc: requires bash 4, use for loop instead
case "${#ENV_FILES[@]}" in

View File

@ -43,3 +43,8 @@ build:
push: build
@docker push decentral1se/abra
symlink:
@mkdir -p ~/.abra/servers/ && \
ln -srf tests/default ~/.abra/servers && \
ln -srf tests/apps/* ~/.abra/apps

View File

@ -0,0 +1,31 @@
---
version: "3.8"
services:
r1:
image: redis:alpine
deploy:
update_config:
failure_action: rollback
order: start-first
rollback_config:
order: start-first
restart_policy:
max_attempts: 3
healthcheck:
test: redis-cli ping
r2:
image: redis:alpine
deploy:
update_config:
failure_action: rollback
order: start-first
rollback_config:
order: start-first
restart_policy:
max_attempts: 3
healthcheck:
test: foobar
# test: redis-cli ping
start_period: 5s
interval: 2s
timeout: 3s

1
tests/default/works.env Normal file
View File

@ -0,0 +1 @@
TYPE=works