Skip to content
Snippets Groups Projects
Commit c4e8117b authored by nimrod's avatar nimrod
Browse files

deploy: Use Docker contexts.

Use Docker contexts in the deploy script and the Compose plugin to
deploy (instead of forwarding sockets over SSH).
parent 1947ea8a
No related branches found
No related tags found
No related merge requests found
Pipeline #4389 passed
#!/bin/sh #!/bin/sh
set -eu set -eu
_docker_compose() {
docker-compose "$@" 2>&1 | sed '/^ File /,+1d'
}
_check() { _check() {
containers="$(until _docker_compose ps -q; do true; done)" host="$1"
containers="$(until docker --context "$host" compose ps -q; do true; done)"
# shellcheck disable=SC2086 # shellcheck disable=SC2086
docker container inspect --format '{{ .State.Health.Status }}' $containers | grep -v '^healthy$' docker --context "$host" container inspect --format '{{ .State.Health.Status }}' $containers | grep -v '^healthy$'
} }
_deploy() { _deploy() {
host="$1" host="$1"
printf '\n\e[1;94m=== %s ====\e[0m\n\n' "Deploying to $host" >&2 printf '\n\e[1;94m=== %s ====\e[0m\n\n' "Deploying to ${host}.shore.co.il" >&2
localsocket="$HOME/.ssh/docker_$host.sock" export RUNNER_NAME="${host}.shore.co.il"
forward "$host" "$localsocket:/var/run/docker.sock" until docker --context "$host" compose up --detach --remove-orphans ; do true; done
export DOCKER_HOST="unix://$localsocket"
export RUNNER_NAME="$host"
until _docker_compose up --detach --remove-orphans ; do true; done
# shellcheck disable=SC2034
for i in $(seq 12) for i in $(seq 12)
do do
# shellcheck disable=SC2046 _check "$host" || break
_check || break
sleep 10 sleep 10
done done
# shellcheck disable=SC2046 # shellcheck disable=SC2251
! _check ! _check "$host"
unset DOCKER_HOST
unset RUNNER_NAME unset RUNNER_NAME
} }
...@@ -48,15 +39,15 @@ do ...@@ -48,15 +39,15 @@ do
case "$i" in case "$i" in
ns4) export REGISTER_RUN_UNTAGGED="true" ns4) export REGISTER_RUN_UNTAGGED="true"
export BUILDS='/builds' export BUILDS='/builds'
_deploy ns4.shore.co.il _deploy ns4
;; ;;
kodi) export REGISTER_RUN_UNTAGGED="false" kodi) export REGISTER_RUN_UNTAGGED="false"
unset BUILDS unset BUILDS
_deploy kodi.shore.co.il _deploy kodi
;; ;;
host01) export REGISTER_RUN_UNTAGGED="false" host01) export REGISTER_RUN_UNTAGGED="false"
unset BUILDS unset BUILDS
_deploy host01.shore.co.il _deploy host01
;; ;;
all) "$0" ns4 host01 kodi ;; all) "$0" ns4 host01 kodi ;;
*) echo 'Unknown host.' >&2; exit 1;; *) echo 'Unknown host.' >&2; exit 1;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment