Skip to content

Merge pull request #20 from SaaSy-Pants/abhishekpaul11-patch-3 #5

Merge pull request #20 from SaaSy-Pants/abhishekpaul11-patch-3

Merge pull request #20 from SaaSy-Pants/abhishekpaul11-patch-3 #5

Workflow file for this run

# .github/workflows/deploy.yml
name: CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout Repository
uses: actions/checkout@v3
# Step 2: Set up Python
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: '3.9'
# Step 3: Install dependencies
- name: Install Dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install pytest
pip install -r requirements.txt
# Step 4: Deploy to EC2
- name: Deploy to EC2
uses: appleboy/ssh-action@v0.1.7
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
port: 22
script: |
# Define environment variables if needed
export APP_DIR=/home/ec2-user/SaaSy-Events-eventhandler
# Navigate to the application directory
mkdir -p $APP_DIR
cd $APP_DIR
# Initialize Git repository if not already initialized
if [ ! -d ".git" ]; then
git init
git remote add origin https://github.com/SaaSy-Pants/SaaSy-Events-eventhandler.git
fi
# Pull the latest changes from GitHub
git fetch origin
git reset --hard origin/main
# Set up Python environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
# Kill any existing main.py process
pkill -f "python3 main.py" || true
# Run main.py in the background using nohup
nohup python3 main.py > app.log 2>&1 &