#!/bin/bash # Exit on any error set -e UAT_USER="$CK_UAT_USER" UAT_HOST="$CK_UAT_HOST" DEPLOYMENT_DIR="$(date +%s)" UAT_DEST_DIR="$CK_UAT_DEPLOYMENT_DIR/$(whoami)/$DEPLOYMENT_DIR" PROJECT_ROOT="${1:-$(pwd)}" IDENTITY_KEY="$HOME/.ssh/${CK_DEPLOY_KEY_NAME:-id_optivex}" if [ ! -f "$IDENTITY_KEY" ]; then echo "Identity key not found. Please check your SSH configuration." exit 1 fi echo "Starting deployment..." echo " -> Deployment id: $DEPLOYMENT_DIR" if [ -z "$VIRTUAL_ENV" ]; then if [ -d ".venv" ]; then echo "Activating virtual environment from .venv..." source .venv/bin/activate else echo "No virtual environment found. Please create one and try again." exit 1 fi fi echo "Building the project with 'uv'..." uv build DIST_DIR="$PROJECT_ROOT/dist" if [ ! -d "$DIST_DIR" ]; then echo "Build failed or dist directory not found." exit 1 fi echo "Copying files to UAT server..." # Create destination directory all the way into the logs directory ssh -i "$IDENTITY_KEY" -o StrictHostKeyChecking=no "$UAT_USER@$UAT_HOST" "mkdir -p $UAT_DEST_DIR/logs" # -O forces legacy SCP protocol (OpenSSH 8.7+ defaults to SFTP, which # the restricted_deploy.sh forced command does not allow) scp -O -i "$IDENTITY_KEY" -o StrictHostKeyChecking=no -r "$DIST_DIR/"* "$UAT_USER@$UAT_HOST:$UAT_DEST_DIR/" if [ $? -ne 0 ]; then echo "File transfer failed." exit 1 fi echo "Deployment to UAT complete." echo "Tests results will soon be available at /tmp/$DEPLOYMENT_DIR/test_results.xml" echo "Bumping patch version of the application for the next deployment..." uv version --bump patch echo "All done!"