#!/usr/bin/env bash # Run on the server, next to the compose file, or with its directory as $1. # No remote shell required: the release scripts on Windows publish an image # and stop there, and this is the other half. # # Rename `app` and `APP_DATA` to your service's name. set -euo pipefail cd "${1:-$(dirname "$(readlink -f "$0")")}" [[ -s .env ]] || { echo 'Install .env before deploying.' >&2; exit 1; } # Where the data directory is depends on APP_DATA, which the compose file also # reads. Pulled out of .env rather than sourced, because Compose's .env is not # a shell script and running it as one is how a stray quote becomes a surprise. DATA=$(sed -n 's/^[[:space:]]*APP_DATA=\([^#]*\).*/\1/p' .env | tail -1 | xargs || true) DATA=${DATA:-./data} [[ -s "$DATA/config.yaml" ]] || { echo "Install $DATA/config.yaml before deploying." >&2 exit 1 } # Pull explicitly, here and nowhere else: the compose file has no pull policy, # so starting or importing never fetches an image on its own. A registry # failure must leave the running service alone, not deploy a cache. echo 'Pulling the configured image…' if ! docker compose pull app; then echo 'Image pull failed; app was not restarted.' >&2 exit 1 fi # Use the image just pulled. Do not start or recreate other services in the # file. `--wait` holds until the container's own HEALTHCHECK passes. if ! docker compose up -d --no-deps --pull never --wait --wait-timeout 240 app; then docker compose ps app >&2 || true echo 'Deployment failed. Check docker compose logs app.' >&2 exit 1 fi docker compose ps app