-
Notifications
You must be signed in to change notification settings - Fork 4
171 lines (150 loc) · 5.18 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: CI/CD Pipeline
on:
push:
branches: [ develop ]
pull_request:
branches: [ develop ]
env:
LIGHTSAIL_USERNAME: ubuntu
AWS_REGION: ap-northeast-2
jobs:
build:
runs-on: ubuntu-22.04
steps:
# 브런치로 체크아웃
- name: Checkout code
uses: actions/checkout@v3
# jdk 설치
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '21'
# application-oauth.yml 생성
- name: Create application-oauth.yml
run: |
mkdir -p src/main/resources
cat <<EOF > src/main/resources/application-oauth.yml
spring:
security:
oauth2:
client:
registration:
google:
client-id: ${{ secrets.GOOGLE_CLIENT_ID}}
client-secret: ${{secrets.GOOGLE_CLIENT_SECRET}}
redirect-uri: https://seamlessup.com/login/oauth2/code/google
scope:
- email
- profile
provider:
google:
authorization-uri: https://accounts.google.com/o/oauth2/auth
token-uri: https://oauth2.googleapis.com/token
user-info-uri: https://www.googleapis.com/oauth2/v3/userinfo
jwt:
secretKey: ${{ secrets.JWT_SECRET_KEY}}
tokenExpTime: ${{ secrets.JWT_TOKEN_EXP_TIME}}
code:
secretKey: ${{ secrets.CODE_SECRET_KEY}}
vector: ${{ secrets.CODE_VECTOR}}
EOF
# application-db.yml 생성
- name: Create application-db.yml
run: |
mkdir -p src/main/resources
cat <<EOF > src/main/resources/application-db.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${{secrets.MYSQL_URL}}
username: ${{secrets.MYSQL_USERNAME}}
password: ${{secrets.MYSQL_PASSWORD}}
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
database: mysql
EOF
# application-mail.yml 생성
- name: Create application-mail.yml
run: |
mkdir -p src/main/resources
cat <<EOF > src/main/resources/application-mail.yml
spring:
mail:
host: smtp.gmail.com
port: ${{secrets.MAIL_PORT}}
username: ${{secrets.MAIL_USERNAME}}
password: ${{secrets.MAIL_PASSWORD}}
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
connectiontimeout: 5000
timeout: 5000
writetimeout: 5000
EOF
# Gradle 캐시 설정
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
# gradlew 실행 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# gradle로 빌드
- name: Build with Gradle
run: ./gradlew bootJar
# AWS 인증
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-region: ${{ env.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# AWS 인증 테스트
- name: Verify AWS Credentials
run: aws configure list
# 배포 자동화
- name: Upload files to Lightsail
uses: appleboy/scp-action@master
with:
host: ${{ secrets.LIGHTSAIL_HOST }}
username: ${{ env.LIGHTSAIL_USERNAME }}
port: 22
key: ${{ secrets.LIGHTSAIL_SSH_KEY }}
source: 'build/libs/*.jar'
target: '/home/ubuntu/seamless/dist'
use_insecure_cipher: true
- name: Restart Spring Boot process
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.LIGHTSAIL_HOST }}
username: ${{env.LIGHTSAIL_USERNAME}}
key: ${{ secrets.LIGHTSAIL_SSH_KEY }}
script: |
BUILD_PATH=$(ls /home/ubuntu/seamless/dist/build/libs/*.jar)
JAR_NAME=$(basename $BUILD_PATH)
CURRENT_PID=$(pgrep -f $JAR_NAME)
if [ -z $CURRENT_PID ]
then
sleep 1
else
kill -15 $CURRENT_PID
sleep 10
fi
DEPLOY_PATH=/home/ubuntu/seamless/deploy/
mkdir -p $DEPLOY_PATH
cp $BUILD_PATH $DEPLOY_PATH
cd $DEPLOY_PATH
DEPLOY_JAR=$DEPLOY_PATH$JAR_NAME
nohup java -jar $DEPLOY_JAR > /dev/null 2> /dev/null < /dev/null &