diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml index 8b73258..f29ee8e 100644 --- a/.github/workflows/action.yml +++ b/.github/workflows/action.yml @@ -42,26 +42,12 @@ jobs: aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com - docker build -t reddi-server-dev . + docker build --platform amd64 -t reddi-server-dev . docker tag reddi-server-dev:latest 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server-dev:latest docker push 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server-dev:latest - - name: (main) Build, tag, and push image to Amazon ECR - if: github.ref == 'refs/heads/main' - run: | - # docker image 빌드 - # ECR push - - aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com - - docker build -t reddi-server . - - docker tag reddi-server:latest 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest - - docker push 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest - - name: (dev) executing remote ssh commands using password if: github.ref == 'refs/heads/dev' uses: appleboy/ssh-action@master @@ -77,11 +63,25 @@ jobs: ## docker-compose 실행 sudo chmod 666 /var/run/docker.sock - sudo docker rm -f $(sudo docker ps -q --filter "ancestor=533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server-dev:latest" --filter "expose=8081" --filter "expose=6380") + sudo docker rm -f $(sudo docker ps -q --filter "expose=8081" --filter "expose=6380") docker pull 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server-dev:latest docker compose -f docker-compose-dev.yml up -d docker image prune -f + - name: (main) Build, tag, and push image to Amazon ECR + if: github.ref == 'refs/heads/main' + run: | + # docker image 빌드 + # ECR push + + aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com + + docker build --platform amd64 -t reddi-server . + + docker tag reddi-server:latest 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest + + docker push 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest + - name: (main) executing remote ssh commands using password if: github.ref == 'refs/heads/main' uses: appleboy/ssh-action@master @@ -98,7 +98,7 @@ jobs: ## docker-compose 실행 sudo chmod 666 /var/run/docker.sock # sudo docker rm -f $(docker ps -qa) - sudo docker rm -f $(sudo docker ps -q --filter "ancestor=533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest" --filter "expose=8080" --filter "expose=6379") + sudo docker rm -f $(sudo docker ps -q --filter "expose=8080" --filter "expose=6379") docker pull 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest docker compose -f docker-compose-prod.yml up -d docker image prune -f diff --git a/deploy_prod.sh b/deploy_prod.sh new file mode 100644 index 0000000..a496ddd --- /dev/null +++ b/deploy_prod.sh @@ -0,0 +1,9 @@ +./gradlew bootJar + +aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com + +docker build --platform amd64 -t reddi-server . + +docker tag reddi-server:latest 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest + +docker push 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest \ No newline at end of file diff --git a/src/main/java/com/example/reddiserver/auth/service/OAuthService.java b/src/main/java/com/example/reddiserver/auth/service/OAuthService.java index a0e2462..53b8065 100644 --- a/src/main/java/com/example/reddiserver/auth/service/OAuthService.java +++ b/src/main/java/com/example/reddiserver/auth/service/OAuthService.java @@ -66,11 +66,11 @@ public LoginResponseDto login(String code) { String refreshToken = jwtTokenProvider.createRefreshToken(payload); // redis에 저장 -// RefreshToken refreshTokenEntity = new RefreshToken(); -// refreshTokenEntity.setUserId(member.getId()); -// refreshTokenEntity.setRefreshToken(refreshToken); -// -// refreshTokenRepository.save(refreshTokenEntity); + RefreshToken refreshTokenEntity = new RefreshToken(); + refreshTokenEntity.setUserId(member.getId()); + refreshTokenEntity.setRefreshToken(refreshToken); + + refreshTokenRepository.save(refreshTokenEntity); return LoginResponseDto.builder() .accessToken(accessToken) diff --git a/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java b/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java index 3571d40..cb83868 100644 --- a/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java +++ b/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java @@ -5,13 +5,19 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.resource.NoResourceFoundException; @Slf4j @RestControllerAdvice public class ApiExceptionHandler { + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity> handleNoResourceFoundException(NoResourceFoundException exception) { + // NoResourceFoundException이 발생했을 때 아무런 처리도 하지 않음 + return ResponseEntity.ok().build(); + } + @ExceptionHandler(Exception.class) public ResponseEntity> handleExceptions(Exception exception) { - log.error("Exception occurred:", exception); // 스택 트레이스 정보를 포함한 로깅 return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.errorResponse(exception.getMessage())); diff --git a/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java b/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java index d2d1149..82e15fe 100644 --- a/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java +++ b/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java @@ -28,10 +28,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .csrf(csrf -> csrf.disable()) .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .httpBasic(httpBasic -> httpBasic.disable()) - .formLogin(formLogin -> formLogin.disable()) +// .httpBasic(httpBasic -> httpBasic.disable()) +// .formLogin(formLogin -> formLogin.disable()) .authorizeHttpRequests((authorize) -> authorize - .requestMatchers("/static/**", "/resources/**", "/css/**", "/js/**", "/images/**", "/**", "/swagger-ui/**", "/v3/api-docs/**").permitAll() + .requestMatchers("/static/**", "/resources/**", "/css/**", "/js/**", "/images/**").authenticated() .requestMatchers(HttpMethod.GET, "/**").permitAll() .requestMatchers(HttpMethod.GET, "/swagger-ui/**").permitAll() .requestMatchers(HttpMethod.GET, "/v3/api-docs/**").permitAll() diff --git a/src/main/java/com/example/reddiserver/entity/RefreshToken.java b/src/main/java/com/example/reddiserver/entity/RefreshToken.java index 822d29c..32f8b64 100644 --- a/src/main/java/com/example/reddiserver/entity/RefreshToken.java +++ b/src/main/java/com/example/reddiserver/entity/RefreshToken.java @@ -14,7 +14,6 @@ public class RefreshToken { @Id private Long userId; - private String refreshToken; } diff --git a/src/main/java/com/example/reddiserver/repository/BrandRepository.java b/src/main/java/com/example/reddiserver/repository/BrandRepository.java index ded9ae1..59bc151 100644 --- a/src/main/java/com/example/reddiserver/repository/BrandRepository.java +++ b/src/main/java/com/example/reddiserver/repository/BrandRepository.java @@ -4,17 +4,23 @@ import com.example.reddiserver.entity.Post; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.EntityGraph; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import java.util.List; +import java.util.Optional; public interface BrandRepository extends JpaRepository { - @Query("SELECT b FROM Brand b") +// @Query("SELECT b FROM Brand b") + @Query("SELECT b FROM Brand b LEFT JOIN FETCH b.brandTags") Page findAllBrands(Pageable pageable); + @EntityGraph(attributePaths = {"posts"}) + Optional findById(Long id); + @Query("SELECT b FROM Brand b WHERE b.notion_page_id = :notion_page_id") Brand findBrandByNotion_page_id(@Param("notion_page_id") String notion_page_id); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 99542d9..4b8ac26 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -73,6 +73,7 @@ spring: database-platform: org.hibernate.dialect.MySQL8Dialect show_sql: true format_sql: true + default_batch_fetch_size: 1000 jwt: secret: ${JWT_SECRET} data: