From 7d05f20ddcb90529d173668acb99fa12d2ee189e Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Sun, 10 Jan 2021 20:46:22 +0200
Subject: [PATCH] Handle errors a little better.

---
 deploy | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/deploy b/deploy
index f2b71c6..4c175e1 100755
--- a/deploy
+++ b/deploy
@@ -1,6 +1,12 @@
 #!/bin/sh
 set -eu
 
+_check() {
+    containers="$(until docker-compose ps -q; do true; done)"
+    # shellcheck disable=SC2086
+    docker container inspect --format '{{ .State.Health.Status }}' $containers | grep -v '^healthy$'
+}
+
 _deploy() {
     echo "Deploying to $1" >&2
     export DOCKER_HOST="ssh://$1"
@@ -10,11 +16,11 @@ _deploy() {
     for i in $(seq 12)
     do
         # shellcheck disable=SC2046
-        docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' || break
+        _check || break
         sleep 10
     done
     # shellcheck disable=SC2046
-    ! docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$'
+    ! _check
     unset DOCKER_HOST
     unset RUNNER_NAME
 }
-- 
GitLab