roadan commented on a change in pull request #56: Ama cli docker
URL: https://github.com/apache/incubator-amaterasu/pull/56#discussion_r295650979
 
 

 ##########
 File path: 
ama-cli/src/main/kotlin/org/apache/amaterasu/ama/cli/container/ContainerHandler.kt
 ##########
 @@ -0,0 +1,67 @@
+package org.apache.amaterasu.ama.cli.container
+
+import com.github.dockerjava.api.DockerClient
+import com.github.dockerjava.api.model.BuildResponseItem
+import com.github.dockerjava.core.DefaultDockerClientConfig
+import com.github.dockerjava.core.DockerClientBuilder
+import com.github.dockerjava.core.command.BuildImageResultCallback
+import com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory
+import org.slf4j.LoggerFactory
+import java.io.File
+
+
+class ContainerHandler(val action : String) {
+  val logger = LoggerFactory.getLogger(ContainerHandler::class.java)
+  private val dockerHost = System.getenv("DOCKER_HOST") ?: 
"unix:///var/run/docker.sock"
+  private val dockerRegistry = System.getenv("DOCKER_REGISTRY") ?: 
"127.0.0.1:5000"
+
+  private val actionHandlers = mapOf("BUILD" to ::buildDockerImage)
+
+  init {
+    logger.info("Got $action for docker as action")
+    val dockerExec =  buildDockerServerExecutor()
+    val dockerClient = getDockerClient(defaultContainerHandler(), dockerExec)
+    val reuslt = actionHandlers[action]?.invoke(dockerClient)
+
+    println(reuslt)
+  }
+
+  private fun buildDockerImage(dockerClient: DockerClient): String? {
+    val baseDir = File("./")
+    return 
dockerClient.buildImageCmd(baseDir).exec(BuildImageCallback()).awaitImageId()
+  }
+
+  private fun buildDockerServerExecutor() : JerseyDockerCmdExecFactory {
+    return JerseyDockerCmdExecFactory()
+        .withReadTimeout(1000)
+        .withConnectTimeout(1000)
+        .withMaxTotalConnections(100)
+        .withMaxPerRouteConnections(10)
+  }
+
+  private fun defaultContainerHandler(): DefaultDockerClientConfig {
+    return DefaultDockerClientConfig.createDefaultConfigBuilder()
+        .withDockerHost(dockerHost)
+        .withDockerTlsVerify(false)
+        .withRegistryUrl(dockerRegistry)
+        .build()
+  }
+
+  private fun getDockerClient(config: DefaultDockerClientConfig, 
dockerCmdExecFactory: JerseyDockerCmdExecFactory?): DockerClient {
 
 Review comment:
   Couldn't this three functions be a single expression funs?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to