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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@RestController
@RequiredArgsConstructor
public class PaymentController {

}
6 changes: 5 additions & 1 deletion src/main/java/com/dangsim/payment/entity/Payment.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,12 @@ public static Payment of(BigDecimal reward, PaymentStatus status, String merchan
.build();
}


public void updatePaymentSuccessStatus(PaymentStatus successPaymentStatus) {
this.status = successPaymentStatus;
}

public void updatePerformer(User performer) {
this.performer = performer;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dangsim.pg.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -17,12 +18,15 @@ public class PaymentGatewayController {

private final PaymentGatewayService paymentGatewayService;

@PostMapping("/api/payments/completion")
public ResponseEntity<PaymentResponse> completePayment(@RequestBody PortOneResponse paymentResponseDto) {
@PostMapping("/api/payments/validation")
public ResponseEntity<PaymentResponse> completePayment(@RequestBody PortOneResponse portOneResponseDto) {

paymentGatewayService.verifyPaymentDetail(paymentResponseDto.getImpUid());
paymentGatewayService.verifyPaymentDetail(portOneResponseDto.getImpUid(), portOneResponseDto.getMerchantUid());

// 결제 성공 시 결제 및 테스크 상태 업데이트
paymentGatewayService.updatePaymentAndTaskStatus(portOneResponseDto.getMerchantUid());

return ResponseEntity.ok()
.body(new PaymentResponse(true, "결제 및 검증 성공"));
.body(new PaymentResponse(true, "결제 및 검증 성공", portOneResponseDto.getTaskId()));
}
}
1 change: 1 addition & 0 deletions src/main/java/com/dangsim/pg/dto/PaymentResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
public class PaymentResponse {
private boolean success;
private String message;
private Long taskId;
}
5 changes: 2 additions & 3 deletions src/main/java/com/dangsim/pg/dto/PortOneResponse.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.dangsim.pg.dto;

import java.math.BigDecimal;

import lombok.Getter;

@Getter
public class PortOneResponse {
private BigDecimal amount;
private String impUid; // 아임포트 결제 고유번호
private String merchantUid; // 주문 고유번호
private Long taskId;
private String buyer_name;
}
Loading