Skip to content
Merged

Dev #240

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
70 changes: 70 additions & 0 deletions .github/workflows/test-server-deploy.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ $ git submodule update
## application.yml 업데이트
``` bash
$ git submodule update —remote
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ public class Board extends BaseEntity {
@Setter
private List<String> imageUrls = new ArrayList<>();

@BatchSize(size = 100)
@OneToMany(mappedBy = "board", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> comments;

@ManyToMany(mappedBy = "likedBoards", fetch = FetchType.LAZY)
@BatchSize(size = 100)
private List<User> likedUsers = new ArrayList<>();

@ManyToMany(fetch = FetchType.LAZY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public interface BoardRepository extends JpaRepository<Board, Long> {

List<Board> findAllByCategoryAndDeletedFalse(Category category);

@Query("SELECT b FROM Board b JOIN FETCH b.user WHERE b.category = :category AND b.deleted = false")
Page<Board> findAllByCategoryAndDeletedFalse(Category category, Pageable pageable);

@EntityGraph(attributePaths = {"likedUsers"})
Optional<Board> findBoardByIdAndDeletedFalse(Long id);

List<Board> findByCategory(Category category);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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); // 쿠키 허용
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserRoleEnum> roles = new HashSet<>();
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config/application-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,9 @@ logging:
com.handong.cra.crawebbackend: info
file:
name: ${LOG_FILE}

dev-site:
test-server:
url: ${DEV-SITE_TEST-SERVER_URL}


Loading