Skip to content

Commit 6a6ebba

Browse files
authored
feat: CD 워크플로우 추가 (#21)
* feat: 의존성 추가 * feat: 설정 파일 분리 및 파라미터 스토어 적용 * feat: cd 워크플로우 추가 * chore: eof * chore: main 브랜치 CD 대상 제외 * chore: eof
1 parent 1d2def0 commit 6a6ebba

6 files changed

Lines changed: 141 additions & 2 deletions

File tree

.github/workflows/deploy-dev.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Spring Boot CD to EC2
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
# 1. 코드 체크아웃
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
# 2. JDK 설정
18+
- name: Set up JDK 21
19+
uses: actions/setup-java@v3
20+
with:
21+
java-version: '21'
22+
distribution: 'temurin'
23+
cache: 'gradle'
24+
25+
# 3. Gradle 실행 권한 부여
26+
- name: Grant execute permission for gradlew
27+
run: chmod +x gradlew
28+
29+
# 4. 빌드 (테스트 포함)
30+
- name: Build with Gradle
31+
run: ./gradlew clean build
32+
33+
# 5. JAR 파일명 확인 및 환경변수 설정
34+
- name: Get JAR file name
35+
id: jar_name
36+
run: |
37+
JAR_FILE=$(ls build/libs/*.jar | grep -v plain | head -n 1)
38+
echo "jar_path=$JAR_FILE" >> $GITHUB_OUTPUT
39+
echo "jar_name=$(basename $JAR_FILE)" >> $GITHUB_OUTPUT
40+
41+
# 6. EC2로 JAR 파일 전송
42+
- name: Copy JAR to EC2
43+
uses: appleboy/scp-action@master
44+
with:
45+
host: ${{ secrets.EC2_HOST }}
46+
username: ${{ secrets.EC2_USERNAME }}
47+
key: ${{ secrets.EC2_SSH_KEY }}
48+
port: ${{ secrets.EC2_SSH_PORT }}
49+
source: ${{ steps.jar_name.outputs.jar_path }}
50+
target: "/home/${{ secrets.EC2_USERNAME }}/app"
51+
strip_components: 2
52+
53+
# 7. 배포 스크립트 실행
54+
- name: Execute deployment script on EC2
55+
uses: appleboy/ssh-action@master
56+
with:
57+
host: ${{ secrets.EC2_HOST }}
58+
username: ${{ secrets.EC2_USERNAME }}
59+
key: ${{ secrets.EC2_SSH_KEY }}
60+
port: ${{ secrets.EC2_SSH_PORT }}
61+
script: |
62+
cd /home/${{ secrets.EC2_USERNAME }}/app
63+
chmod +x deploy.sh
64+
./deploy.sh ${{ steps.jar_name.outputs.jar_name }}
65+
66+
# 8. 배포 결과 알림
67+
- name: Notify deployment status
68+
if: always()
69+
run: |
70+
if [ ${{ job.status }} == 'success' ]; then
71+
echo "✅ 배포 성공!"
72+
else
73+
echo "❌ 배포 실패!"
74+
fi

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ out/
3737
### VS Code ###
3838
.vscode/
3939

40-
**/application.yml
40+
**/application-local.yml
4141
**/application.properties
4242

4343
/lib/

build.gradle

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,22 @@ dependencies {
3737
implementation 'org.locationtech.jts:jts-core:1.19.0'
3838

3939
// Swagger-ui
40-
implementation "org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0"
40+
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
4141

4242
// EXIF metadata extraction
4343
implementation 'com.drewnoakes:metadata-extractor:2.19.0'
4444

4545
// File type validation
4646
implementation 'org.apache.tika:tika-core:2.9.1'
47+
48+
// BOM
49+
implementation platform('io.awspring.cloud:spring-cloud-aws-dependencies:3.2.1')
50+
51+
// 사용하려는 프레임워크 모듈
52+
implementation 'io.awspring.cloud:spring-cloud-aws-starter-parameter-store'
53+
54+
// AWS 자격 증명
55+
implementation 'io.awspring.cloud:spring-cloud-aws-starter'
4756
}
4857

4958
tasks.named('test') {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
spring:
2+
config:
3+
import:
4+
- "aws-parameterstore:/PHOTO_LINER_API/rds/dev/"
5+
- "aws-parameterstore:/PHOTO_LINER_API/ec2/dev/"
6+
7+
cloud:
8+
aws:
9+
region:
10+
static: ap-northeast-2
11+
12+
datasource:
13+
url: ${MYSQL_URL}
14+
username: ${MYSQL_USER_NAME}
15+
password: ${MYSQL_PASSWORD}
16+
17+
photo:
18+
upload:
19+
base-dir: ${PHOTOS_UPLOAD_URL}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
spring:
2+
3+
datasource:
4+
url: url
5+
username: username
6+
password: password
7+
8+
photo:
9+
upload:
10+
base-dir: url

src/main/resources/application.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
spring:
2+
profiles:
3+
active: local
4+
5+
application:
6+
name: PhotoLiner
7+
8+
servlet:
9+
multipart:
10+
enabled: true
11+
max-file-size: 10MB
12+
max-request-size: 100MB
13+
14+
datasource:
15+
driver-class-name: com.mysql.cj.jdbc.Driver
16+
17+
jpa:
18+
hibernate:
19+
ddl-auto: validate
20+
show-sql: true
21+
properties:
22+
hibernate:
23+
format_sql: true
24+
25+
flyway:
26+
enabled: true
27+
baseline-on-migrate: true

0 commit comments

Comments
 (0)