-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·67 lines (51 loc) · 2.16 KB
/
deploy.sh
File metadata and controls
executable file
·67 lines (51 loc) · 2.16 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Deployment script for Prex Challenge server monitoring system
# Variables - EC2 instance details
EC2_HOST="15.228.201.242" # Public IP of the EC2 instance
KEY_PATH="./prex-challenge-key.pem"
REMOTE_USER="ubuntu" # Default user for Ubuntu AMIs
REMOTE_DIR="/home/ubuntu/prex-challenge"
# Check if key exists and has correct permissions
if [ ! -f "$KEY_PATH" ]; then
echo "Error: Key file not found at $KEY_PATH"
exit 1
fi
# Ensure key has correct permissions (required by SSH)
chmod 400 "$KEY_PATH"
# Create a deployment package, excluding unnecessary files
echo "Creating deployment package..."
tar --exclude="venv" --exclude=".git" --exclude="__pycache__" --exclude="*.log" --exclude="data" -czf prex-challenge.tar.gz ./
# Create remote directory if it doesn't exist
echo "Creating remote directory..."
ssh -i "$KEY_PATH" -o StrictHostKeyChecking=no "$REMOTE_USER@$EC2_HOST" "mkdir -p $REMOTE_DIR"
# Copy files to EC2 instance
echo "Copying files to EC2 instance..."
scp -i "$KEY_PATH" prex-challenge.tar.gz "$REMOTE_USER@$EC2_HOST:$REMOTE_DIR/"
# Extract files and set up environment on the EC2 instance
echo "Setting up environment on EC2 instance..."
ssh -i "$KEY_PATH" "$REMOTE_USER@$EC2_HOST" << EOF
cd $REMOTE_DIR
tar -xzf prex-challenge.tar.gz
rm prex-challenge.tar.gz
# Install dependencies
sudo apt update
sudo apt install -y python3-pip python3-venv
# Create and activate virtual environment
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Create data directory
mkdir -p data
# Stop any existing API server
pkill -f "python3 api_server/run_api.py" || true
# Start API server in background
nohup python3 api_server/run_api.py --host 0.0.0.0 --port 5000 > api_server.log 2>&1 &
# Set up firewall to allow access to port 5000
sudo ufw allow 5000/tcp
echo "Deployment completed. API server running on port 5000."
EOF
# Clean up local deployment package
rm prex-challenge.tar.gz
echo "Deployment script completed."
echo "To test the agent against your EC2 instance, run:"
echo "python agent/run_agent.py --url http://$EC2_HOST:5000/ --once"