Skip to content

Commit

Permalink
[SETTINGS] 자동 재배포 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
hnnynh committed Feb 17, 2024
1 parent f25fc03 commit 66f6cd1
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
name: Deploy
name: Django EC2 Deploy

on:
push:
branches:
- deploy
branches: [main, cd]
pull_request:
branches: [main, cd]

jobs:
deploy:
runs-on: ubuntu-latest

cd:
name: "Django CD"
needs: ci
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up SSH
uses: webfactory/[email protected]
- name: EC2 ssh connection test
uses: appleboy/ssh-action@master
with:
ssh-private-key: ${{ secrets.CHUNGHAHA_DEPLOY_KEY }}

- name: SSH to EC2 and kill running processes
run: |
ssh ubuntu@ip-172-31-1-75 "ps -ef | grep manage.py | grep -v grep | awk '{print \$2}' | xargs -r kill -9"
- name: Activate virtualenv and install dependencies
run: |
ssh ubuntu@ip-172-31-1-75 "source venv/bin/activate && cd cau-likelion-django && pip install -r requirements.txt"
- name: Update code and run server
run: |
ssh ubuntu@ip-172-31-1-75 "git pull origin main && nohup python manage.py runserver 0.0.0.0:8000 &"
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PEM }}
command_timeout: 3m
script: |
sudo apt-get update
sudo apt-get -y upgrade
cd cau-likelion-django
source venv/bin/activate
git pull origin main
sudo lsof -t -i tcp:8000 | xargs kill -9
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
nohup python manage.py runserver 0.0.0.0:8000 &
exit 0

0 comments on commit 66f6cd1

Please sign in to comment.