-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
Β·50 lines (38 loc) Β· 1.44 KB
/
deploy.sh
File metadata and controls
executable file
Β·50 lines (38 loc) Β· 1.44 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
#!/bin/bash
set -e # Exit immediately if any command fails
set -x # Print each command as it runs
echo "π Starting deployment to EC2..."
# Decode the base64 deploy key and set permissions
echo "$DEPLOY_KEY" | base64 -d > travis_temp_key
chmod 600 travis_temp_key
# Test SSH connection
echo "π Testing SSH connection..."
ssh -o StrictHostKeyChecking=no -i travis_temp_key $EC2_USER@$EC2_HOST "echo 'β
SSH connection successful'"
# Run deployment commands on EC2
ssh -o StrictHostKeyChecking=no -i travis_temp_key $EC2_USER@$EC2_HOST << EOF
echo "π Navigating to project directory..."
cd ~/team2-wed-fall25 || { echo "β Directory not found"; exit 1; }
echo "π Pulling latest code from LeBranch..."
git fetch origin develop
git reset --hard origin/develop
echo "π Activating virtual environment..."
if [ -f "venv/bin/activate" ]; then
source venv/bin/activate
echo "β
Virtualenv activated"
else
echo "β Virtualenv not found, exiting"
exit 1
fi
echo "π¦ Installing dependencies..."
pip install -r requirements.txt
echo "ποΈ Applying migrations..."
python manage.py migrate --noinput
echo "πΌοΈ Collecting static files..."
python manage.py collectstatic --noinput
echo "π Restarting Gunicorn..."
sudo systemctl restart gunicorn
echo "β
Deployment finished successfully"
EOF
# Cleanup: remove the temporary key
rm -f travis_temp_key
echo "π§Ή Temporary key removed"