#!/bin/bash # deploy.sh — Remote deploy for Aether Platform # Run on srv-nyx directly, or triggered via SSH from the workstation. # # Usage: ./deploy.sh [app_branch] [api_branch] # Example: ./deploy.sh prod # ./deploy.sh test ae_app_3x_llm development # # From workstation (npm run deploy:remote:prod / deploy:remote:test): # ssh linode.oneskyit.com 'bash /srv/env/prod_aether/deploy.sh prod' # ssh linode.oneskyit.com 'bash /srv/env/test_aether/deploy.sh test' # # NOTE: bak_aether shares the same app/api dirs as prod. # After a prod deploy, restart bak containers manually if running: # cd /srv/env/bak_aether && docker compose restart ae_app ae_api set -euo pipefail ensure_bitbucket_ssh_remote() { local repo_path=$1 local remote_url local remote_path remote_url=$(git -C "$repo_path" remote get-url origin) if [[ "$remote_url" =~ ^https://([^@/]+@)?bitbucket\.org/(.+)$ ]]; then remote_path=${BASH_REMATCH[2]} git -C "$repo_path" remote set-url origin "git@bitbucket.org:${remote_path}" fi } ENV=${1:-} if [ -z "$ENV" ]; then echo "Usage: $0 [app_branch] [api_branch]" exit 1 fi # --- Environment config --- # TODO: Update default branches once prod/test branch strategy is finalized. # Currently both envs pull from the same working branches. if [ "$ENV" = "prod" ]; then APP_DIR=/srv/apps/prod_aether_app_sveltekit API_DIR=/srv/apps/prod_aether_api_fastapi COMPOSE_DIR=/srv/env/prod_aether BUILD_MODE=prod APP_BRANCH=${2:-ae_app_3x_llm} API_BRANCH=${3:-development} elif [ "$ENV" = "test" ]; then APP_DIR=/srv/apps/test_aether_app_sveltekit API_DIR=/srv/apps/test_aether_api_fastapi COMPOSE_DIR=/srv/env/test_aether BUILD_MODE=test APP_BRANCH=${2:-ae_app_3x_llm} API_BRANCH=${3:-development} else echo "Unknown environment: '$ENV' (expected: prod or test)" exit 1 fi echo "" echo "========================================" echo " Aether Deploy: $ENV" echo " App: $APP_DIR [$APP_BRANCH]" echo " API: $API_DIR [$API_BRANCH]" echo " Mode: $BUILD_MODE" echo "========================================" echo "" # --- Pull repos --- echo "[1/4] Pulling container env..." ensure_bitbucket_ssh_remote "$COMPOSE_DIR" git -C "$COMPOSE_DIR" pull --ff-only echo "" echo "[2/4] Pulling app ($APP_BRANCH)..." ensure_bitbucket_ssh_remote "$APP_DIR" git -C "$APP_DIR" pull --ff-only origin "$APP_BRANCH" echo "" echo "[3/4] Pulling API ($API_BRANCH)..." ensure_bitbucket_ssh_remote "$API_DIR" git -C "$API_DIR" pull --ff-only origin "$API_BRANCH" # --- Build and deploy --- echo "" echo "[4/4] Building and deploying..." cd "$COMPOSE_DIR" docker compose build --build-arg BUILD_MODE="$BUILD_MODE" ae_app docker compose up -d ae_app docker compose restart ae_api echo "" echo "========================================" echo " Done: $ENV deployed successfully" echo "========================================" if [ "$ENV" = "prod" ]; then echo "" echo " bak_aether uses the same code dirs — if its containers" echo " are running, restart them:" echo " cd /srv/env/bak_aether && docker compose restart ae_app ae_api" fi echo ""