Skip to content

Commit

Permalink
[CHORE #81] CD 구현 중
Browse files Browse the repository at this point in the history
  • Loading branch information
Taehk committed Dec 26, 2023
1 parent 43da682 commit 6928fb2
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 46 deletions.
7 changes: 7 additions & 0 deletions board-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM eclipse-temurin:17

ARG JAR_FILE=*.jar
ARG JASYPT_ENCRYPTOR_PASSWORD
COPY build/libs/$JAR_FILE app.jar

ENTRYPOINT ["java","-jar", "-Djasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD}", "/app.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ResponseEntity<GlobalResponseDto<?>> getBoardListWriter(
@Operation(summary = "특정 게시글 수정", description = "개별 경매 게시글에 대한 수정 요청")
public ResponseEntity<GlobalResponseDto<?>> updateAuctionBoard(@PathVariable(value= "board_uuid") String boardUuid,
@Valid @RequestBody RequestUpdateProductBoardDto updateDTO,
@RequestHeader("UUID") String uuid){
@RequestHeader("UUID") String uuid) throws InterruptedException {
boardFacade.updateBoard(updateDTO, boardUuid, uuid);
return ResponseEntity.ok(
GlobalResponseDto.of(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class Board extends TimeStamp {
@Column(nullable = false, updatable = false, unique = true)
private String boardUuid;

@Version// 낙관적 락에서 정합성을 맞추기 위해서 추가하는 필드
private Long version; //버전 어노테이션이 붙은 필드 하나 더 선언

////////////////////////////////////////////////
// 엔티티 최초 생성 시 자동 초기화할 값
// UUID, Status, viewCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,25 @@ public ResponseGetCombinationDetailDto getBoard(String boardUuid) {

// 게시글 업데이트
@Transactional
public void updateBoard(RequestUpdateProductBoardDto updateDTO, String boardUuid, String memberUuid) {
boolean productChange = boardService.updateBoard(updateDTO, boardUuid, memberUuid);
if(productChange)
productService.checkUpdateProduct(boardUuid, updateDTO, memberUuid);

public void updateBoard(RequestUpdateProductBoardDto updateDTO, String boardUuid, String memberUuid) throws InterruptedException {
// 재시도 폭주를 막기 위한 지수 백오프
int maxRetries = 3; // 최대 3회까지 시도
int retries = 0;
Boolean productChange = null;
while (retries < maxRetries) {
try {
productChange = boardService.updateBoard(updateDTO, boardUuid, memberUuid);
break;
} catch (Exception e) {
// 낙관적 락에 의해서 버전 정합성이 맞지 않아 예외가 발생했다면
int sleepTime = (int) Math.pow(2, retries++) * 100; // 지수 백오프
Thread.sleep(sleepTime);
}
}
if(retries == maxRetries) // 재시도 횟수가 넘으면 예외
throw new BoardException(ExceptionType.UPDATE);
if(Boolean.TRUE.equals(productChange))
productService.checkUpdateProduct(boardUuid, updateDTO, memberUuid);
}

// 게시글 삭제, 성공하면 1페이지로 리다이렉트
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.farmted.boardservice.dto.response.detailDomain.ResponseGetBoardDetailDto;
import com.farmted.boardservice.dto.response.listDomain.ResponseGetBoardDto;
import com.farmted.boardservice.enums.BoardType;
import jakarta.persistence.LockModeType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;
Expand Down Expand Up @@ -37,7 +39,6 @@ public interface BoardRepository extends JpaRepository<Board, Long> {
Optional<ResponseGetBoardDetailDto> findDetailByBoardUuid(String boardUuid);

// 업데이트/삭제용 엔티티 불러오기 (영속성때문에)
@Lock(value = LockModeType.OPTIMISTIC)
Optional<Board> findByBoardUuidAndBoardStatusTrue(String boardUuid);

Board getByBoardUuidAndBoardStatusTrue(String boardUuid);
}
2 changes: 1 addition & 1 deletion board-service/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
spring:
cloud:
config:
uri: http://localhost:9999
uri: http://43.202.60.155:9999
name: config, s3, server
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.test.context.ActiveProfiles;

@SpringBootTest
@ActiveProfiles("test-private")
@ActiveProfiles("private")
class BoardServiceApplicationTests {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.farmted.boardservice.dto.request.RequestCreateBoardDto;
import com.farmted.boardservice.dto.response.listDomain.ResponseGetBoardDto;
import com.farmted.boardservice.enums.BoardType;
import com.farmted.boardservice.util.JasyptConfig;
import com.farmted.boardservice.vo.MemberVo;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -24,7 +22,7 @@
import static org.assertj.core.api.Assertions.assertThat;

@DataJpaTest
@ActiveProfiles("test-private")
@ActiveProfiles({"test","private"})
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
// 해당 어노테이션은 @DataJpaTest에 내장되어 있으며, 이 어노테이션은 '내장된 메모리 데이터베이스'로 테스트를 진행
// 설정을 통해 내장된 메모리 데이터베이스로 변경하지 못하도록 막기
Expand Down
11 changes: 0 additions & 11 deletions board-service/src/test/resources/application-test-private.yml

This file was deleted.

24 changes: 15 additions & 9 deletions board-service/src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
eureka:
client:
register-with-eureka: false
fetch-registry: false
spring:
jpa:
hibernate:
ddl-auto: create-drop
properties:
hibernate:
format_sql: true
show-sql: true
datasource:
url: jdbc:mysql://localhost:3306/msa_db
username: root
password: 1234
url: ${dbURL}
username: ${dbName}
password: ${dbPwd}
driver-class-name: com.mysql.cj.jdbc.Driver

## S3 세팅
cloud:
aws:
Expand All @@ -20,4 +22,8 @@ cloud:
auto: false
credentials:
secret-key: secret
access-key: access
access-key: access
eureka:
client:
register-with-eureka: false
fetch-registry: false
7 changes: 7 additions & 0 deletions config-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM eclipse-temurin:17

ARG JAR_FILE=*.jar
ARG JASYPT_ENCRYPTOR_PASSWORD
COPY build/libs/config-service-0.0.1-SNAPSHOT.jar app.jar

ENTRYPOINT ["java","-jar", "-Djasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD}", "/app.jar"]
2 changes: 2 additions & 0 deletions config-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ ext {
dependencies {
implementation 'org.springframework.cloud:spring-cloud-config-server'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// 암호화 라이브러리
implementation 'com.github.ulisesbocchio:jasypt-spring-boot-starter:3.0.5'
}

dependencyManagement {
Expand Down
2 changes: 1 addition & 1 deletion config-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring:
server:
git:
default-label: main
uri: https://github.com/farmtedPlaydata/configFiles.git
uri: ENC(SsVWZpxAzcEkFBdQoXE8Pro4E7M6hFafZKonzQN1TmE33Q9c2fY3xcn7rXBEv5W+2UID/9yPr3i7ButUzjPAfg==)
# basedir: ./repo
server:
port: 9999
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.farmted.configservice;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class ConfigServiceApplicationTests {

@Test
void contextLoads() {
}
}
//package com.farmted.configservice;
//
//import org.junit.jupiter.api.Test;
//import org.springframework.boot.test.context.SpringBootTest;
//
//@SpringBootTest
//class ConfigServiceApplicationTests {
//
// @Test
// void contextLoads() {
// }
//}
4 changes: 4 additions & 0 deletions eureka-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM eclipse-temurin:17
ARG JAR_FILE=*.jar
COPY build/libs/eureka-service-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","/app.jar"]

0 comments on commit 6928fb2

Please sign in to comment.