-
Notifications
You must be signed in to change notification settings - Fork 2
54 lines (47 loc) · 1.64 KB
/
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
name: CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
# 1. 코드 체크아웃
- name: Checkout Code
uses: actions/checkout@v3
# 2. .env 파일 생성
- name: Create .env file
run: |
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" > .env
echo "KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}" >> .env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> .env
# 3. Docker 이미지 빌드
- name: Build Docker Image
run: |
docker build -t backend_server ./backend
# 4. 서버에 코드 전송 및 배포
- name: Deploy to EC2
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
source: "./*"
target: "/home/ubuntu/backend"
# 5. 서버에서 .env 파일 생성 및 Docker 실행
- name: SSH into EC2 and restart Docker Compose
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_SSH_KEY }}
script: |
cd /home/ubuntu/backend
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" > .env
echo "KAKAO_SECRET=${{ secrets.KAKAO_SECRET }}" >> .env
echo "SECRET_KEY=${{ secrets.SECRET_KEY }}" >> .env
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> .env
docker-compose down
docker-compose up -d --build