Skip to content

chore: add git fetch to CD pipeline #9

chore: add git fetch to CD pipeline

chore: add git fetch to CD pipeline #9

Workflow file for this run

name: Deploy to EC2
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Deploy to EC2
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.SERVER_IP }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
username: ${{ secrets.USERNAME }}
script: |
echo "Starting deployment..."
# Navigate to project directory
cd /home/$USERNAME/telex-commit-intergration
# Fetch and reset to main
echo "Fetching latest changes..."
git fetch origin main
echo "Resetting to origin/main..."
git reset --hard origin/main
# Create .env file with environment variables
echo "MY_GITHUB_SECRET=${MY_GITHUB_SECRET}" > .env
echo "CHANNEL_ID=${CHANNEL_ID}" >> .env
chmod 600 .env
# Deploy using Docker Compose
sudo docker-compose down
sudo docker-compose up --build -d
sudo docker system prune -f