Merge pull request #54 from DowaDream/fix/#53-social-login #33
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
name: DowaDream CI/CD | |
on: # action을 언제 실행할지 설정 | |
push: | |
branches: ["main"] # main 브랜치가 push될 때마다 github action이 실행됨 | |
jobs: | |
CI: | |
name: 'CI' | |
runs-on: ubuntu-latest | |
strategy: | |
max-parallel: 4 # 병렬 처리 | |
matrix: | |
python-version: ["3.10"] | |
steps: | |
- uses: actions/checkout@v3 # 기본적으로 사용하는 github action 라이브러리 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: # 파이썬 버전 설정 | |
python-version: ${{ matrix.python-version }} | |
- name: Install requirements.txt | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Generate env file | |
run: | | |
echo "$ENV_FILE" >> .env | |
env: | |
ENV_FILE: ${{ secrets.ENV_FILE }} | |
- name: Run Tests | |
run: | | |
python manage.py test | |
CD: # 배포 | |
name: 'CD' | |
needs: CI # CI가 완료되면 CD 시작 | |
runs-on: ubuntu-latest | |
steps: | |
- name: Connect EC2 | |
uses: appleboy/ssh-action@master # EC2 SSH 연결을 도와주는 라이브러리 | |
env: | |
ENV_FILE: ${{ secrets.ENV_FILE }} | |
with: | |
host: ${{ secrets.HOST }} # EC2 IP 주소 | |
username: ${{ secrets.USERNAME }} # EC2 username | |
key: ${{ secrets.KEY }} # pem키 | |
command_timeout: 1m | |
port: 22 | |
envs: ENV_FILE | |
script: | | |
echo "EC2 연결 성공" | |
sudo apt-get update | |
sudo apt-get -y upgrade | |
cd /home/ubuntu/DowaDream-Server | |
source venv/bin/activate | |
git pull | |
echo "git pull 성공" | |
echo "$ENV_FILE" >> .env | |
pip install -r requirements.txt | |
echo "requirements.txt 설치 성공" | |
sudo lsof -t -i tcp:8000 | xargs kill -9 | |
python manage.py migrate | |
nohup python manage.py runserver 0.0.0.0:8000 > nohup.out 2> nohup.err < /dev/null & | |
echo "배포 성공" | |
exit 0 |