Skip to content

Commit 708bf72

Browse files
author
lihe.ma
committed
[Improve] Use local docker image cache when build (#4193)
1 parent cbea401 commit 708bf72

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

streampark-flink/streampark-flink-packer/src/main/scala/org/apache/streampark/flink/packer/pipeline/impl/FlinkK8sApplicationBuildPipeline.scala

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.streampark.flink.packer.pipeline.impl
1919

20+
import com.github.dockerjava.api.DockerClient
2021
import org.apache.streampark.common.fs.LfsOperator
2122
import org.apache.streampark.common.util.ThreadUtils
2223
import org.apache.streampark.flink.kubernetes.PodTemplateTool
@@ -34,6 +35,7 @@ import org.apache.commons.lang3.StringUtils
3435
import java.io.File
3536
import java.util.concurrent.{LinkedBlockingQueue, ThreadPoolExecutor, TimeUnit}
3637

38+
import org.apache.streampark.common.util.Implicits._
3739
import scala.concurrent.{ExecutionContext, Future}
3840

3941
/** Building pipeline for flink kubernetes-native application mode */
@@ -139,29 +141,34 @@ class FlinkK8sApplicationBuildPipeline(request: FlinkK8sApplicationBuildRequest)
139141
execStep(5) {
140142
usingDockerClient {
141143
dockerClient =>
142-
val pullImageCmd = {
143-
// when the register address prefix is explicitly identified on base image tag,
144-
// the user's pre-saved docker register auth info would be used.
145-
val pullImageCmdState =
146-
dockerConf.registerAddress != null && !baseImageTag.startsWith(
147-
dockerConf.registerAddress)
148-
if (pullImageCmdState) {
149-
dockerClient.pullImageCmd(baseImageTag)
150-
} else {
151-
dockerClient
152-
.pullImageCmd(baseImageTag)
153-
.withAuthConfig(dockerConf.toAuthConf)
144+
val imgExists = dockerClient.listImagesCmd().exec().exists(_.getRepoTags.exists(_.contains(baseImageTag)))
145+
if (imgExists) {
146+
logInfo(s"found local docker image $baseImageTag, no need to pull from remote.")
147+
} else {
148+
val pullImageCmd = {
149+
// when the register address prefix is explicitly identified on base image tag,
150+
// the user's pre-saved docker register auth info would be used.
151+
val pullImageCmdState =
152+
dockerConf.registerAddress != null && !baseImageTag.startsWith(
153+
dockerConf.registerAddress)
154+
if (pullImageCmdState) {
155+
dockerClient.pullImageCmd(baseImageTag)
156+
} else {
157+
dockerClient
158+
.pullImageCmd(baseImageTag)
159+
.withAuthConfig(dockerConf.toAuthConf)
160+
}
154161
}
162+
val pullCmdCallback = pullImageCmd
163+
.asInstanceOf[HackPullImageCmd]
164+
.start(watchDockerPullProcess {
165+
pullRsp =>
166+
dockerProcess.pull.update(pullRsp)
167+
Future(dockerProcessWatcher.onDockerPullProgressChange(dockerProcess.pull.snapshot))
168+
})
169+
pullCmdCallback.awaitCompletion
170+
logInfo(s"Already pulled docker image from remote register, imageTag=$baseImageTag")
155171
}
156-
val pullCmdCallback = pullImageCmd
157-
.asInstanceOf[HackPullImageCmd]
158-
.start(watchDockerPullProcess {
159-
pullRsp =>
160-
dockerProcess.pull.update(pullRsp)
161-
Future(dockerProcessWatcher.onDockerPullProgressChange(dockerProcess.pull.snapshot))
162-
})
163-
pullCmdCallback.awaitCompletion
164-
logInfo(s"Already pulled docker image from remote register, imageTag=$baseImageTag")
165172
}(err => throw new Exception(s"Pull docker image failed, imageTag=$baseImageTag", err))
166173
}.getOrElse(throw getError.exception)
167174

0 commit comments

Comments
 (0)