summaryrefslogtreecommitdiff
path: root/deploy.sh
blob: aca4181b9079b387a2541155219cf8a288f24726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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"