-
Notifications
You must be signed in to change notification settings - Fork 3
133 lines (115 loc) · 4.23 KB
/
django-deploy.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Web Application CI/CD Pipeline
on:
push:
branches:
- main
pull_request_target:
types: [closed]
jobs:
CI:
runs-on: ubuntu-latest
services:
db:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.DATABASE_USER_PASSWORD }}
MYSQL_DATABASE: ${{ secrets.DATABASE_NAME }}
MYSQL_USER: ${{ secrets.DATABASE_USER }}
MYSQL_PASSWORD: ${{ secrets.DATABASE_USER_PASSWORD }}
ports:
- 3306:3306
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Create .env file
run: |
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "DEBUG=${{ secrets.DEBUG }}" >> .env
echo "DJANGO_DEPLOY=${{ secrets.DJANGO_DEPLOY }}" >> .env
echo "DATABASE_ENGINE=${{ secrets.DATABASE_ENGINE }}" >> .env
echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_USER_PASSWORD=${{ secrets.DATABASE_USER_PASSWORD }}" >> .env
echo "DATABASE_HOST=${{ secrets.DATABASE_HOST }}" >> .env
echo "DATABASE_PORT=${{ secrets.DATABASE_PORT }}" >> .env
echo "CELERY_BROKER_URL=${{ secrets.CELERY_BROKER_URL }}" >> .env
echo "CELERY_RESULT_BACKEND=${{ secrets.CELERY_RESULT_BACKEND }}" >> .env
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" >> .env
echo "KAKAO_CALLBACK_URI=${{ secrets.KAKAO_CALLBACK_URI }}" >> .env
echo "BACK_BASE_URL=${{ secrets.BACK_BASE_URL }}" >> .env
echo "KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}" >> .env
echo "SMS_TOKEN_KEY=${{ secrets.SMS_TOKEN_KEY }}" >> .env
echo "SMS_API_KEY=${{ secrets.SMS_API_KEY }}" >> .env
echo "SEND_PHONE=${{ secrets.SEND_PHONE }}" >> .env
echo "SSODAA_BASE_URL=${{ secrets.SSODAA_BASE_URL }}" >> .env
echo "TURNSTILE_SECRET_KEY=${{ secrets.TURNSTILE_SECRET_KEY }}" >> .env
cat .env
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run migrations and tests
run: |
cat .env
python manage.py makemigrations
python manage.py migrate
python manage.py test
build_and_push:
needs: CI
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}:${{ GITHUB.SHA }}
deploy:
needs: build_and_push
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: SSH into server and pull Docker image
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
cd /root/linenow-dev
git pull origin main
docker-compose down
docker-compose pull
docker-compose up --build -d
- name: Collect static files
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
docker exec linenow-was python manage.py collectstatic --noinput
- name: Cleanup Docker resources on server # Docker 자원 정리 작업 추가
uses: appleboy/[email protected]
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
password: ${{ secrets.SSH_PASSWORD }}
port: ${{ secrets.SSH_PORT }}
script: |
docker system prune -f