diff --git a/deploy-citadel.sh b/deploy-citadel.sh new file mode 100755 index 0000000..350e2c9 --- /dev/null +++ b/deploy-citadel.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +set -euo pipefail + +HOST="${ELPRICE_DEPLOY_HOST:-citadel}" +APP_DIR="${ELPRICE_DEPLOY_DIR:-/home/pmp/app/elprice}" +IMAGE_NAME="${ELPRICE_IMAGE_NAME:-$(basename "$APP_DIR")-app:latest}" +PLATFORM="${ELPRICE_PLATFORM:-}" +FILES=(docker-compose.yml .env .token) + +if [[ -z "$PLATFORM" ]]; then + remote_arch="$(ssh "$HOST" uname -m)" + case "$remote_arch" in + x86_64|amd64) PLATFORM="linux/amd64" ;; + aarch64|arm64) PLATFORM="linux/arm64" ;; + *) + echo "Unsupported target architecture: $remote_arch" >&2 + echo "Set ELPRICE_PLATFORM manually, e.g. ELPRICE_PLATFORM=linux/amd64" >&2 + exit 1 + ;; + esac +fi + +for file in "${FILES[@]}"; do + if [[ ! -f "$file" ]]; then + echo "Missing required file: $file" >&2 + exit 1 + fi +done + +echo "Building $IMAGE_NAME locally for $PLATFORM..." +docker build --platform "$PLATFORM" -t "$IMAGE_NAME" . + +echo "Preparing $APP_DIR on $HOST..." +ssh "$HOST" "mkdir -p '$APP_DIR'" + +echo "Copying docker-compose.yml, .env, and .token to $HOST:$APP_DIR..." +scp "${FILES[@]}" "$HOST:$APP_DIR/" + +echo "Copying Docker image $IMAGE_NAME to $HOST..." +docker save "$IMAGE_NAME" | ssh "$HOST" docker load + +echo "Starting docker compose on $HOST in $APP_DIR..." +ssh "$HOST" "cd '$APP_DIR' && docker compose up -d --no-build"