1717
1818package whisk .core .entity
1919
20- import scala .util .{Failure , Success , Try }
20+ import scala .util .{Failure , Try }
2121import spray .json ._
2222import spray .json .DefaultJsonProtocol ._
2323import whisk .core .WhiskConfig
@@ -41,15 +41,13 @@ protected[core] object ExecManifest {
4141 * singleton Runtime instance.
4242 *
4343 * @param config a valid configuration
44- * @param reinit re-initialize singleton iff true
45- * @return the manifest if initialized successfully, or if previously initialized
44+ * @param localDockerImagePrefix optional local docker prefix, permitting images matching prefix to bypass docker pull
45+ * @return the manifest if initialized successfully, or an failure
4646 */
47- protected [core] def initialize (config : WhiskConfig , reinit : Boolean = false ): Try [Runtimes ] = {
48- if (manifest.isEmpty || reinit) {
49- val mf = Try (config.runtimesManifest.parseJson.asJsObject).flatMap(runtimes(_))
50- mf.foreach(m => manifest = Some (m))
51- mf
52- } else Success (manifest.get)
47+ protected [core] def initialize (config : WhiskConfig , localDockerImagePrefix : Option [String ] = None ): Try [Runtimes ] = {
48+ val mf = Try (config.runtimesManifest.parseJson.asJsObject).flatMap(runtimes(_, localDockerImagePrefix))
49+ mf.foreach(m => manifest = Some (m))
50+ mf
5351 }
5452
5553 /**
@@ -71,26 +69,34 @@ protected[core] object ExecManifest {
7169 * @param config a configuration object as JSON
7270 * @return Runtimes instance
7371 */
74- protected [entity] def runtimes (config : JsObject ): Try [Runtimes ] = Try {
72+ protected [entity] def runtimes (config : JsObject , localDockerImagePrefix : Option [ String ] = None ): Try [Runtimes ] = Try {
7573 val prefix = config.fields.get(" defaultImagePrefix" ).map(_.convertTo[String ])
7674 val tag = config.fields.get(" defaultImageTag" ).map(_.convertTo[String ])
77- val runtimes = config
78- .fields( " runtimes " )
79- .convertTo[ Map [ String , Set [ RuntimeManifest ]]]
80- .map {
75+
76+ val runtimes = config .fields
77+ .get( " runtimes " )
78+ .map(_.convertTo[ Map [ String , Set [ RuntimeManifest ]]].map {
8179 case (name, versions) =>
8280 RuntimeFamily (name, versions.map { mf =>
8381 val img = ImageName (mf.image.name, mf.image.prefix.orElse(prefix), mf.image.tag.orElse(tag))
8482 mf.copy(image = img)
8583 })
86- }
87- .toSet
84+ }.toSet)
85+
8886 val blackbox = config.fields
8987 .get(" blackboxes" )
9088 .map(_.convertTo[Set [ImageName ]].map { image =>
9189 ImageName (image.name, image.prefix.orElse(prefix), image.tag.orElse(tag))
9290 })
93- Runtimes (runtimes, blackbox.getOrElse(Set .empty))
91+
92+ val bypassPullForLocalImages = config.fields
93+ .get(" bypassPullForLocalImages" )
94+ .map(_.convertTo[Boolean ])
95+ .filter(identity)
96+ .flatMap(_ => localDockerImagePrefix)
97+ .map(_.trim)
98+
99+ Runtimes (runtimes.getOrElse(Set .empty), blackbox.getOrElse(Set .empty), bypassPullForLocalImages)
94100 }
95101
96102 /**
@@ -215,10 +221,17 @@ protected[core] object ExecManifest {
215221 *
216222 * @param set of supported runtime families
217223 */
218- protected [core] case class Runtimes (runtimes : Set [RuntimeFamily ], blackboxImages : Set [ImageName ]) {
224+ protected [core] case class Runtimes (runtimes : Set [RuntimeFamily ],
225+ blackboxImages : Set [ImageName ],
226+ bypassPullForLocalImages : Option [String ]) {
219227
220228 val knownContainerRuntimes : Set [String ] = runtimes.flatMap(_.versions.map(_.kind))
221229
230+ def skipDockerPull (image : ImageName ): Boolean = {
231+ blackboxImages.contains(image) ||
232+ image.prefix.flatMap(p => bypassPullForLocalImages.map(_ == p)).getOrElse(false )
233+ }
234+
222235 def toJson : JsObject = {
223236 runtimes
224237 .map { family =>
0 commit comments