From f151018f104df17cb8ccfb6736075e4c216d9c13 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Wed, 9 Jun 2021 10:10:16 +0200 Subject: [PATCH] WIP WORLD --- abra | 61 ++++++++++++++---------------------- makefile | 5 +++ tests/apps/works/compose.yml | 31 ++++++++++++++++++ tests/default/works.env | 1 + 4 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 tests/apps/works/compose.yml create mode 100644 tests/default/works.env diff --git a/abra b/abra index 684e4c3..117084e 100755 --- a/abra +++ b/abra @@ -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 diff --git a/makefile b/makefile index bea1f2f..0a673f1 100644 --- a/makefile +++ b/makefile @@ -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 diff --git a/tests/apps/works/compose.yml b/tests/apps/works/compose.yml new file mode 100644 index 0000000..482e236 --- /dev/null +++ b/tests/apps/works/compose.yml @@ -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 diff --git a/tests/default/works.env b/tests/default/works.env new file mode 100644 index 0000000..aa318fd --- /dev/null +++ b/tests/default/works.env @@ -0,0 +1 @@ +TYPE=works