-
Notifications
You must be signed in to change notification settings - Fork 1
80 lines (71 loc) · 2.46 KB
/
django_cicd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Django CI/CD
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
#CI pipeline
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ['3.10', '3.11']
steps:
#코드 체크아웃
- uses: actions/checkout@v4
#파이썬 설정
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# pip 캐시 추가
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/backend/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
#의존성 설치
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r backend/requirements.txt
#테스트 실행
- name: Run Tests
run: |
cd backend/worklog
python manage.py test auth
python manage.py test profiles
#빌드 실패 시 오류 보고 후 정지
- name: Report Build Failure
if: failure()
run: echo "Build failed. Skipping deployment."
continue-on-error: false
#CD pipeline
deploy:
runs-on: ubuntu-latest
needs: build
if: success()
steps:
#AWS EC2로 배포
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd worklog/backend/
git pull origin main
cd ../..
source worklogvenv/bin/activate
cd worklog/backend/
pip install -r requirements.txt
cd worklog/
python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic --noinput
sudo systemctl restart gunicorn