#!/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" export RUNNER_NAME="$1" until docker-compose up --detach --remove-orphans ; do true; done # shellcheck disable=SC2034 for i in $(seq 12) do # shellcheck disable=SC2046 _check || break sleep 10 done # shellcheck disable=SC2046 ! _check unset DOCKER_HOST unset RUNNER_NAME } if [ -z "${REGISTRATION_TOKEN:-}" ] then echo "REGISTRATION_TOKEN isn't set." >&2 exit 1 fi case "${1:-all}" in ns4) export REGISTER_RUN_UNTAGGED="true" export BUILDS='/builds' _deploy ns4.shore.co.il ;; kodi) export REGISTER_RUN_UNTAGGED="false" unset BUILDS _deploy kodi.shore.co.il ;; host01) export REGISTER_RUN_UNTAGGED="false" unset BUILDS _deploy host01.shore.co.il ;; all) "$0" ns4; "$0" host01; "$0" kodi ;; *) echo 'Unknown host.' >&2; exit 1;; esac