-
Notifications
You must be signed in to change notification settings - Fork 1
141 lines (115 loc) · 5.13 KB
/
Copy pathdev_deploy.yml
File metadata and controls
141 lines (115 loc) · 5.13 KB
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
134
135
136
137
138
139
140
141
name: Deploy to EC2
on:
push:
branches:
- develop
jobs:
build:
runs-on: ubuntu-latest
steps:
# 1️⃣ 코드 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# 2️⃣ JDK 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# 3️⃣ application.properties 생성 (GitHub Secrets 사용)
- name: Create application.properties
run: |
cat <<EOF > drivemate/src/main/resources/application.properties
spring.application.name=drivemate
# DB
spring.datasource.url=${{ secrets.RDS_URL }}
spring.datasource.username=${{ secrets.RDS_USERNAME }}
spring.datasource.password=${{ secrets.RDS_PASSWORD }}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# OpenAI API key
openai.api.key= ${{ secrets.AI_KEY }}
openai.api.url= https://api.openai.com/v1/chat/completions
# JPA
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
# OAuth2
spring.security.oauth2.client.registration.kakao.client-id=${{ secrets.OAUTH_REST }}
spring.security.oauth2.client.registration.kakao.client-secret=${{ secrets.OAUTH_CLIENT }}
spring.security.oauth2.client.registration.kakao.redirect-uri=http://localhost:8080/oauth/callback/kakao
spring.security.oauth2.client.registration.kakao.client-authentication-method=client_secret_post
spring.security.oauth2.client.registration.kakao.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.kakao.scope=profile_img, profile_nickname
spring.security.oauth2.client.provider.kakao.authorization-uri=https://kauth.kakao.com/oauth/authorize
spring.security.oauth2.client.provider.kakao.token-uri=https://kauth.kakao.com/oauth/token
spring.security.oauth2.client.provider.kakao.user-info-uri=https://kapi.kakao.com/v2/user/me
spring.security.oauth2.client.provider.kakao.user-name-attribute=id
# JWT
jwt.secretKey=${{ secrets.JWT_KEY }}
EOF
# 4️⃣ Gradle 빌드
- name: Grant execute permission for gradlew
run: chmod +x drivemate/gradlew
- name: Build with Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
build-root-directory: drivemate
# 5️⃣ 빌드된 JAR 파일 업로드 (GitHub Actions에서 사용할 수 있도록 저장)
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: Drivemate-Server
path: drivemate/build/libs/*.jar
# 6️⃣ 테스트 결과 업로드 (실패해도 계속 진행)
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: drivemate/build/reports/tests/test/
# 7️⃣ EC2 배포
deploy:
needs: build # build 작업이 성공적으로 완료된 후 실행
runs-on: ubuntu-latest
steps:
# 8️⃣ 빌드된 JAR 파일 다운로드
- name: Download build artifact
uses: actions/download-artifact@v4
with:
name: Drivemate-Server
path: build/libs/
# 9️⃣ EC2에 배포
- name: Deploy to EC2
env:
EC2_SSH_KEY: ${{ secrets.EC2_SSH_KEY }}
EC2_USERNAME: ${{ secrets.EC2_USERNAME }}
EC2_HOST: ${{ secrets.EC2_HOST }}
RDS_URL: ${{ secrets.RDS_URL }}
RDS_USERNAME: ${{ secrets.RDS_USERNAME }}
RDS_PASSWORD: ${{ secrets.RDS_PASSWORD }}
OAUTH_REST: ${{ secrets.OAUTH_REST }}
OAUTH_CLIENT: ${{ secrets.OAUTH_CLIENT }}
JWT_KEY: ${{ secrets.JWT_KEY }}
openai.api.key: ${{ secrets.AI_KEY }}
run: |
echo "$EC2_SSH_KEY" > x10.pem
chmod 600 x10.pem
# SSH 접속 테스트
ssh -i x10.pem -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST "echo '✅ Connected successfully'"
# JAR 파일 찾기
jar_file=$(find build/libs -name '*.jar' ! -name '*plain.jar' | head -n 1)
echo "JAR 파일 경로: $jar_file"
# EC2에 JAR 파일 전송
scp -i x10.pem -o StrictHostKeyChecking=no "$jar_file" $EC2_USERNAME@$EC2_HOST:/home/$EC2_USERNAME/Drivemate-Server.jar
# EC2에서 실행 중인 서버 종료 및 새 JAR 실행
ssh -i x10.pem -o StrictHostKeyChecking=no $EC2_USERNAME@$EC2_HOST << 'EOF'
echo "🔄 기존 프로세스 종료 중..."
pkill -f 'java -jar' || echo "No process to kill"
echo "🚀 새로운 서버 실행 중..."
nohup java -jar /home/$EC2_USERNAME/Drivemate-Server.jar > /home/$EC2_USERNAME/app.log 2>&1 &
echo "✅ 배포 완료"
EOF
# SSH 키 삭제
rm -f x10.pem