Skip to content

Commit 87ece27

Browse files
committed
pull image first
1 parent c94c05d commit 87ece27

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

core/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@
5959
<plugin>
6060
<artifactId>maven-failsafe-plugin</artifactId>
6161
</plugin>
62-
<plugin>
63-
<groupId>org.codehaus.mojo</groupId>
64-
<artifactId>exec-maven-plugin</artifactId>
65-
<configuration>
66-
<mainClass>MainKt</mainClass>
67-
</configuration>
68-
</plugin>
6962
</plugins>
7063
</build>
7164

core/src/main/kotlin/com/javaaidev/llmcodeexecutor/core/LLMCodeExecutor.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.github.dockerjava.api.model.*
66
import com.github.dockerjava.core.DefaultDockerClientConfig
77
import com.github.dockerjava.core.DockerClientImpl
88
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient
9+
import org.slf4j.LoggerFactory
910
import java.io.Closeable
1011
import java.nio.file.Files
1112
import java.nio.file.Path
@@ -61,6 +62,7 @@ data class CodeExecutionResponse(
6162
)
6263

6364
class LLMCodeExecutor(private val config: CodeExecutorConfig) {
65+
private val logger = LoggerFactory.getLogger(LLMCodeExecutor::class.java)
6466
private val dockerClientConfig = DefaultDockerClientConfig.createDefaultConfigBuilder().build()
6567
private val httpClient = ApacheDockerHttpClient.Builder()
6668
.dockerHost(dockerClientConfig.dockerHost)
@@ -72,6 +74,33 @@ class LLMCodeExecutor(private val config: CodeExecutorConfig) {
7274
private val dockerClient = DockerClientImpl.getInstance(dockerClientConfig, httpClient)
7375

7476
fun execute(request: CodeExecutionRequest): CodeExecutionResponse {
77+
val pullImageCountDownLatch = CountDownLatch(1)
78+
dockerClient.pullImageCmd(config.containerImage)
79+
.exec(object : ResultCallback<PullResponseItem> {
80+
override fun close() {
81+
82+
}
83+
84+
override fun onStart(closeable: Closeable?) {
85+
86+
}
87+
88+
override fun onError(throwable: Throwable?) {
89+
logger.error("Failed to pull image", throwable)
90+
}
91+
92+
override fun onComplete() {
93+
pullImageCountDownLatch.countDown()
94+
}
95+
96+
override fun onNext(`object`: PullResponseItem?) {
97+
98+
}
99+
100+
})
101+
pullImageCountDownLatch.await(1, TimeUnit.MINUTES)
102+
logger.info("Image pulled successfully")
103+
75104
val cmd = dockerClient.createContainerCmd(config.containerImage)
76105
config.volumes?.let { volumes ->
77106
cmd.withVolumes(volumes.map { Volume(it) })

core/src/main/resources/logback.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<configuration>
2+
3+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4+
<layout class="ch.qos.logback.classic.PatternLayout">
5+
<Pattern>
6+
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
7+
</Pattern>
8+
</layout>
9+
</appender>
10+
11+
<root level="info">
12+
<appender-ref ref="CONSOLE"/>
13+
</root>
14+
15+
</configuration>

executors/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,6 @@
5959
<plugin>
6060
<artifactId>maven-failsafe-plugin</artifactId>
6161
</plugin>
62-
<plugin>
63-
<groupId>org.codehaus.mojo</groupId>
64-
<artifactId>exec-maven-plugin</artifactId>
65-
<configuration>
66-
<mainClass>MainKt</mainClass>
67-
</configuration>
68-
</plugin>
6962
</plugins>
7063
</build>
7164

0 commit comments

Comments
 (0)