#!/usr/bin/env bash set -euo pipefail HOST="${BTCPRICE_DEPLOY_HOST:-citadel}" APP_DIR="${BTCPRICE_DEPLOY_DIR:-/home/pmp/apps/btcprice}" IMAGE_NAME="${BTCPRICE_IMAGE_NAME:-btcprice:latest}" PLATFORM="${BTCPRICE_PLATFORM:-}" COMPOSE_FILE="docker-compose.citadel.yml" ENV_FILE=".env.citadel" FILES=("$COMPOSE_FILE" "$ENV_FILE") 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 BTCPRICE_PLATFORM manually, e.g. BTCPRICE_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 $COMPOSE_FILE and $ENV_FILE to $HOST:$APP_DIR..." scp "$COMPOSE_FILE" "$HOST:$APP_DIR/docker-compose.yml" scp "$ENV_FILE" "$HOST:$APP_DIR/.env" 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"