#!/bin/sh # Build the application image, create local Swarm secrets once, deploy the stack. # # Prerequisites: Docker Engine with Swarm mode (docker swarm init is done here if # needed) and the files created by scripts/bootstrap-secrets.sh. No secret value # is printed. This is the one documented bootstrap sequence for stack.yaml. set -eu root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) cd "$root" # The public failover test invokes the action script without a shell; it must be # executable on POSIX. Git may not preserve the mode on a Windows checkout. chmod +x scripts/stop-one.sh scripts/restore.sh scripts/restart.sh scripts/rolling-update.sh scripts/deploy.sh 2>/dev/null || true stack=${STACK_NAME:-lab3} image=${API_IMAGE:-mtusi-messenger-lab3:3.0.0} # Single host uses the locally built image; multi-node requires a registry and # RESOLVE_IMAGE=always after `docker push` (see REPORT.md). resolve=${RESOLVE_IMAGE:-never} state=$(docker info --format '{{.Swarm.LocalNodeState}}') if [ "$state" != "active" ]; then docker swarm init >/dev/null fi sh scripts/bootstrap-secrets.sh for name in database_url cache_url postgres_password cursor_secret; do if ! docker secret inspect "${stack}_${name}" >/dev/null 2>&1; then docker secret create "${stack}_${name}" "secrets/${name}" >/dev/null fi done docker build -t "$image" . API_IMAGE="$image" docker stack deploy --resolve-image "$resolve" -c stack.yaml "$stack" i=0 while [ "$i" -lt 90 ]; do if curl -fsS "http://127.0.0.1:${APP_PORT:-8080}/health/ready" >/dev/null 2>&1; then printf 'deployed: http://127.0.0.1:%s (image %s)\n' "${APP_PORT:-8080}" "$image" docker stack services "$stack" exit 0 fi i=$((i + 1)) sleep 2 done printf 'stack did not become ready within 180s\n' >&2 docker stack services "$stack" >&2 || true exit 1