Skip to content

Commit

Permalink
feat :: 몰라.
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed Jul 15, 2024
1 parent 6c5ef97 commit 4abe88b
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
package xquare.app.xquareinfra.domain.container.adapter

import org.springframework.web.bind.annotation.*
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateGradleDockerfileRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeDockerfileRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeWithNginxDockerfileRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.request.SetContainerConfigRequest
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateGradleDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeWithNginxDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.SetContainerConfigUseCase
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.*

@RequestMapping("/v2/container")
@RestController
class V2ContainerWebAdapter(
private val setContainerConfigUseCase: SetContainerConfigUseCase
private val setContainerConfigUseCase: SetContainerConfigUseCase,
private val createGradleDockerfileUseCase: CreateGradleDockerfileUseCase,
private val createNodeWithNginxDockerfileUseCase: CreateNodeWithNginxDockerfileUseCase,
private val createNodeDockerfileUseCase: CreateNodeDockerfileUseCase
) {
@PutMapping("/config")
fun setContainerConfig(
Expand All @@ -17,4 +27,34 @@ class V2ContainerWebAdapter(
@RequestBody
setContainerConfigRequest: SetContainerConfigRequest
) = setContainerConfigUseCase.setContainerConfig(deployId, setContainerConfigRequest)

@PostMapping("/gradle")
fun createGradleDockerfile(
@RequestParam(name = "deployId", required = true)
deployId: UUID,
@RequestParam(name = "environment", required = true)
containerEnvironment: ContainerEnvironment,
@RequestBody
createGradleDockerfileRequest: CreateGradleDockerfileRequest
) = createGradleDockerfileUseCase.createGradleDockerfile(deployId, containerEnvironment, createGradleDockerfileRequest)

@PostMapping("/node")
fun createNodeDockerfile(
@RequestParam(name = "deployId", required = true)
deployId: UUID,
@RequestParam(name = "environment", required = true)
containerEnvironment: ContainerEnvironment,
@RequestBody
createNodeDockerfileRequest: CreateNodeDockerfileRequest
) = createNodeDockerfileUseCase.createNodeDockerfile(deployId, containerEnvironment, createNodeDockerfileRequest)

@PostMapping("/node-with-nginx")
fun createNodeWithNginxDockerfile(
@RequestParam(name = "deployId", required = true)
deployId: UUID,
@RequestParam(name = "environment", required = true)
containerEnvironment: ContainerEnvironment,
@RequestBody
createNodeWithNginxDockerfileRequest: CreateNodeWithNginxDockerfileRequest
) = createNodeWithNginxDockerfileUseCase.createNodeWithNginxDockerfile(deployId, containerEnvironment, createNodeWithNginxDockerfileRequest)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package xquare.app.xquareinfra.domain.container.adapter.dto.request

data class CreateGradleDockerfileRequest(
val jdkVersion: Int,
val outputDir: String,
val builder: String = "gradle",
val commands: List<String> = listOf(),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xquare.app.xquareinfra.domain.container.adapter.dto.request

data class CreateNodeDockerfileRequest(
val nodeVersion: String,
val buildCommands: List<String> = emptyList(),
val builder: String = "node",
val command: String,
var port: Int? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xquare.app.xquareinfra.domain.container.adapter.dto.request

data class CreateNodeWithNginxDockerfileRequest(
val nodeVersion: Int,
val commands: List<String> = emptyList(),
val builder: String = "node_with_nginx",
val outputDir: String,
var port: Int?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xquare.app.xquareinfra.domain.container.application.port.`in`

import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateGradleDockerfileRequest
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.UUID

interface CreateGradleDockerfileUseCase {
fun createGradleDockerfile(
deployId: UUID,
containerEnvironment: ContainerEnvironment,
createGradleDockerfileRequest: CreateGradleDockerfileRequest
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xquare.app.xquareinfra.domain.container.application.port.`in`

import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeDockerfileRequest
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.*

interface CreateNodeDockerfileUseCase {
fun createNodeDockerfile(
deployId: UUID,
containerEnvironment: ContainerEnvironment,
createNodeDockerfileRequest: CreateNodeDockerfileRequest
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package xquare.app.xquareinfra.domain.container.application.port.`in`

import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeWithNginxDockerfileRequest
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.*

interface CreateNodeWithNginxDockerfileUseCase {
fun createNodeWithNginxDockerfile(
deployId: UUID,
containerEnvironment: ContainerEnvironment,
createNodeDockerfileRequest: CreateNodeWithNginxDockerfileRequest
)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package xquare.app.xquareinfra.domain.container.application.port.`in`

import xquare.app.xquareinfra.domain.container.adapter.dto.request.SetContainerConfigRequest
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.UUID
import java.util.*

interface SetContainerConfigUseCase {
fun setContainerConfig(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package xquare.app.xquareinfra.domain.container.application.service

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.stereotype.Service
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateGradleDockerfileRequest
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateGradleDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.out.FindContainerPort
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort
import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException
import xquare.app.xquareinfra.infrastructure.feign.client.github.GithubClient
import xquare.app.xquareinfra.infrastructure.feign.client.github.dto.request.DispatchEventRequest
import xquare.app.xquareinfra.infrastructure.global.env.github.GithubProperties
import java.util.*

@Service
class CreateGradleDockerfileService(
private val findDeployPort: FindDeployPort,
private val githubClient: GithubClient,
private val findContainerPort: FindContainerPort,
private val githubProperties: GithubProperties,
private val objectMapper: ObjectMapper
) : CreateGradleDockerfileUseCase{
override fun createGradleDockerfile(
deployId: UUID,
containerEnvironment: ContainerEnvironment,
createGradleDockerfileRequest: CreateGradleDockerfileRequest
) {
val deploy = findDeployPort.findById(deployId) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND
val container = findContainerPort.findByDeployAndEnvironment(deploy, containerEnvironment)
?: throw BusinessLogicException.CONTAINER_NOT_FOUND

githubClient.dispatchWorkflow(
authorization = "Bearer ${githubProperties.token}",
accept = "application/vnd.github.v3+json",
request = DispatchEventRequest(
event_type = "write-dockerfile",
client_payload = mapOf(
"name" to deploy.deployName,
"environment" to container.containerEnvironment.name,
"template_json" to objectMapper.writeValueAsString(createGradleDockerfileRequest),
"builder" to createGradleDockerfileRequest.builder
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package xquare.app.xquareinfra.domain.container.application.service

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.stereotype.Service
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeDockerfileRequest
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.out.FindContainerPort
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort
import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException
import xquare.app.xquareinfra.infrastructure.feign.client.github.GithubClient
import xquare.app.xquareinfra.infrastructure.feign.client.github.dto.request.DispatchEventRequest
import xquare.app.xquareinfra.infrastructure.global.env.github.GithubProperties
import java.util.*

@Service
class CreateNodeDockerfileService(
private val findDeployPort: FindDeployPort,
private val githubClient: GithubClient,
private val findContainerPort: FindContainerPort,
private val githubProperties: GithubProperties,
private val objectMapper: ObjectMapper
) : CreateNodeDockerfileUseCase {
override fun createNodeDockerfile(
deployId: UUID,
containerEnvironment: ContainerEnvironment,
createNodeDockerfileRequest: CreateNodeDockerfileRequest
) {
val deploy = findDeployPort.findById(deployId) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND
val container = findContainerPort.findByDeployAndEnvironment(deploy, containerEnvironment)
?: throw BusinessLogicException.CONTAINER_NOT_FOUND

createNodeDockerfileRequest.port = container.containerPort

githubClient.dispatchWorkflow(
authorization = "Bearer ${githubProperties.token}",
accept = "application/vnd.github.v3+json",
request = DispatchEventRequest(
event_type = "write-dockerfile",
client_payload = mapOf(
"name" to deploy.deployName,
"environment" to container.containerEnvironment.name,
"template_json" to objectMapper.writeValueAsString(createNodeDockerfileRequest),
"builder" to createNodeDockerfileRequest.builder
)
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package xquare.app.xquareinfra.domain.container.application.service

import com.fasterxml.jackson.databind.ObjectMapper
import org.springframework.stereotype.Service
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeDockerfileRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.request.CreateNodeWithNginxDockerfileRequest
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.CreateNodeWithNginxDockerfileUseCase
import xquare.app.xquareinfra.domain.container.application.port.out.FindContainerPort
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort
import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException
import xquare.app.xquareinfra.infrastructure.feign.client.github.GithubClient
import xquare.app.xquareinfra.infrastructure.feign.client.github.dto.request.DispatchEventRequest
import xquare.app.xquareinfra.infrastructure.global.env.github.GithubProperties
import java.util.*

@Service
class CreateNodeWithNginxDockerfileService(
private val findDeployPort: FindDeployPort,
private val githubClient: GithubClient,
private val findContainerPort: FindContainerPort,
private val githubProperties: GithubProperties,
private val objectMapper: ObjectMapper
) : CreateNodeWithNginxDockerfileUseCase {
override fun createNodeWithNginxDockerfile(
deployId: UUID,
containerEnvironment: ContainerEnvironment,
createNodeDockerfileRequest: CreateNodeWithNginxDockerfileRequest
) {
val deploy = findDeployPort.findById(deployId) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND
val container = findContainerPort.findByDeployAndEnvironment(deploy, containerEnvironment)
?: throw BusinessLogicException.CONTAINER_NOT_FOUND

createNodeDockerfileRequest.port = container.containerPort

githubClient.dispatchWorkflow(
authorization = "Bearer ${githubProperties.token}",
accept = "application/vnd.github.v3+json",
request = DispatchEventRequest(
event_type = "write-dockerfile",
client_payload = mapOf(
"name" to deploy.deployName,
"environment" to container.containerEnvironment.name,
"template_json" to objectMapper.writeValueAsString(createNodeDockerfileRequest),
"builder" to createNodeDockerfileRequest.builder
)
)
)
}
}

0 comments on commit 4abe88b

Please sign in to comment.