You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2017/12/13 16:06:27 UTC

[GitHub] rabbah closed pull request #2852: invoker: use locally available image if docker pull fails

rabbah closed pull request #2852: invoker: use locally available image if docker pull fails
URL: https://github.com/apache/incubator-openwhisk/pull/2852
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClient.scala b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClient.scala
index d714a9fbaa..e4d3f6f741 100644
--- a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClient.scala
+++ b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerClient.scala
@@ -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)
 
@@ -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.
diff --git a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
index 89960e36e4..a0a0083e9a 100644
--- a/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
+++ b/core/invoker/src/main/scala/whisk/core/containerpool/docker/DockerContainer.scala
@@ -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(())
 
diff --git a/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala b/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala
index 960ab9262c..44019961e1 100644
--- a/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala
+++ b/tests/src/test/scala/whisk/core/containerpool/docker/test/DockerContainerTests.scala
@@ -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] = {


 

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


With regards,
Apache Git Services