-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (54 loc) · 2.11 KB
/
deploy.yml
File metadata and controls
72 lines (54 loc) · 2.11 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
68
69
70
71
72
name: Auto Deploy Django Application
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
types: [closed]
jobs:
deploy:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
runs-on: ubuntu-latest
steps:
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.3
with:
host: 20.39.60.118
username: azureuser
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Starting auto-deployment..."
# Navigate to app directory
cd /home/azureuser/app
# Stop the Django server
sudo supervisorctl stop django-server || true
# Pull latest changes
git pull origin main || git pull origin master
# Activate virtual environment and install/update dependencies
source venv/bin/activate
# Install any new dependencies
if [ -f requirements.txt ]; then
pip install -r requirements.txt --no-cache-dir
elif [ -f */requirements.txt ]; then
pip install -r */requirements.txt --no-cache-dir
fi
# Set environment variables from GitHub secrets
# Find Django project directory
MANAGE_PY=$(find . -name "manage.py" | head -1)
if [ -n "$MANAGE_PY" ]; then
PROJECT_DIR=$(dirname "$MANAGE_PY")
cd "$PROJECT_DIR"
# Run migrations
python manage.py migrate --noinput
# Collect static files
python manage.py collectstatic --noinput || true
# Run additional commands if any
# Additional commands
pip install requirements.txt
fi
# Start the Django server
sudo supervisorctl start django-server
# Wait a moment and check status
sleep 5
sudo supervisorctl status django-server
echo "Auto-deployment completed!"