From db359f8efc7925ac400c5d41c7b7e7719233f076 Mon Sep 17 00:00:00 2001 From: Byuk_mm Date: Sat, 27 Jul 2024 14:53:03 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[chore][#23]=20jenkinsfile=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..62ec60c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,69 @@ +pipeline { + agent any + + tools { + jdk 'JDK21' + } + + environment { + DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials-id') + DOCKER_IMAGE = 'jeongsangbyuk/bbogak-dev:latest' + K8S_URL = credentials('k8s-url') + K8S_NAMESPACE = 'bbogak-api' + JAVA_HOME = "${tool 'JDK21'}" + PATH = "${env.JAVA_HOME}/bin:${env.PATH}" + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build') { + steps { + script { + sh './gradlew clean build' + sh './gradlew openapi3' + } + } + } + + stage('Login'){ + steps{ + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' // docker hub 로그인 + } + } + + stage('Build & Push Docker Image') { + steps { + script { + sh 'docker buildx build --push --platform linux/amd64 -t $DOCKER_IMAGE .' + } + } + } + stage('ssh-test') { + steps{ + script{ + sshagent (credentials: ['ncp-key']) { + sh """ + ssh -o StrictHostKeyChecking=no ${K8S_URL} << EOF + microk8s kubectl rollout restart deploy deploy-bbogak-api-dev -n=$K8S_NAMESPACE + """ + } + } + } + } + + } + + post { + success { + echo 'Deployment was successful!' + } + failure { + echo 'Deployment failed!' + } + } +} \ No newline at end of file From 694d9e5c26f44ff2ab7c34169c16ab2f7b3e146f Mon Sep 17 00:00:00 2001 From: Byuk_mm Date: Sat, 27 Jul 2024 14:53:03 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[chore][#23]=20jenkinsfile=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jenkinsfile | 69 +++++++++++++++++++ .../config/security/SecurityConfig.java | 3 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..62ec60c --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,69 @@ +pipeline { + agent any + + tools { + jdk 'JDK21' + } + + environment { + DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials-id') + DOCKER_IMAGE = 'jeongsangbyuk/bbogak-dev:latest' + K8S_URL = credentials('k8s-url') + K8S_NAMESPACE = 'bbogak-api' + JAVA_HOME = "${tool 'JDK21'}" + PATH = "${env.JAVA_HOME}/bin:${env.PATH}" + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build') { + steps { + script { + sh './gradlew clean build' + sh './gradlew openapi3' + } + } + } + + stage('Login'){ + steps{ + sh 'echo $DOCKERHUB_CREDENTIALS_PSW | docker login -u $DOCKERHUB_CREDENTIALS_USR --password-stdin' // docker hub 로그인 + } + } + + stage('Build & Push Docker Image') { + steps { + script { + sh 'docker buildx build --push --platform linux/amd64 -t $DOCKER_IMAGE .' + } + } + } + stage('ssh-test') { + steps{ + script{ + sshagent (credentials: ['ncp-key']) { + sh """ + ssh -o StrictHostKeyChecking=no ${K8S_URL} << EOF + microk8s kubectl rollout restart deploy deploy-bbogak-api-dev -n=$K8S_NAMESPACE + """ + } + } + } + } + + } + + post { + success { + echo 'Deployment was successful!' + } + failure { + echo 'Deployment failed!' + } + } +} \ No newline at end of file diff --git a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java index 9701e35..6365d48 100644 --- a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java +++ b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java @@ -62,7 +62,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { public CorsConfigurationSource corsConfigurationSource() { CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowedOrigins( - List.of("http://114.70.23.79:8080", "http://localhost:8080", "http://52.65.6.74:8080")); // 허용할 오리진 지정 + List.of("http://114.70.23.79:8080", "http://localhost:8080", "http://52.65.6.74:8080", + "http://118.67.129.12")); // 허용할 오리진 지정 configuration.addAllowedMethod("*"); configuration.setAllowedHeaders(List.of("*")); // 허용할 헤더 configuration.setAllowCredentials(true); From 4f79d64f44f519be1953b5f1bbaef34e43453e41 Mon Sep 17 00:00:00 2001 From: Byuk_mm Date: Sat, 3 Aug 2024 20:50:15 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[chore][#23]=20ingress=20controller=20swagg?= =?UTF-8?q?er=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [chore][#23] 스웨거 셋팅 테스트 [chore][#23] 스웨거 셋팅 테스트 --- .../com/server/bbo_gak/BboGakApplication.java | 7 +++++++ .../server/bbo_gak/global/config/WebConfig.java | 7 +++++++ .../global/config/security/SecurityConfig.java | 3 ++- src/main/resources/application-prod.yml | 15 +++++++++++++++ src/main/resources/application-swagger.yml | 2 +- src/main/resources/application.yml | 3 ++- 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/application-prod.yml diff --git a/src/main/java/com/server/bbo_gak/BboGakApplication.java b/src/main/java/com/server/bbo_gak/BboGakApplication.java index 23294e0..803af3c 100644 --- a/src/main/java/com/server/bbo_gak/BboGakApplication.java +++ b/src/main/java/com/server/bbo_gak/BboGakApplication.java @@ -1,11 +1,18 @@ package com.server.bbo_gak; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.servers.Server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @EnableJpaAuditing @SpringBootApplication +@OpenAPIDefinition( + servers = { + @Server(url = "/") + } +) public class BboGakApplication { public static void main(String[] args) { diff --git a/src/main/java/com/server/bbo_gak/global/config/WebConfig.java b/src/main/java/com/server/bbo_gak/global/config/WebConfig.java index f36fe18..8ca510d 100644 --- a/src/main/java/com/server/bbo_gak/global/config/WebConfig.java +++ b/src/main/java/com/server/bbo_gak/global/config/WebConfig.java @@ -3,9 +3,11 @@ import com.server.bbo_gak.global.annotation.AuthenticationArgumentResolver; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.filter.ForwardedHeaderFilter; import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -32,4 +34,9 @@ public void addCorsMappings(CorsRegistry registry) { public void addArgumentResolvers(List resolvers) { resolvers.add(authenticationArgumentResolver); } + + @Bean + ForwardedHeaderFilter forwardedHeaderFilter() { + return new ForwardedHeaderFilter(); + } } diff --git a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java index 6365d48..cae3379 100644 --- a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java +++ b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java @@ -27,7 +27,8 @@ public class SecurityConfig { private final JwtTokenService jwtTokenService; - private String[] allowUrls = {"/", "/api/v1/users/test/login", "/docs/**", "/v3/**", "/favicon.ico"}; + private String[] allowUrls = {"/", "/api/v1/users/test/login", "/docs/**", "/v3/**", "/favicon.ico", + "/api/docs/**", "/api/v3/**"}; @Bean public WebSecurityCustomizer configure() { diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml new file mode 100644 index 0000000..e47c6b7 --- /dev/null +++ b/src/main/resources/application-prod.yml @@ -0,0 +1,15 @@ +spring: + config: + activate: + on-profile: prod + jpa: + properties: + hibernate: + show_sql: true + format_sql: true + use_sql_comments: true + hibernate: + ddl-auto: update + +server: + forward-headers-strategy: framework diff --git a/src/main/resources/application-swagger.yml b/src/main/resources/application-swagger.yml index 822e082..3a1efe9 100644 --- a/src/main/resources/application-swagger.yml +++ b/src/main/resources/application-swagger.yml @@ -3,4 +3,4 @@ springdoc: default-produces-media-type: application/json;charset=UTF-8 swagger-ui: url: /docs/open-api-3.0.1.json - path: /docs/swagger \ No newline at end of file + path: /docs/swagger diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a580472..d74a530 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,10 +1,11 @@ spring: profiles: - active: local + active: prod group: test: "test" local: "local, datasource" dev: "dev, datasource" + prod: "prod, datasource" include: - security - swagger From 35013216bacc13fa2a42613bff19d1a2c0be7f38 Mon Sep 17 00:00:00 2001 From: Byuk_mm Date: Sun, 18 Aug 2024 17:11:25 +0900 Subject: [PATCH 4/5] [chore][#23] health check api [chore][#23] health check code Update Jenkinsfile --- Jenkinsfile | 2 +- build.gradle | 1 + .../java/com/server/bbo_gak/BboGakApplication.java | 7 ------- .../bbo_gak/global/config/security/SecurityConfig.java | 3 +-- src/main/resources/application-prod.yml | 10 ++++++++++ src/main/resources/application.yml | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 62ec60c..6a1e28d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,4 +66,4 @@ pipeline { echo 'Deployment failed!' } } -} \ No newline at end of file +} diff --git a/build.gradle b/build.gradle index 16c3b03..bbe6da3 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-actuator' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/com/server/bbo_gak/BboGakApplication.java b/src/main/java/com/server/bbo_gak/BboGakApplication.java index 803af3c..23294e0 100644 --- a/src/main/java/com/server/bbo_gak/BboGakApplication.java +++ b/src/main/java/com/server/bbo_gak/BboGakApplication.java @@ -1,18 +1,11 @@ package com.server.bbo_gak; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; -import io.swagger.v3.oas.annotations.servers.Server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @EnableJpaAuditing @SpringBootApplication -@OpenAPIDefinition( - servers = { - @Server(url = "/") - } -) public class BboGakApplication { public static void main(String[] args) { diff --git a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java index cae3379..8528569 100644 --- a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java +++ b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java @@ -28,7 +28,7 @@ public class SecurityConfig { private final JwtTokenService jwtTokenService; private String[] allowUrls = {"/", "/api/v1/users/test/login", "/docs/**", "/v3/**", "/favicon.ico", - "/api/docs/**", "/api/v3/**"}; + "/api/docs/**", "/api/v3/**", "/api/health-check/**"}; @Bean public WebSecurityCustomizer configure() { @@ -78,5 +78,4 @@ public CorsConfigurationSource corsConfigurationSource() { public BCryptPasswordEncoder bCryptPasswordEncoder() { return new BCryptPasswordEncoder(); } - } diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index e47c6b7..12bd0d4 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -13,3 +13,13 @@ spring: server: forward-headers-strategy: framework + +management: + endpoints: + enabled-by-default: false + web: + base-path: /api/health-check + endpoint: + health: + enabled: true + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d74a530..00ad658 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - active: prod + active: local group: test: "test" local: "local, datasource" From a5f1a9e2318a3b610c76544b25c4b9a416c0a345 Mon Sep 17 00:00:00 2001 From: Byuk_mm Date: Sun, 18 Aug 2024 17:11:25 +0900 Subject: [PATCH 5/5] [chore][#23] health check api [chore][#23] health check code Update Jenkinsfile --- Jenkinsfile | 9 +++++---- build.gradle | 1 + .../java/com/server/bbo_gak/BboGakApplication.java | 7 ------- .../bbo_gak/global/config/security/SecurityConfig.java | 3 +-- src/main/resources/application-prod.yml | 10 ++++++++++ src/main/resources/application.yml | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 62ec60c..19e17ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,9 +7,10 @@ pipeline { environment { DOCKERHUB_CREDENTIALS = credentials('dockerhub-credentials-id') - DOCKER_IMAGE = 'jeongsangbyuk/bbogak-dev:latest' + DOCKER_IMAGE = credentials('docker-image') K8S_URL = credentials('k8s-url') - K8S_NAMESPACE = 'bbogak-api' + K8S_NAMESPACE = credentials('k8s-namespace') + K8S_DEPLOY_NAME = credentials('k8s-deploy-name') JAVA_HOME = "${tool 'JDK21'}" PATH = "${env.JAVA_HOME}/bin:${env.PATH}" } @@ -49,7 +50,7 @@ pipeline { sshagent (credentials: ['ncp-key']) { sh """ ssh -o StrictHostKeyChecking=no ${K8S_URL} << EOF - microk8s kubectl rollout restart deploy deploy-bbogak-api-dev -n=$K8S_NAMESPACE + microk8s kubectl rollout restart deploy ${K8S_DEPLOY_NAME} -n=${K8S_NAMESPACE} """ } } @@ -66,4 +67,4 @@ pipeline { echo 'Deployment failed!' } } -} \ No newline at end of file +} diff --git a/build.gradle b/build.gradle index 16c3b03..bbe6da3 100644 --- a/build.gradle +++ b/build.gradle @@ -38,6 +38,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-actuator' compileOnly 'org.projectlombok:lombok' runtimeOnly 'com.mysql:mysql-connector-j' annotationProcessor 'org.projectlombok:lombok' diff --git a/src/main/java/com/server/bbo_gak/BboGakApplication.java b/src/main/java/com/server/bbo_gak/BboGakApplication.java index 803af3c..23294e0 100644 --- a/src/main/java/com/server/bbo_gak/BboGakApplication.java +++ b/src/main/java/com/server/bbo_gak/BboGakApplication.java @@ -1,18 +1,11 @@ package com.server.bbo_gak; -import io.swagger.v3.oas.annotations.OpenAPIDefinition; -import io.swagger.v3.oas.annotations.servers.Server; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; @EnableJpaAuditing @SpringBootApplication -@OpenAPIDefinition( - servers = { - @Server(url = "/") - } -) public class BboGakApplication { public static void main(String[] args) { diff --git a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java index cae3379..8528569 100644 --- a/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java +++ b/src/main/java/com/server/bbo_gak/global/config/security/SecurityConfig.java @@ -28,7 +28,7 @@ public class SecurityConfig { private final JwtTokenService jwtTokenService; private String[] allowUrls = {"/", "/api/v1/users/test/login", "/docs/**", "/v3/**", "/favicon.ico", - "/api/docs/**", "/api/v3/**"}; + "/api/docs/**", "/api/v3/**", "/api/health-check/**"}; @Bean public WebSecurityCustomizer configure() { @@ -78,5 +78,4 @@ public CorsConfigurationSource corsConfigurationSource() { public BCryptPasswordEncoder bCryptPasswordEncoder() { return new BCryptPasswordEncoder(); } - } diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml index e47c6b7..12bd0d4 100644 --- a/src/main/resources/application-prod.yml +++ b/src/main/resources/application-prod.yml @@ -13,3 +13,13 @@ spring: server: forward-headers-strategy: framework + +management: + endpoints: + enabled-by-default: false + web: + base-path: /api/health-check + endpoint: + health: + enabled: true + diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d74a530..00ad658 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - active: prod + active: local group: test: "test" local: "local, datasource"