diff --git a/.github/workflows/test-server-deploy.yml b/.github/workflows/test-server-deploy.yml new file mode 100644 index 0000000..e198f0a --- /dev/null +++ b/.github/workflows/test-server-deploy.yml @@ -0,0 +1,70 @@ +name: Build & Deploy + +on: + push: + branches: [dev] + + pull_request: + branches: [dev] + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: "17" + cache: gradle + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Build Spring Boot + run: ./gradlew clean bootJar + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker Hub Login + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build & Push Docker Image + uses: docker/build-push-action@v6 + with: + context: . + push: true + platforms: linux/arm64 + tags: | + lkyoung/craweb:latest + lkyoung/craweb:${{ github.sha }} + + - name: Deploy via SSH + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + port: ${{ secrets.SERVER_SSH_PORT }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | + set -e + + cd ~/cra-web-test + + echo "${{ secrets.SERVER_USER_PASSWORD }}" | sudo -S docker login \ + -u ${{ secrets.DOCKERHUB_USERNAME }} \ + -p ${{ secrets.DOCKERHUB_TOKEN }} + + echo "${{ secrets.SERVER_USER_PASSWORD }}" | sudo -S docker compose up -d --pull always + echo "${{ secrets.SERVER_USER_PASSWORD }}" | sudo -S docker logout diff --git a/README.md b/README.md index a7b4e54..5312ef6 100644 --- a/README.md +++ b/README.md @@ -50,4 +50,4 @@ $ git submodule update ## application.yml 업데이트 ``` bash $ git submodule update —remote -``` \ No newline at end of file +``` diff --git a/src/main/java/com/handong/cra/crawebbackend/board/domain/Board.java b/src/main/java/com/handong/cra/crawebbackend/board/domain/Board.java index f4b1907..07e1734 100644 --- a/src/main/java/com/handong/cra/crawebbackend/board/domain/Board.java +++ b/src/main/java/com/handong/cra/crawebbackend/board/domain/Board.java @@ -45,10 +45,12 @@ public class Board extends BaseEntity { @Setter private List imageUrls = new ArrayList<>(); + @BatchSize(size = 100) @OneToMany(mappedBy = "board", cascade = CascadeType.ALL, orphanRemoval = true) private List comments; @ManyToMany(mappedBy = "likedBoards", fetch = FetchType.LAZY) + @BatchSize(size = 100) private List likedUsers = new ArrayList<>(); @ManyToMany(fetch = FetchType.LAZY) diff --git a/src/main/java/com/handong/cra/crawebbackend/board/repository/BoardRepository.java b/src/main/java/com/handong/cra/crawebbackend/board/repository/BoardRepository.java index d1e6924..9ace391 100644 --- a/src/main/java/com/handong/cra/crawebbackend/board/repository/BoardRepository.java +++ b/src/main/java/com/handong/cra/crawebbackend/board/repository/BoardRepository.java @@ -18,9 +18,9 @@ public interface BoardRepository extends JpaRepository { List findAllByCategoryAndDeletedFalse(Category category); + @Query("SELECT b FROM Board b JOIN FETCH b.user WHERE b.category = :category AND b.deleted = false") Page findAllByCategoryAndDeletedFalse(Category category, Pageable pageable); - @EntityGraph(attributePaths = {"likedUsers"}) Optional findBoardByIdAndDeletedFalse(Long id); List findByCategory(Category category); diff --git a/src/main/java/com/handong/cra/crawebbackend/config/WebSecurityConfig.java b/src/main/java/com/handong/cra/crawebbackend/config/WebSecurityConfig.java index 520e0a0..1ae57bd 100644 --- a/src/main/java/com/handong/cra/crawebbackend/config/WebSecurityConfig.java +++ b/src/main/java/com/handong/cra/crawebbackend/config/WebSecurityConfig.java @@ -37,6 +37,9 @@ public class WebSecurityConfig { @Value("${site.frontend.url}") private String frontUrl; + @Value("${dev-site.test-server.url}") + private String testServerUrl; + @Bean public JwtAuthenticationFilter jwtAuthenticationFilter() { return new JwtAuthenticationFilter(jwtTokenProvider, userDetailsService, userRepository); @@ -98,7 +101,7 @@ public SecurityFilterChain securityFilterChain(final HttpSecurity http) throws E @Bean public CorsConfigurationSource corsConfigurationSource() { final CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(List.of("http://localhost:5173", "https://test.cra206.org", frontUrl)); // React 앱 도메인 허용 + configuration.setAllowedOrigins(List.of("http://localhost:5173", frontUrl, testServerUrl)); configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS")); configuration.setAllowedHeaders(List.of("*")); // 모든 헤더 허용 configuration.setAllowCredentials(true); // 쿠키 허용 diff --git a/src/main/java/com/handong/cra/crawebbackend/user/domain/User.java b/src/main/java/com/handong/cra/crawebbackend/user/domain/User.java index 86749b5..c4576ee 100644 --- a/src/main/java/com/handong/cra/crawebbackend/user/domain/User.java +++ b/src/main/java/com/handong/cra/crawebbackend/user/domain/User.java @@ -31,6 +31,7 @@ public class User extends BaseEntity { @Column(name = "github_id", nullable = false) private String githubId; + private UserRoleSet roles; @Column(name = "student_id", unique = true, nullable = false) @@ -46,7 +47,7 @@ public class User extends BaseEntity { @Column(name = "img_url") private String imgUrl; - @ManyToMany(fetch = FetchType.EAGER) + @ManyToMany(fetch = FetchType.LAZY) @JoinTable( name = "likes", joinColumns = @JoinColumn(name = "user_id"), diff --git a/src/main/java/com/handong/cra/crawebbackend/user/domain/UserRoleSet.java b/src/main/java/com/handong/cra/crawebbackend/user/domain/UserRoleSet.java index 1839483..de150b7 100644 --- a/src/main/java/com/handong/cra/crawebbackend/user/domain/UserRoleSet.java +++ b/src/main/java/com/handong/cra/crawebbackend/user/domain/UserRoleSet.java @@ -14,7 +14,7 @@ @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) public class UserRoleSet { - @ElementCollection(fetch = FetchType.EAGER) + @ElementCollection(fetch = FetchType.LAZY) @CollectionTable(name = "roles", joinColumns = @JoinColumn(name = "user_id")) @Enumerated(EnumType.STRING) private Set roles = new HashSet<>(); diff --git a/src/main/resources/config/application-deploy.yml b/src/main/resources/config/application-deploy.yml index 0cb2111..ea757ae 100644 --- a/src/main/resources/config/application-deploy.yml +++ b/src/main/resources/config/application-deploy.yml @@ -58,3 +58,9 @@ logging: com.handong.cra.crawebbackend: info file: name: ${LOG_FILE} + +dev-site: + test-server: + url: ${DEV-SITE_TEST-SERVER_URL} + +