From b8bbb191a19e551baff19d5f8624f43f6b592161 Mon Sep 17 00:00:00 2001 From: bendsouza Date: Sat, 11 Jan 2025 15:57:01 +0000 Subject: [PATCH] ensure gunicorn restart when backend updates pushed --- .github/workflows/deploy_backend.yml | 23 +++++++++++++++++++++++ app/post_update.sh | 10 +++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy_backend.yml 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 +