Skip to content

Update deployment workflow and form validation #15

Update deployment workflow and form validation

Update deployment workflow and form validation #15

Workflow file for this run

name: Deploy to Hostinger VPS
on:
push:
branches:
- main # Trigger when changes are pushed to the 'main' branch
jobs:
deploy:
runs-on: ubuntu-latest # The job will run on an Ubuntu runner
steps:
- name: Checkout code
uses: actions/checkout@v2 # This step checks out your code from the repository
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x' # Use the appropriate Python version for your project
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt # Make sure you have a 'requirements.txt' in your project
- name: Set up SSH agent
uses: webfactory/ssh-agent@v0.5.3
with:
ssh-private-key: ${{ secrets.HOSTINGER_SSH_PRIVATE_KEY }} # Use the private key from GitHub Secrets
- name: Deploy to VPS
run: |
ssh -o StrictHostKeyChecking=no root@147.93.102.113 << 'EOF'
cd /var/www/Community_Management # Navigate to your Django project directory
echo "Starting deployment..."
# Kill any process using port 80 (development server port)
fuser -k 80/tcp || true # Ignore error if port isn't in use
echo "Killed any processes using port 80"
# Set up virtual environment
python3 -m venv venv
source venv/bin/activate # Activate virtual environment
# Pull the latest code from GitHub
git pull origin main
echo "Pulled latest code from GitHub"
# Install the dependencies from the updated code
pip install -r requirements.txt
# Run database migrations
python manage.py migrate
echo "Ran database migrations"
# Run the Django development server in the background (not recommended for production)
nohup python manage.py runserver 0.0.0.0:80 > server.log 2>&1 &
echo "Started Django development server"
EOF