Skip to content
Snippets Groups Projects
deploy 1.14 KiB
Newer Older
nimrod's avatar
nimrod committed
#!/bin/sh
set -eu

nimrod's avatar
nimrod committed
_deploy() {
nimrod's avatar
nimrod committed
    echo "Deploying to $1" >&2
    export DOCKER_HOST="ssh://$1"
    export RUNNER_NAME="$1"
nimrod's avatar
nimrod committed
    until docker-compose up --detach --remove-orphans ; do true; done
nimrod's avatar
nimrod committed
    # shellcheck disable=SC2034
    for i in $(seq 12)
    do
        # shellcheck disable=SC2046
        docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$' || break
        sleep 10
    done
    # shellcheck disable=SC2046
    ! docker container inspect --format '{{ .State.Health.Status }}' $(docker-compose ps -q) | grep -v '^healthy$'
    unset DOCKER_HOST
    unset RUNNER_NAME
}

if [ -z "${REGISTRATION_TOKEN:-}" ]
then
    echo "REGISTRATION_TOKEN isn't set." >&2
    exit 1
fi

nimrod's avatar
nimrod committed
case "${1:-all}" in
    ns4) export REGISTER_RUN_UNTAGGED="true"
        export BUILDS='/builds'
        _deploy ns4
        ;;
    kodi) export REGISTER_RUN_UNTAGGED="false"
        unset BUILDS
        _deploy kodi
        ;;
    host01) export REGISTER_RUN_UNTAGGED="false"
        unset BUILDS
        _deploy host01
        ;;
    all) deploy ns4; deploy host01; deploy kodi ;;
    *) echo 'Unknown host.' >&2; exit 1;;
esac