Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
yooooonshine committed Sep 1, 2024
2 parents ea167fe + 284c51a commit 2ef20a1
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 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,45 @@ jobs:
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools
pip install django djangorestframework drf-yasg
working-directory: aiServer

- name: Create secrets.json
run: |
echo '{"SECRET_KEY": "${{ secrets.SECRET_KEY }}"}' > aiServer/secrets.json
deploy:
runs-on: ubuntu-latest
needs: build

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

- name: Upload and Deploy Code to EC2
env:
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_USER: ubuntu
EC2_KEY: ${{ secrets.EC2_KEY }}
SECRET: ${{ secrets.SECRETS }}
run: |
python manage.py test
working-directory: aiServer
echo "${{ secrets.EC2_KEY }}" > key.pem
chmod 400 key.pem
# secrets.json 파일 생성
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << 'EOF'
echo '{"SECRET_KEY": "'"${SECRETS}"'"}' > /home/ubuntu/aiServer/secrets.json
EOF
# 코드 업로드
scp -o StrictHostKeyChecking=no -i key.pem -r ./aiServer $EC2_USER@$EC2_HOST:/home/ubuntu/
# 서버에 접속하여 작업 수행
ssh -o StrictHostKeyChecking=no -i key.pem $EC2_USER@$EC2_HOST << 'EOF'
cd /home/ubuntu/aiServer || exit 1
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
pip install setuptools django djangorestframework drf-yasg gunicorn
nohup gunicorn --bind 0.0.0.0:8000 aiServer.wsgi:application &
sudo service nginx restart
EOF
# 사용된 키 삭제
rm key.pem

0 comments on commit 2ef20a1

Please sign in to comment.