-
Notifications
You must be signed in to change notification settings - Fork 1
74 lines (63 loc) · 2.56 KB
/
cd.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
name: Django CD # workflow 이름
on: # Event
pull_request:
types:
- closed
branches: [ develop ]
jobs: # Job
cd: # Job 이름
if: github.event.pull_request.merged == true # Job 실행 조건
runs-on: ubuntu-latest # Runner
steps: # Step
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
# 라이브러리 설치
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
# 도커 허브 사용을 위해 도커에 로그인
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }} # 도커 홈페이지에서 발급받은 토큰 사용
# 이미지 빌드를 위해 .env 생성
- name: Setting .env
run: |
# echo "${{ secrets.ENV }}" >> .env
echo "DATABASE_NAME=${{ secrets.DATABASE_NAME }}" >> .env
echo "DATABASE_USER=${{ secrets.DATABASE_USER }}" >> .env
echo "DATABASE_PASSWORD=${{ secrets.DATABASE_PASSWORD }}" >> .env
echo "DATABASE_HOST=${{ secrets.DATABASE_HOST }}" >> .env
echo "DATABASE_PORT=${{ secrets.DATABASE_PORT }}" >> .env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
# ... add other variables
cat .env
# docker-compose에서 사용하는 이미지들을 build, 공식 이미지들은 x
- name: Build docker images
run: docker-compose -f docker-compose.yml build
# docker images
# docker hub repository에 이미지들을 push
- name: Push docker images
run: docker-compose -f docker-compose.yml push
# ssh를 통해 EC2에 접속, 접속한 후에 실행할 스크립트 작성
- name: Connect to EC2 using SSH
uses: appleboy/ssh-action@master
with:
host: ${{secrets.AWS_HOST}}
username: ${{secrets.AWS_USERNAME}}
password: ${{ secrets.PASSWD }}
key: ${{ secrets.AWS_KEY_PEM }}
envs: GITHUB_SHA
script: |
cd NextPage/backend/
git pull
cd ../
sudo docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml down
sudo docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml pull
sudo docker-compose -f docker-compose.yml -f docker-compose.monitoring.yml up -d --build