diff --git a/.github/workflows/deploy_backend.yml b/.github/workflows/deploy_backend.yml new file mode 100644 index 0000000..8c15db0 --- /dev/null +++ b/.github/workflows/deploy_backend.yml @@ -0,0 +1,23 @@ +name: Deploy to EC2 + +on: + push: + branches: + - main + paths: + - app/** + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Deploy to EC2 + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.EC2_HOST }} + username: ubuntu + key: ${{ secrets.EC2_SSH_KEY }} + script: | + cd ~/yt_translator + app/post_update.sh diff --git a/app/post_update.sh b/app/post_update.sh index 870a088..5cd8aca 100644 --- a/app/post_update.sh +++ b/app/post_update.sh @@ -1,7 +1,10 @@ #!/bin/bash +cd ~/yt_translator +git pull origin main + # Copy custom settings file -if [ ! -f settings.py ]; then +if [ ! -f video_host/settings.py ]; then echo "Restoring settings.py..." cp /home/ubuntu/settings_backup/settings.py video_host/settings.py fi @@ -9,4 +12,9 @@ fi source /home/ubuntu/yt_translator/venv/bin/activate python manage.py migrate +sudo systemctl stop gunicorn +sudo systemctl daemon-reload +sudo systemctl start gunicorn +sudo systemctl enable gunicorn +