diff options
Diffstat (limited to 'deploy.sh')
| -rwxr-xr-x | deploy.sh | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/deploy.sh b/deploy.sh new file mode 100755 index 0000000..aca4181 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Deploy script to push code to a server via scp and run it + +set -e + +if [ $# -lt 4 ]; then + echo "Usage: $0 <ip> <name> <port> <strategy> [ssh_config]" + exit 1 +fi + +SERVER="$1" +NAME="$2" +PORT="$3" +SSH_CONFIG="${4:-../../ssh.config}" + +# Validate port range +if [ "$PORT" -lt 8001 ] || [ "$PORT" -gt 8003 ]; then + echo "Error: PORT must be between 8001 and 8003 (inclusive)" + exit 1 +fi +USER="evroc-user" +REMOTE_PATH="~/hackathon/$PORT" + +echo "Deploying to $USER@$SERVER:$REMOTE_PATH..." + +# Create remote directory if it doesn't exist +ssh -F "$SSH_CONFIG" "$USER@$SERVER" "mkdir -p $REMOTE_PATH" + +# Remove everything in remote directory except .venv +echo "Cleaning up remote directory (keeping .venv)..." +ssh -F "$SSH_CONFIG" "$USER@$SERVER" "cd $REMOTE_PATH && find . -maxdepth 1 -not -name '.venv' -not -name '.' -exec rm -rf {} + 2>/dev/null || true" + +# Create a temporary directory with files to deploy +DEPLOY_DIR=$(mktemp -d) +trap "rm -rf $DEPLOY_DIR" EXIT + +# Copy project files to temp directory (excluding .venv, .git, etc.) +echo "Preparing files for deployment..." +find . -type f ! -path './.venv/*' ! -path './.git/*' ! -path './__pycache__/*' ! -name '*.pyc' ! -name '.env' -print0 | \ + tar -cf - --null -T - | \ + tar -xf - -C "$DEPLOY_DIR" + +# Deploy using scp +echo "Copying files via scp..." +scp -q -F "$SSH_CONFIG" -r "$DEPLOY_DIR/"* "$USER@$SERVER:$REMOTE_PATH/" + +# Execute setup and run on remote server with port +echo "Running setup and execution script on remote server..." +ssh -F "$SSH_CONFIG" "$USER@$SERVER" "bash $REMOTE_PATH/setup-and-run.sh $NAME $PORT" |