commit c72ee8968f615fc8f3543fef0dcf6fe845a3b4eb Author: CUBETIQ Solution <> Date: Mon Dec 20 17:26:07 2021 +0700 Initial commit diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..58b9810 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,13 @@ +kind: pipeline +type: docker +name: ci +steps: + - name: submodules + image: d.ctdn.net/alpine/git + commands: + - git submodule update --init --recursive + - name: test + image: d.ctdn.net/cubetiq/openjdk:11u-ubuntu + commands: + - apt-get update && apt-get install git -y + - sh gradlew bootJar \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..dd84ea7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2bff8a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..58689d8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM cubetiq/calpine-openjdk11:latest +LABEL maintainer="sombochea@cubetiqs.com" + +# Working directory for application +WORKDIR /opt/cubetiq + +# Define mount volumn for data path +VOLUME ["/opt/cubetiq/data"] + +# Copy build source to container +COPY api/build/libs/*.jar ./api.jar + +ENV APP_DATA_DIR "/opt/cubetiq/data" + +# Entrypoint to app +CMD ["java","-jar", "./api.jar"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..2fe194e --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# CUBETIQ Web Modules (Template) +- Setup and Default Web Configuration +- Swagger UI and API's Documentation (SpringFox) +- General Purpose for External and Internal use-cases +- Dockerfile and Docker profile build support + +# Modules +- API (Default Module) + +# Contributors +- Sambo Chea + +### Language and Framework +- Spring Boot: 2.5.7 +- Kotlin: 1.6.0 +- Gradle: 7.3.1 \ No newline at end of file diff --git a/api/.gitignore b/api/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/api/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/api/build.gradle.kts b/api/build.gradle.kts new file mode 100644 index 0000000..63065e0 --- /dev/null +++ b/api/build.gradle.kts @@ -0,0 +1,52 @@ +import java.io.ByteArrayOutputStream + +plugins { + id("org.springframework.boot") + id("io.spring.dependency-management") + kotlin("jvm") + kotlin("plugin.spring") +} + +val kotlinVersion = "1.6.0" +val springBootVersion = "2.5.7" + +// find the last commit +fun getGitHashLastCommit(): String { + val stdout = ByteArrayOutputStream() + exec { + commandLine("git", "rev-parse", "HEAD") + standardOutput = stdout + } + + return stdout.toString().trim() +} + +springBoot { + buildInfo { + properties { + additional["commitId"] = getGitHashLastCommit() + additional["springBootVersion"] = springBootVersion + additional["kotlinVersion"] = kotlinVersion + } + } +} + +dependencies { + // Migrating from SpringFox + implementation("org.springdoc:springdoc-openapi-ui:1.5.13") + + // SPRING FRAMEWORK AND CORE + implementation("org.springframework.boot:spring-boot-starter-web") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin") + + // Development Runtime + developmentOnly("org.springframework.boot:spring-boot-devtools") + + implementation("org.jetbrains.kotlin:kotlin-reflect") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + testImplementation("org.springframework.boot:spring-boot-starter-test") +} + +tasks.withType { + useJUnitPlatform() +} diff --git a/api/src/main/kotlin/com/cubetiqs/web/ApiApplication.kt b/api/src/main/kotlin/com/cubetiqs/web/ApiApplication.kt new file mode 100644 index 0000000..0bb1387 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/ApiApplication.kt @@ -0,0 +1,11 @@ +package com.cubetiqs.web + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class ApiApplication + +fun main(args: Array) { + runApplication(*args) +} diff --git a/api/src/main/kotlin/com/cubetiqs/web/StaticContextInitializer.kt b/api/src/main/kotlin/com/cubetiqs/web/StaticContextInitializer.kt new file mode 100644 index 0000000..aecc660 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/StaticContextInitializer.kt @@ -0,0 +1,12 @@ +package com.cubetiqs.web + +import com.cubetiqs.web.stereotype.FunctionComponent +import org.springframework.context.annotation.Lazy + +@FunctionComponent +@Lazy(false) +class StaticContextInitializer { + init { + println("Static context is loaded...!") + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/annotation/ApiBearerAuth.kt b/api/src/main/kotlin/com/cubetiqs/web/annotation/ApiBearerAuth.kt new file mode 100644 index 0000000..7476f9b --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/annotation/ApiBearerAuth.kt @@ -0,0 +1,8 @@ +package com.cubetiqs.web.annotation + +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.security.SecurityRequirement + +@Retention(AnnotationRetention.RUNTIME) +@Operation(security = [SecurityRequirement(name = "bearerAuth")]) +annotation class ApiBearerAuth() diff --git a/api/src/main/kotlin/com/cubetiqs/web/config/DefaultConfig.kt b/api/src/main/kotlin/com/cubetiqs/web/config/DefaultConfig.kt new file mode 100644 index 0000000..edd4d7a --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/config/DefaultConfig.kt @@ -0,0 +1,6 @@ +package com.cubetiqs.web.config + +import org.springframework.context.annotation.Configuration + +@Configuration +class DefaultConfig \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/config/OpenApiDocConfig.kt b/api/src/main/kotlin/com/cubetiqs/web/config/OpenApiDocConfig.kt new file mode 100644 index 0000000..0ae6db9 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/config/OpenApiDocConfig.kt @@ -0,0 +1,57 @@ +package com.cubetiqs.web.config + +import com.cubetiqs.web.property.AppProperties +import io.swagger.v3.oas.annotations.enums.SecuritySchemeType +import io.swagger.v3.oas.annotations.security.SecurityScheme +import io.swagger.v3.oas.models.OpenAPI +import io.swagger.v3.oas.models.info.Info +import io.swagger.v3.oas.models.info.License +import org.springdoc.core.GroupedOpenApi +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +@SecurityScheme( + name = "bearerAuth", + type = SecuritySchemeType.HTTP, + scheme = "bearer", + bearerFormat = "JWT", +) +class OpenApiDocConfig @Autowired constructor( + val appProperties: AppProperties, +) { + companion object { + private val ADMIN_API_PATH get() = "/admin/**" + private val DEFAULT_API_PATH get() = "/**" + } + + @Bean + fun defaultApi(): GroupedOpenApi { + return GroupedOpenApi.builder() + .group("default") + .pathsToMatch(DEFAULT_API_PATH) + .pathsToExclude("/error", ADMIN_API_PATH) + .packagesToScan("com.cubetiqs.web") + .build() + } + + @Bean + fun adminApi(): GroupedOpenApi { + return GroupedOpenApi.builder() + .group("admin") + .pathsToMatch(ADMIN_API_PATH) + .build() + } + + @Bean + fun cubetiqOpenAPI(): OpenAPI { + return OpenAPI() + .info( + Info().title(appProperties.appName) + .description(appProperties.appDescription) + .version(appProperties.appVersion) + .license(License().name("Apache 2.0").url(appProperties.appLicenseUrl)) + ) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/controller/ApiDoc.kt b/api/src/main/kotlin/com/cubetiqs/web/controller/ApiDoc.kt new file mode 100644 index 0000000..a5a7918 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/controller/ApiDoc.kt @@ -0,0 +1,15 @@ +package com.cubetiqs.web.controller + +import io.swagger.v3.oas.annotations.Hidden +import org.springframework.stereotype.Controller +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.servlet.view.RedirectView + +@Hidden +@Controller +class ApiDoc { + @GetMapping(value = [ "/api-doc", "/api-docs"]) + fun redirect(): RedirectView { + return RedirectView("/swagger-ui/") + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/controller/BaseController.kt b/api/src/main/kotlin/com/cubetiqs/web/controller/BaseController.kt new file mode 100644 index 0000000..624b846 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/controller/BaseController.kt @@ -0,0 +1,13 @@ +package com.cubetiqs.web.controller + +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity + +interface BaseController { + fun response( + data: T?, + status: HttpStatus = HttpStatus.OK, + ): ResponseEntity { + return ResponseEntity.status(status).body(data) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/controller/IndexController.kt b/api/src/main/kotlin/com/cubetiqs/web/controller/IndexController.kt new file mode 100644 index 0000000..492949c --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/controller/IndexController.kt @@ -0,0 +1,47 @@ +package com.cubetiqs.web.controller + +import com.cubetiqs.web.model.response.ApiInfoAuthorResponse +import com.cubetiqs.web.model.response.ApiInfoResponse +import com.cubetiqs.web.model.response.HealthResponse +import com.cubetiqs.web.util.RouteConstants +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.info.BuildProperties +import org.springframework.core.env.Environment +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "Miscellaneous") +@RestController +@RequestMapping(RouteConstants.INDEX) +class IndexController @Autowired constructor( + private val buildProperties: BuildProperties, + private val environment: Environment, +) : BaseController { + @GetMapping + fun index(): ResponseEntity { + val authors = listOf( + ApiInfoAuthorResponse(name = "Sambo Chea", email = "sombochea@cubetiqs.com"), + ApiInfoAuthorResponse(name = "CUBETIQ OSS", email = "oss@cubetiqs.com"), + ) + val response = ApiInfoResponse( + info = "API Operation is running normally on ${environment.activeProfiles.joinToString(separator = ",")}", + name = buildProperties.name, + service = buildProperties.artifact, + version = buildProperties.version, + date = buildProperties.time.toString(), + commit = buildProperties["commitId"], + authors = authors, + ) + return response(response) + } + + @GetMapping("/health") + fun health(): ResponseEntity { + return response( + HealthResponse.UP + ) + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/controller/admin/AdminController.kt b/api/src/main/kotlin/com/cubetiqs/web/controller/admin/AdminController.kt new file mode 100644 index 0000000..f851765 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/controller/admin/AdminController.kt @@ -0,0 +1,20 @@ +package com.cubetiqs.web.controller.admin + +import com.cubetiqs.web.annotation.ApiBearerAuth +import com.cubetiqs.web.controller.BaseController +import com.cubetiqs.web.util.RouteConstants +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "Admin") +@RestController +@RequestMapping(RouteConstants.ADMIN) +class AdminController : BaseController { + @ApiBearerAuth + @GetMapping + fun getAdmin(): String { + return "Admin" + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/exception/BaseException.kt b/api/src/main/kotlin/com/cubetiqs/web/exception/BaseException.kt new file mode 100644 index 0000000..c0cdcba --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/exception/BaseException.kt @@ -0,0 +1,14 @@ +package com.cubetiqs.web.exception + +open class BaseException : RuntimeException { + constructor() : super() + constructor(message: String?) : super(message) + constructor(message: String?, cause: Throwable?) : super(message, cause) + constructor(cause: Throwable?) : super(cause) + constructor(message: String?, cause: Throwable?, enableSuppression: Boolean, writableStackTrace: Boolean) : super( + message, + cause, + enableSuppression, + writableStackTrace + ) +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/infrastructure/component/BaseFunctionComponent.kt b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/component/BaseFunctionComponent.kt new file mode 100644 index 0000000..e0e9b9e --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/component/BaseFunctionComponent.kt @@ -0,0 +1,5 @@ +package com.cubetiqs.web.infrastructure.component + +interface BaseFunctionComponent { + fun execute(input: I?): O? +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/infrastructure/data/BaseEntity.kt b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/data/BaseEntity.kt new file mode 100644 index 0000000..a4444ab --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/data/BaseEntity.kt @@ -0,0 +1,7 @@ +package com.cubetiqs.web.infrastructure.data + +import java.io.Serializable + +interface BaseEntity : Serializable { + fun setId(id: ID) +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/infrastructure/event/BaseEvent.kt b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/event/BaseEvent.kt new file mode 100644 index 0000000..50dabb0 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/event/BaseEvent.kt @@ -0,0 +1,5 @@ +package com.cubetiqs.web.infrastructure.event + +import java.io.Serializable + +interface BaseEvent : Serializable \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/infrastructure/listener/BaseEventListener.kt b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/listener/BaseEventListener.kt new file mode 100644 index 0000000..bdd6b68 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/listener/BaseEventListener.kt @@ -0,0 +1,9 @@ +package com.cubetiqs.web.infrastructure.listener + +import com.cubetiqs.web.infrastructure.event.BaseEvent + +interface BaseEventListener { + fun persist(event: BaseEvent) { + return + } +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/infrastructure/repository/BaseRepository.kt b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/repository/BaseRepository.kt new file mode 100644 index 0000000..f71e5d1 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/repository/BaseRepository.kt @@ -0,0 +1,3 @@ +package com.cubetiqs.web.infrastructure.repository + +interface BaseRepository \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/infrastructure/service/BaseService.kt b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/service/BaseService.kt new file mode 100644 index 0000000..306e40e --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/infrastructure/service/BaseService.kt @@ -0,0 +1,3 @@ +package com.cubetiqs.web.infrastructure.service + +interface BaseService \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/model/ob/BaseOb.kt b/api/src/main/kotlin/com/cubetiqs/web/model/ob/BaseOb.kt new file mode 100644 index 0000000..e8cdb0b --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/model/ob/BaseOb.kt @@ -0,0 +1,5 @@ +package com.cubetiqs.web.model.ob + +import java.io.Serializable + +interface BaseOb : Serializable \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/model/request/BaseResponseModel.kt b/api/src/main/kotlin/com/cubetiqs/web/model/request/BaseResponseModel.kt new file mode 100644 index 0000000..fc4affc --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/model/request/BaseResponseModel.kt @@ -0,0 +1,5 @@ +package com.cubetiqs.web.model.request + +import com.cubetiqs.web.model.ob.BaseOb + +interface BaseResponseModel : BaseOb \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/model/response/ApiInfoResponse.kt b/api/src/main/kotlin/com/cubetiqs/web/model/response/ApiInfoResponse.kt new file mode 100644 index 0000000..fec4996 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/model/response/ApiInfoResponse.kt @@ -0,0 +1,20 @@ +package com.cubetiqs.web.model.response + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(name = "ApiInfoResponse", description = "ApiInfoResponse") +data class ApiInfoResponse( + val name: String, + val info: String, + val service: String, + val version: String, + val date: String, + val commit: String, + val authors: Collection = listOf(), +) : BaseRequestModel + +@Schema(name = "ApiInfoAuthorResponse", description = "ApiInfoAuthorResponse") +data class ApiInfoAuthorResponse( + val name: String, + val email: String, +) : BaseRequestModel \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/model/response/BaseRequestModel.kt b/api/src/main/kotlin/com/cubetiqs/web/model/response/BaseRequestModel.kt new file mode 100644 index 0000000..8c8e1b1 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/model/response/BaseRequestModel.kt @@ -0,0 +1,5 @@ +package com.cubetiqs.web.model.response + +import com.cubetiqs.web.model.ob.BaseOb + +interface BaseRequestModel : BaseOb \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/model/response/HealthResponse.kt b/api/src/main/kotlin/com/cubetiqs/web/model/response/HealthResponse.kt new file mode 100644 index 0000000..7f718cc --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/model/response/HealthResponse.kt @@ -0,0 +1,16 @@ +package com.cubetiqs.web.model.response + +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(name = "HealthResponse", description = "HealthResponse") +data class HealthResponse( + @Schema(name = "status", description = "Status for the service") + val status: String, +) : BaseRequestModel { + companion object { + private const val STATUS_UP = "UP" + private const val STATUS_DOWN = "DOWN" + val UP get() = HealthResponse(STATUS_UP) + val DOWN get() = HealthResponse(STATUS_DOWN) + } +} diff --git a/api/src/main/kotlin/com/cubetiqs/web/modules/AppModule.kt b/api/src/main/kotlin/com/cubetiqs/web/modules/AppModule.kt new file mode 100644 index 0000000..6acc120 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/modules/AppModule.kt @@ -0,0 +1,5 @@ +package com.cubetiqs.web.modules + +interface AppModule { + fun getModule(): Class<*> +} \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/property/AppProperties.kt b/api/src/main/kotlin/com/cubetiqs/web/property/AppProperties.kt new file mode 100644 index 0000000..a2b21c5 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/property/AppProperties.kt @@ -0,0 +1,19 @@ +package com.cubetiqs.web.property + +import com.cubetiqs.web.stereotype.FunctionComponent +import org.springframework.beans.factory.annotation.Value + +@FunctionComponent +class AppProperties( + @Value("\${cubetiq.app.name:CUBETIQ Web API}") + val appName: String, + + @Value("\${cubetiq.app.description:CUBETIQ Web APIs Documentation}") + val appDescription: String, + + @Value("\${cubetiq.app.version:v0.0.1}") + val appVersion: String, + + @Value("\${cubetiq.app.license-url:https://cubetiqs.com}") + val appLicenseUrl: String, +) \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/stereotype/FunctionComponent.kt b/api/src/main/kotlin/com/cubetiqs/web/stereotype/FunctionComponent.kt new file mode 100644 index 0000000..be835b5 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/stereotype/FunctionComponent.kt @@ -0,0 +1,20 @@ +package com.cubetiqs.web.stereotype + +import org.springframework.context.annotation.Lazy +import org.springframework.core.annotation.AliasFor +import org.springframework.stereotype.Component + +/** + * @author sombochea + * @email sombochea@cubetiqs.com + * @date 18/05/21 + * @since 1.0 + */ +@Retention(AnnotationRetention.RUNTIME) +@Target(AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.CLASS) +@Lazy(value = true) +@Component +annotation class FunctionComponent( + @get: AliasFor(annotation = Component::class) + val value: String = "" +) \ No newline at end of file diff --git a/api/src/main/kotlin/com/cubetiqs/web/util/AppConstants.kt b/api/src/main/kotlin/com/cubetiqs/web/util/AppConstants.kt new file mode 100644 index 0000000..534f3b7 --- /dev/null +++ b/api/src/main/kotlin/com/cubetiqs/web/util/AppConstants.kt @@ -0,0 +1,10 @@ +package com.cubetiqs.web.util + +object RouteConstants { + const val INDEX = "/" + const val ADMIN = "/admin" +} + +object AppConstants { + val BASE_PACKAGE_API_DOCS get() = "com.cubetiqs.web" +} \ No newline at end of file diff --git a/api/src/main/resources/application-dev.yml b/api/src/main/resources/application-dev.yml new file mode 100644 index 0000000..47fbb02 --- /dev/null +++ b/api/src/main/resources/application-dev.yml @@ -0,0 +1,2 @@ +server: + port: 8080 \ No newline at end of file diff --git a/api/src/main/resources/application.yml b/api/src/main/resources/application.yml new file mode 100644 index 0000000..bea3b1f --- /dev/null +++ b/api/src/main/resources/application.yml @@ -0,0 +1,22 @@ +spring: + profiles: + active: ${APP_PROFILE:dev} + application: + name: cubetiq-api-service + +cubetiq: + app: + data-dir: ${APP_DATA_DIR:${user.home}/${spring.application.name}} + name: CUBETIQ Web API + description: CUBETIQ Spring Web API's Documentation + +logging: + file: + path: ${LOGGING_FILE_PATH:${cubetiq.app.data-dir}/logs/} + name: ${logging.file.path}/app.log + +springdoc: + api-docs: + enabled: true + swagger-ui: + path: /swagger-ui diff --git a/api/src/test/kotlin/com/cubetiqs/web/ApiApplicationTests.kt b/api/src/test/kotlin/com/cubetiqs/web/ApiApplicationTests.kt new file mode 100644 index 0000000..8a6e2db --- /dev/null +++ b/api/src/test/kotlin/com/cubetiqs/web/ApiApplicationTests.kt @@ -0,0 +1,13 @@ +package com.cubetiqs.web + +import org.junit.jupiter.api.Test +import org.springframework.boot.test.context.SpringBootTest + +@SpringBootTest +class ApiApplicationTests { + + @Test + fun contextLoads() { + } + +} diff --git a/apps/demo/.env b/apps/demo/.env new file mode 100644 index 0000000..3a2c672 --- /dev/null +++ b/apps/demo/.env @@ -0,0 +1,2 @@ +APP_PROFILE=demo +APP_DATA_DIR=/opt/cubetiq/data \ No newline at end of file diff --git a/apps/demo/application-demo.yml b/apps/demo/application-demo.yml new file mode 100644 index 0000000..8811dc3 --- /dev/null +++ b/apps/demo/application-demo.yml @@ -0,0 +1,2 @@ +server: + port: ${APP_PORT:8090} \ No newline at end of file diff --git a/apps/demo/build.sh b/apps/demo/build.sh new file mode 100644 index 0000000..158c6e3 --- /dev/null +++ b/apps/demo/build.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +# Get Execute Script Directory +SCRIPT_DIR=$(dirname "$0") + +# shellcheck disable=SC2039 +source "$SCRIPT_DIR"/variable.sh + +echo "===> Clean Gradle Build <===" +bash gradlew clean + +echo "===> Moving App File <===" +bash "$SCRIPT_DIR"/move-file.sh + +echo "===> Gradle Building Application <===" +bash gradlew build -x test + +echo "===> Docker Building Image <===" +docker build . -t "$ROOT_HUB" + +echo "===> Docker Pushing Image <===" +docker push "$ROOT_HUB" diff --git a/apps/demo/move-file.sh b/apps/demo/move-file.sh new file mode 100644 index 0000000..0abfab4 --- /dev/null +++ b/apps/demo/move-file.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Get Execute Script Directory +SCRIPT_DIR=$(dirname "$0") + +source "$SCRIPT_DIR"/variable.sh + +echo "===> Copy & Replace Application Profile <===" +rm -rf "$APP_MODULE_PATH"/src/main/resources/application-dev.yml +cp -f "$SCRIPT_DIR"/application-"$APP_PROFILE".yml "$APP_MODULE_PATH"/src/main/resources/ \ No newline at end of file diff --git a/apps/demo/run.sh b/apps/demo/run.sh new file mode 100644 index 0000000..7c6e288 --- /dev/null +++ b/apps/demo/run.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Get Execute Script Directory +SCRIPT_DIR=$(dirname "$0") + +# shellcheck disable=SC2039 +source "$SCRIPT_DIR"/variable.sh + +CONTAINER_NAME="$CONTAINER" +APP_DATA_DIR=$(passwd)/"$CONTAINER_NAME" + +echo "===> Docker Pulling New Image <===" +docker pull "$ROOT_HUB" + +echo "===> Docker Removing Container <===" +docker rm -f "$CONTAINER_NAME" + +echo "===> Docker Run Container: $CONTAINER_NAME <===" +docker run -d \ + -p "$EXPOSE_PORT":8090 \ + --env-file "$SCRIPT_DIR"/.env \ + -e HIBERNATE_DDL="${HIBERNATE_DDL:-update}" \ + -v "$APP_DATA_DIR"/data:/opt/cubetiq/data \ + --restart=always \ + --name "$CONTAINER_NAME" \ + "$ROOT_HUB" diff --git a/apps/demo/variable.sh b/apps/demo/variable.sh new file mode 100644 index 0000000..6b48545 --- /dev/null +++ b/apps/demo/variable.sh @@ -0,0 +1,11 @@ +# Build variables +APP_MODULE_PATH=api +APP_PROFILE=demo + +# Docker Image variables +VERSION=latest +IMAGE=api-demo +CONTAINER=$IMAGE +REGISTRY=registry.kh.cubetiqs.com +EXPOSE_PORT=8080 +ROOT_HUB=$REGISTRY/$IMAGE:$VERSION \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..907644d --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,49 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.springframework.boot") version "2.6.1" apply false + id("io.spring.dependency-management") version "1.0.11.RELEASE" apply false + kotlin("jvm") version "1.6.0" apply false + kotlin("plugin.spring") version "1.6.0" apply false + // kotlin("plugin.jpa") version "1.6.0" apply false +} + +allprojects { + // Fixed Zero-Day CVE-2021-44228: https://cubetiq.atlassian.net/browse/CERT-1 + // Fixed Zero-Day CVE-2021-45046: https://cubetiq.atlassian.net/browse/CERT-3 + // Fixed Zero-Day CVE-2021-45105: https://cubetiq.atlassian.net/browse/CERT-4 + ext["log4j2.version"] = "2.17.0" + + repositories { + maven("https://m.ctdn.net") + } + + group = "com.cubetiqs" + version = "0.0.1-SNAPSHOT" + + val javaVersion = "11" + + tasks.withType { + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + } + + tasks.withType { + kotlinOptions { + freeCompilerArgs = listOf("-Xjsr305=strict") + jvmTarget = javaVersion + } + } +} + +subprojects { + apply { + plugin("io.spring.dependency-management") + } + + the().apply { + imports { + mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES) + } + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..4d1a59e --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https://mirror.ctdn.net/gradle/gradle-7.3.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists \ No newline at end of file diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..ac1b06f --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..3582e66 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,5 @@ +rootProject.name = "spring-web-modules" + +include( + "api" +) \ No newline at end of file