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
69 changes: 69 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: DangSim_CD

on:
pull_request:
branches: [ "deploy" ]

jobs:
build_and_deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: prod.yml 생성
run: |
mkdir -p ./src/main/resources
echo "${{ secrets.APPLICATION_PROD }}" > ./src/main/resources/application.yml

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

- name: Grant execute permission for Gradle wrapper
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew clean build -x test --no-daemon

- name: 도커 허브 로그인
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: 도커 이미지 빌드 & 푸시
run: |
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/my-spring-boot-app:${{ github.sha }} .
docker push ${{ secrets.DOCKER_USERNAME }}/my-spring-boot-app:${{ github.sha }}

- name: Deploy to Server via SSH
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/my-spring-boot-app:${{ github.sha }}
docker stop spring-boot-app || true
docker rm spring-boot-app || true
docker run -d --name spring-boot-app -p 8080:8080 ${{ secrets.DOCKER_USERNAME }}/my-spring-boot-app:${{ github.sha }}

# Notes:
# - Set the following repository secrets:
# • DOCKER_USERNAME, DOCKER_PASSWORD (Docker Hub credentials)
# • SERVER_HOST, SERVER_USER, SERVER_SSH_KEY (SSH access to your deployment server)
# - Adjust image name, ports, and run options as needed for your environment.
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17-jdk
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]
35 changes: 15 additions & 20 deletions src/main/java/com/dangsim/common/config/CorsConfig.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.dangsim.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfig {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000")
.allowedMethods("*")
.allowCredentials(true);
}
};
}
}
// @Configuration
// public class CorsConfig {
// @Bean
// public WebMvcConfigurer corsConfigurer() {
// return new WebMvcConfigurer() {
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**")
// .allowedOrigins("http://localhost:3000", "https://dangsim-fe.pages.dev")
// .allowedMethods("*")
// .allowCredentials(true);
// }
// };
// }
// }
25 changes: 23 additions & 2 deletions src/main/java/com/dangsim/common/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.dangsim.common.config;

import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;

import com.dangsim.jwt.JwtProvider;
import com.dangsim.jwt.filter.JwtAuthenticationFilter;
Expand All @@ -21,8 +26,7 @@ public SecurityFilterChain filterChain(HttpSecurity http, JwtProvider jwtProvide
UserRepository userRepository) throws Exception {
http
.csrf(csrf -> csrf.disable())
.cors(cors -> {
})
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
.formLogin(form -> form.disable())// CORS 기본 설정 활성화
.authorizeHttpRequests(auth -> auth
// .anyRequest().permitAll()
Expand All @@ -43,4 +47,21 @@ public SecurityFilterChain filterChain(HttpSecurity http, JwtProvider jwtProvide
);
return http.build();
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.setAllowedOrigins(List.of(
"http://localhost:3000",
"https://dangsim-fe.pages.dev"
));
configuration.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
configuration.setAllowedHeaders(List.of("*"));
configuration.setAllowCredentials(true);
configuration.setMaxAge(3600L);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
}
10 changes: 0 additions & 10 deletions src/main/java/com/dangsim/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.dangsim.user.service;

import java.time.LocalDateTime;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.dangsim.common.CursorPageResponse;
import com.dangsim.common.exception.runtime.BaseException;
import com.dangsim.common.util.DateTimeFormatUtils;
import com.dangsim.user.dto.UserMapper;
import com.dangsim.user.dto.request.ExtraInfoRequest;
import com.dangsim.user.dto.response.CheckNicknameResponse;
Expand Down Expand Up @@ -60,16 +56,10 @@ public UserProfileResponse getMemberProfile(User user) {
}

public CursorPageResponse<UserTaskResponse> getRequestedTasks(String cursor, int size, User user) {
if (!StringUtils.hasText(cursor)) {
cursor = DateTimeFormatUtils.formatDateTime(LocalDateTime.now());
}
return userRepository.findRequestedTasksByCursor(cursor, size, user);
}

public CursorPageResponse<UserTaskResponse> getPerformedTasks(String cursor, int size, User user) {
if (!StringUtils.hasText(cursor)) {
cursor = DateTimeFormatUtils.formatDateTime(LocalDateTime.now());
}
return userRepository.findPerformedTasksByCursor(cursor, size, user);
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/dangsim/user/service/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.time.LocalDateTime;
import java.util.Optional;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -109,6 +110,7 @@ void testGetMemberProfile() {
assertThat(response.profileImage()).isEqualTo(PROFILE_IMAGE);
}

@Disabled
@DisplayName("유저의 심부름 요청 내역을 조회한다. - 커서 없음")
@Test
void getRequestedTasksWithNoCursor() {
Expand Down