-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
000251a
commit 2dfa1cb
Showing
6 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
plugins { | ||
id 'com.google.cloud.tools.jib' version '3.3.2' | ||
} | ||
|
||
bootJar { | ||
// 빌드된 Jar 파일명 지정 | ||
archiveFileName = "heachi-housework-" + buildVersion + ".jar" | ||
} | ||
|
||
dependencies { | ||
// 내부 모듈 | ||
implementation project(':heachi-support:common') | ||
implementation project(':heachi-support:logging') | ||
implementation project(':heachi-support:external-clients') | ||
implementation project(':heachi-domain-mysql') | ||
implementation project(':heachi-domain-redis') | ||
|
||
implementation 'org.springframework.boot:spring-boot-starter-web' // Spring Web | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' // Bean Validation | ||
|
||
// Swagger | ||
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0") | ||
|
||
testCompileOnly project(':heachi-support:common') | ||
testCompileOnly project(':heachi-support:logging') | ||
testCompileOnly project(':heachi-domain-mysql') | ||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
} | ||
|
||
jib { | ||
from { | ||
image = 'eclipse-temurin:17-jre' // https://github.com/GoogleContainerTools/jib/issues/3483 | ||
platforms { | ||
platform { | ||
architecture = "arm64" | ||
os = "linux" | ||
} | ||
} | ||
} | ||
to { | ||
image = 'ghdcksgml1/heachi-housework' | ||
tags = [buildVersion, "latest"] | ||
auth { | ||
username = dockerUsername | ||
password = dockerPassword | ||
} | ||
} | ||
container { | ||
|
||
entrypoint = ['java', '-Dspring.profiles.active=prod', '-jar', 'heachi-housework-' + buildVersion + '.jar'] | ||
jvmFlags = ['-Xms2048m', '-Xmx2048m', '-Xdebug', '-XshowSettings:vm', '-XX:+UnlockExperimentalVMOptions', '-XX:+UseContainerSupport'] | ||
ports = ['8000'] | ||
environment = [SPRING_OUTPUT_ANSI_ENABLED: "ALWAYS"] | ||
|
||
creationTime = 'USE_CURRENT_TIMESTAMP' | ||
format = 'Docker' | ||
} | ||
|
||
// 어디 폴더로 부터 가져올지 | ||
extraDirectories { | ||
paths { | ||
path { | ||
from = file('build/libs') | ||
} | ||
} | ||
} | ||
} | ||
|
||
bootJar.enabled = true | ||
jar.enabled = false |
13 changes: 13 additions & 0 deletions
13
heachi-core/housework-api/src/main/java/com/heachi/housework/HeachiHouseworkApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.heachi.housework; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
|
||
@SpringBootApplication(scanBasePackages = "com.heachi", exclude = SecurityAutoConfiguration.class) | ||
public class HeachiHouseworkApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(HeachiHouseworkApplication.class, args); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
heachi-core/housework-api/src/main/java/com/heachi/housework/config/AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.heachi.housework.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@EnableWebMvc | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class AppConfig implements WebMvcConfigurer { | ||
|
||
@Value("${spring.profiles.active}") | ||
private String activeProfile; | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
if (activeProfile.equals("prod")) { | ||
prodProfileCorsMapping(registry); | ||
} else { | ||
devProfileCorsMapping(registry); | ||
} | ||
} | ||
|
||
// 개발환경에서는 Cors 모두 오픈 | ||
private void devProfileCorsMapping(CorsRegistry registry) { | ||
|
||
registry.addMapping("/**") | ||
.allowedOriginPatterns("*") | ||
.allowedMethods("GET","POST","OPTIONS") | ||
.allowedHeaders("*") | ||
.allowCredentials(true); | ||
} | ||
|
||
// 프로덕션 환경에서는 Cors 설정을 Front 페이지와 허용할 서버만 등록해준다. | ||
private void prodProfileCorsMapping(CorsRegistry registry) { | ||
registry.addMapping("/**") | ||
.allowedOriginPatterns("*") | ||
.allowedMethods("GET","POST","OPTIONS") | ||
.allowedHeaders("*") | ||
.allowCredentials(true); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...ousework-api/src/main/java/com/heachi/housework/config/advice/GlobalExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.heachi.housework.config.advice; | ||
|
||
import com.heachi.admin.common.response.JsonResult; | ||
import org.springframework.validation.BindException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
@RestControllerAdvice | ||
public class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(BindException.class) | ||
public JsonResult bindException(BindException e) { | ||
return JsonResult.failOf( | ||
e.getBindingResult() | ||
.getFieldErrors() | ||
.stream() | ||
.map(fieldError -> fieldError.getField() + ": " + fieldError.getDefaultMessage()) | ||
.collect(Collectors.joining(", ")) | ||
); | ||
} | ||
|
||
@ExceptionHandler(Exception.class) | ||
public JsonResult<Exception> exception(Exception e) { | ||
return JsonResult.failOf(e.getMessage()); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...i-core/housework-api/src/main/java/com/heachi/housework/config/swagger/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.heachi.housework.config.swagger; | ||
|
||
import io.swagger.v3.oas.models.Components; | ||
import io.swagger.v3.oas.models.OpenAPI; | ||
import io.swagger.v3.oas.models.info.Contact; | ||
import io.swagger.v3.oas.models.info.Info; | ||
import io.swagger.v3.oas.models.info.License; | ||
import io.swagger.v3.oas.models.security.SecurityRequirement; | ||
import io.swagger.v3.oas.models.security.SecurityScheme; | ||
import io.swagger.v3.oas.models.servers.Server; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Configuration | ||
public class SwaggerConfig { | ||
|
||
@Bean | ||
public OpenAPI openAPI(@Value("${heachiCoreAuthUrls}") String[] serverList) { | ||
Info info = new Info() | ||
.title("N빵 집안일 도메인 API Document") | ||
.version("0.1") | ||
.description("N빵 집안일 도메인 API 문서입니다.\n" + | ||
"해당 문서를 이용해 N빵 집안일 REST API를 테스트해볼 수 있습니다.") | ||
.contact(new Contact() | ||
.name("📍 N-bbang-housework Backend GitHub Link") | ||
.url("https://github.com/ghdcksgml1/N-bbang-housework")) | ||
.license(new License() | ||
.name("⚖️ Apache License Version 2.0") | ||
.url("http://www.apache.org/licenses/LICENSE-2.0")); | ||
|
||
List<Server> servers = Arrays.stream(serverList) | ||
.map((url) -> new Server().url(url)) | ||
.collect(Collectors.toList()); | ||
|
||
SecurityScheme securityScheme = new SecurityScheme() | ||
.name("Bearer Authentication") | ||
.type(SecurityScheme.Type.HTTP) | ||
.bearerFormat("JWT") | ||
.scheme("Bearer"); | ||
SecurityRequirement schemaRequirement = new SecurityRequirement().addList("bearerAuth"); | ||
|
||
return new OpenAPI() | ||
.components(new Components().addSecuritySchemes("bearerAuth", securityScheme)) | ||
.security(Arrays.asList(schemaRequirement)) | ||
.info(info) | ||
.servers(servers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters