-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
26 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |