Skip to content

Commit b4f9dd3

Browse files
authored
Merge pull request #370 from Clokey-dev/refactor/#369-refactor-sonarcloud-jacoco
[refactor/#369] sonarcloud 작동 확인
2 parents 6dd78b4 + 4235f08 commit b4f9dd3

23 files changed

+269
-328
lines changed

.github/workflows/cd.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ develop ]
6+
7+
jobs:
8+
cd:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Create application-secret.yml
15+
run: |
16+
mkdir -p ./temp_secret
17+
echo "${{ secrets.APPLICATION_SECRET }}" > ./temp_secret/application-secret.yml
18+
shell: bash
19+
20+
- name: Copy application-secret.yml to EC2
21+
uses: appleboy/[email protected]
22+
with:
23+
username: ubuntu
24+
host: ${{ secrets.EC2_HOST }}
25+
key: ${{ secrets.EC2_SSH_KEY }}
26+
source: ./temp_secret/application-secret.yml
27+
target: /home/ubuntu/secret/
28+
29+
- name: Copy docker-compose.yml
30+
uses: appleboy/[email protected]
31+
with:
32+
username: ubuntu
33+
host: ${{ secrets.EC2_HOST }}
34+
key: ${{ secrets.EC2_SSH_KEY }}
35+
source: ./docker-compose.yml
36+
target: /home/ubuntu/cicd/
37+
38+
- name: Copy deploy.sh
39+
uses: appleboy/[email protected]
40+
with:
41+
username: ubuntu
42+
host: ${{ secrets.EC2_HOST }}
43+
key: ${{ secrets.EC2_SSH_KEY }}
44+
source: ./deploy.sh
45+
target: /home/ubuntu/cicd/
46+
47+
- name: Deploy (Blue-Green)
48+
uses: appleboy/ssh-action@master
49+
with:
50+
username: ubuntu
51+
host: ${{ secrets.EC2_HOST }}
52+
key: ${{ secrets.EC2_SSH_KEY }}
53+
script: |
54+
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
55+
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:1.0.0
56+
sudo chmod +x /home/ubuntu/cicd/deploy.sh
57+
sudo /home/ubuntu/cicd/deploy.sh

.github/workflows/ci.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: CI Pipeline
2+
3+
on:
4+
pull_request:
5+
branches: [ develop ]
6+
7+
jobs:
8+
ci:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
22+
- name: Gradle Cache
23+
uses: actions/cache@v4
24+
with:
25+
path: |
26+
~/.gradle/caches
27+
~/.gradle/wrapper
28+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
29+
restore-keys: ${{ runner.os }}-gradle-
30+
31+
- name: SonarCloud Cache
32+
uses: actions/cache@v4
33+
with:
34+
path: ~/.sonar/cache
35+
key: ${{ runner.os }}-sonar
36+
restore-keys: ${{ runner.os }}-sonar
37+
38+
- name: Run Tests + SonarCloud
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
42+
run: ./gradlew test jacocoTestReport sonarqube --info --stacktrace
43+
44+
- name: Grant gradlew permission
45+
run: chmod +x ./gradlew
46+
47+
- name: Set up Docker Buildx
48+
uses: docker/setup-buildx-action@v3
49+
with:
50+
install: true
51+
52+
- name: Create buildx builder
53+
run: |
54+
docker buildx create --use --name mybuilder
55+
docker buildx inspect --bootstrap
56+
57+
- name: Log in to DockerHub
58+
uses: docker/login-action@v2
59+
with:
60+
username: ${{ secrets.DOCKERHUB_USERNAME }}
61+
password: ${{ secrets.DOCKERHUB_TOKEN }}
62+
63+
- name: Build & Push Dependency Cache
64+
run: |
65+
docker buildx build \
66+
--builder mybuilder \
67+
--platform linux/amd64 \
68+
--push \
69+
--file Dockerfile \
70+
--tag ${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache \
71+
--cache-to type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache,mode=max \
72+
.
73+
74+
- name: Build & Push App Image
75+
run: |
76+
docker buildx build \
77+
--builder mybuilder \
78+
--platform linux/amd64 \
79+
--push \
80+
--file Dockerfile \
81+
--tag ${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:1.0.0 \
82+
--build-arg DEPENDENCY_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache \
83+
--cache-from type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache \
84+
.

.github/workflows/dev_deploy.yml

Lines changed: 0 additions & 151 deletions
This file was deleted.

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jacocoTestReport {
106106

107107
sonarqube {
108108
properties {
109-
property "sonar.projectKey", "clokey-dev_Clokey_SpringBoot"
109+
property "sonar.projectKey", "Clokey-dev_Clokey_SpringBoot"
110110
property "sonar.organization", "clokey-dev"
111111
property "sonar.host.url", "https://sonarcloud.io"
112112
property "sonar.sourceEncoding", "UTF-8"
@@ -119,6 +119,7 @@ sonarqube {
119119
}
120120
}
121121

122+
122123
tasks.processResources {
123124
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
124125
}

src/main/java/com/clokey/server/ServerApplication.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.boot.context.properties.ConfigurationProperties;
6-
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
76
import org.springframework.scheduling.annotation.EnableScheduling;
87

98
@SpringBootApplication
109
@EnableScheduling
11-
@EnableJpaAuditing
1210
@ConfigurationProperties("spring.data.redis")
1311
public class ServerApplication {
1412

src/main/java/com/clokey/server/domain/history/domain/repository/HistoryProjectionRepositoryImpl.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public class HistoryProjectionRepositoryImpl implements HistoryProjectionReposit
3333
public List<HistoryProjectionDTO> getMonthlyHistoriesByMemberAndYearMonth(Long memberId, String yearMonth) {
3434
QHistory history = QHistory.history;
3535

36-
//입력 YYYY-MM을 기준으로 해당 달의 1일 부터 다음 달의 1일 전까지 범위 쿼리 수행
3736
YearMonth ym = YearMonth.parse(yearMonth);
3837
LocalDate startDate = ym.atDay(1);
3938
LocalDate endDate = ym.plusMonths(1).atDay(1);
@@ -66,10 +65,9 @@ public List<DailyHistoryClothProjectionDTO> findClothesByHistoryId(Long historyI
6665
.fetch();
6766

6867
if (clothIds.isEmpty()) {
69-
return List.of(); // 조기 반환 : 에러로 대체해야함. -> 버그 데이터 거든요.
68+
return List.of();
7069
}
7170

72-
// 2단계: cloth + clothImage 조회
7371
return queryFactory
7472
.select(Projections.constructor(
7573
DailyHistoryClothProjectionDTO.class,
@@ -108,7 +106,7 @@ public List<HistoryCommentProjectionDTO> findFlatCommentsByHistoryId(Long histor
108106
comment.banned.isFalse()
109107
)
110108
.orderBy(comment.createdAt.asc())
111-
.offset(page * size)
109+
.offset((long) page * size)
112110
.limit(size)
113111
.fetch();
114112
}
@@ -152,5 +150,4 @@ public Page<HistoryProjectionDTO> findLikedHistoryAndAuthorIds(Long memberId, Pa
152150

153151
return new PageImpl<>(content, pageable, total == null ? 0 : total);
154152
}
155-
156153
}

src/main/java/com/clokey/server/domain/member/domain/entity/Member.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,5 @@ public void releaseBan(){
168168
this.banned = false;
169169
}
170170

171+
171172
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.clokey.server.global.config;
2+
3+
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
5+
6+
@Configuration
7+
@EnableJpaAuditing
8+
public class JpaAuditingConfig {
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.clokey.server.domain;
2+
3+
import com.clokey.server.global.config.QuerydslConfig;
4+
import org.junit.jupiter.api.Disabled;
5+
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
6+
import org.springframework.context.annotation.Import;
7+
import org.springframework.test.context.ActiveProfiles;
8+
9+
@Disabled
10+
@DataJpaTest
11+
@ActiveProfiles("test")
12+
@Import(QuerydslConfig.class)
13+
public abstract class JpaIntegrationTestSupport {
14+
}

0 commit comments

Comments
 (0)