Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ class DockerClient(dockerHost: Option[String] = None)(executionContext: Executio
runCmd("pull", image).map(_ => ()).andThen { case _ => pullsInFlight.remove(image) }
})

def imagePresent(image: String)(implicit transid: TransactionId): Future[String] = {
// --format only added to keep the output minimal
val cmd = dockerCmd ++ Seq("inspect", "--format={{.Config.Image}}", image)
executeProcess(cmd: _*)
}

def isOomKilled(id: ContainerId)(implicit transid: TransactionId): Future[Boolean] =
runCmd("inspect", id.asString, "--format", "{{.State.OOMKilled}}").map(_.toBoolean)

Expand Down Expand Up @@ -181,6 +187,14 @@ trait DockerApi {
*/
def pull(image: String)(implicit transid: TransactionId): Future[Unit]

/**
* Checks if image is present locally.
*
* @param image the image to check
* @return a Future completing successful wif the image is present locally, or failing if not
*/
def imagePresent(image: String)(implicit transid: TransactionId): Future[String]

/**
* Determines whether the given container was killed due to
* memory constraints.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ object DockerContainer {
params
val pulled = if (userProvidedImage) {
docker.pull(image).recoverWith {
case _ => Future.failed(BlackboxStartupError(s"Failed to pull container image '${image}'."))
case _ =>
// check if image exists locally and reuse that one
docker.imagePresent(image).recoverWith {
case _ => Future.failed(BlackboxStartupError(s"Failed to pull container image '${image}'."))
}
}
} else Future.successful(())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ class DockerContainerTests
Future.successful(())
}

def imagePresent(image: String)(implicit transid: TransactionId): Future[String] = {
Future.failed(new Exception())
}

override def isOomKilled(id: ContainerId)(implicit transid: TransactionId): Future[Boolean] = ???

def rawContainerLogs(containerId: ContainerId, fromPos: Long): Future[ByteBuffer] = {
Expand Down