Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CD Pipeline

on:
push:
branches: [ develop ]

jobs:
cd:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Create application-secret.yml
run: |
mkdir -p ./temp_secret
echo "${{ secrets.APPLICATION_SECRET }}" > ./temp_secret/application-secret.yml
shell: bash

- name: Copy application-secret.yml to EC2
uses: appleboy/[email protected]
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
source: ./temp_secret/application-secret.yml
target: /home/ubuntu/secret/

- name: Copy docker-compose.yml
uses: appleboy/[email protected]
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
source: ./docker-compose.yml
target: /home/ubuntu/cicd/

- name: Copy deploy.sh
uses: appleboy/[email protected]
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
source: ./deploy.sh
target: /home/ubuntu/cicd/

- name: Deploy (Blue-Green)
uses: appleboy/ssh-action@master
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_SSH_KEY }}
script: |
echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:1.0.0
sudo chmod +x /home/ubuntu/cicd/deploy.sh
sudo /home/ubuntu/cicd/deploy.sh
84 changes: 84 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: CI Pipeline

on:
pull_request:
branches: [ develop ]

jobs:
ci:
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Gradle Cache
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle-

- name: SonarCloud Cache
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Run Tests + SonarCloud
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew test jacocoTestReport sonarqube --info --stacktrace

- name: Grant gradlew permission
run: chmod +x ./gradlew

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
install: true

- name: Create buildx builder
run: |
docker buildx create --use --name mybuilder
docker buildx inspect --bootstrap

- name: Log in to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build & Push Dependency Cache
run: |
docker buildx build \
--builder mybuilder \
--platform linux/amd64 \
--push \
--file Dockerfile \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache \
--cache-to type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache,mode=max \
.

- name: Build & Push App Image
run: |
docker buildx build \
--builder mybuilder \
--platform linux/amd64 \
--push \
--file Dockerfile \
--tag ${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:1.0.0 \
--build-arg DEPENDENCY_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache \
--cache-from type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/clokey-docker:dependency-cache \
.
151 changes: 0 additions & 151 deletions .github/workflows/dev_deploy.yml

This file was deleted.

3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ jacocoTestReport {

sonarqube {
properties {
property "sonar.projectKey", "clokey-dev_Clokey_SpringBoot"
property "sonar.projectKey", "Clokey-dev_Clokey_SpringBoot"
property "sonar.organization", "clokey-dev"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.sourceEncoding", "UTF-8"
Expand All @@ -119,6 +119,7 @@ sonarqube {
}
}


tasks.processResources {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
2 changes: 0 additions & 2 deletions src/main/java/com/clokey/server/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@EnableJpaAuditing
@ConfigurationProperties("spring.data.redis")
public class ServerApplication {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class HistoryProjectionRepositoryImpl implements HistoryProjectionReposit
public List<HistoryProjectionDTO> getMonthlyHistoriesByMemberAndYearMonth(Long memberId, String yearMonth) {
QHistory history = QHistory.history;

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

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

// 2단계: cloth + clothImage 조회
return queryFactory
.select(Projections.constructor(
DailyHistoryClothProjectionDTO.class,
Expand Down Expand Up @@ -108,7 +106,7 @@ public List<HistoryCommentProjectionDTO> findFlatCommentsByHistoryId(Long histor
comment.banned.isFalse()
)
.orderBy(comment.createdAt.asc())
.offset(page * size)
.offset((long) page * size)
.limit(size)
.fetch();
}
Expand Down Expand Up @@ -152,5 +150,4 @@ public Page<HistoryProjectionDTO> findLikedHistoryAndAuthorIds(Long memberId, Pa

return new PageImpl<>(content, pageable, total == null ? 0 : total);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@ public void releaseBan(){
this.banned = false;
}


}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

따로 뺀 이유가 뭔가요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository layer에서 @DataJpaTest를 수행하는데, 전체 Context를 로딩하지 않아서 createdAt과 updatedAt을 업데이트 할 때 에러가 생겨서 따로 config로 빼주었슴다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.clokey.server.global.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@Configuration
@EnableJpaAuditing
public class JpaAuditingConfig {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.clokey.server.domain;

import com.clokey.server.global.config.QuerydslConfig;
import org.junit.jupiter.api.Disabled;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;

@Disabled
@DataJpaTest
@ActiveProfiles("test")
@Import(QuerydslConfig.class)
public abstract class JpaIntegrationTestSupport {
}
Loading