Skip to content

Commit

Permalink
Update django_CI.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
2ming00 authored Aug 31, 2024
1 parent 561aed8 commit 1656e66
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions .github/workflows/django_CI.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Django CI
name: Django CI/CD

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches: ["main"]

jobs:
build:
Expand All @@ -22,14 +20,43 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools
pip install django djangorestframework drf-yasg
- name: Create secrets.json
run: |
echo '{"SECRET_KEY": "${{ secrets.SECRET_KEY }}"}' > aiServer/secrets.json
working-directory: aiServer

- name: Run Tests
run: |
python manage.py test
working-directory: aiServer

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Upload Code to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
run: |
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
scp -o StrictHostKeyChecking=no -i key.pem -r ./aiServer ubuntu@$EC2_HOST:/home/ubuntu/
- name: Deploy to EC2
run: |
ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@$EC2_HOST << 'EOF'
cd /home/ubuntu/aiServer
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install django djangorestframework drf-yasg
nohup gunicorn --bind 0.0.0.0:8000 aiServer.wsgi:application &
sudo service nginx restart
EOF
rm key.pem

0 comments on commit 1656e66

Please sign in to comment.