Skip to content

fix(cd): ensure environment variables are set and Docker Compose is u… #13

fix(cd): ensure environment variables are set and Docker Compose is u…

fix(cd): ensure environment variables are set and Docker Compose is u… #13

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/${{ secrets.USERNAME }}/telex-commit-integration
# 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=${{ secrets.MY_GITHUB_SECRET }}" > .env
echo "CHANNEL_ID=${{ secrets.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