chetanmeh commented on a change in pull request #3887: Implement full 
specification of docker image names.
URL: 
https://github.com/apache/incubator-openwhisk/pull/3887#discussion_r204214422
 
 

 ##########
 File path: common/scala/src/main/scala/whisk/core/entity/ExecManifest.scala
 ##########
 @@ -185,36 +186,72 @@ protected[core] object ExecManifest {
 
   protected[core] object ImageName {
     private val defaultImageTag = "latest"
-    private val componentRegex = """([a-z0-9._-]+)""".r
-    private val tagRegex = """([\w.-]{0,128})""".r
+
+    // docker image name grammar, taken from: 
https://github.com/docker/distribution/blob/master/reference/reference.go
+    //
+    // Grammar
+    //
+    // reference                       := name [ ":" tag ] [ "@" digest ]
+    // name                            := [domain '/'] path-component ['/' 
path-component]*
+    // domain                          := domain-component ['.' 
domain-component]* [':' port-number]
+    // domain-component                := 
/([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])/
+    // port-number                     := /[0-9]+/
+    // path-component                  := alpha-numeric [separator 
alpha-numeric]*
+    // alpha-numeric                   := /[a-z0-9]+/
+    // separator                       := /[_.]|__|[-]*/
+    //
+    // tag                             := /[\w][\w.-]{0,127}/
+    //
+    // digest                          := digest-algorithm ":" digest-hex
+    // digest-algorithm                := digest-algorithm-component [ 
digest-algorithm-separator digest-algorithm-component ]*
+    // digest-algorithm-separator      := /[+.-_]/
+    // digest-algorithm-component      := /[A-Za-z][A-Za-z0-9]*/
+    // digest-hex                      := /[0-9a-fA-F]{32,}/ ; At least 128 
bit digest value
+    private val lowercaseLetters = P(CharIn('a' to 'z'))
+    private val uppercaseLetters = P(CharIn('A' to 'Z'))
+    private val letters = P(lowercaseLetters | uppercaseLetters)
+    private val digits = P(CharIn('0' to '9'))
+
+    private val alphaNumeric = P(lowercaseLetters | digits)
+    private val alphaNumericWithUpper = P(letters | digits)
+    private val word = P(alphaNumericWithUpper | "_")
+
+    private val digestHex = P(digits | CharIn(('a' to 'f') ++ ('A' to 
'F'))).rep(min = 32)
+    private val digestAlgorithmComponent = P(letters ~ 
alphaNumericWithUpper.rep)
+    private val digestAlgorithmSeperator = P("+" | "." | "-" | "_")
+    private val digestAlgorithm = P(digestAlgorithmComponent.rep(min = 1, sep 
= digestAlgorithmSeperator))
+    private val digest = P(digestAlgorithm ~ ":" ~ digestHex)
+
+    private val tag = P(word ~ (word | "." | "-").rep(max = 127))
+
+    private val separator = P("_" | "." | "__" | "-".rep)
+    private val pathComponent = P(alphaNumeric.rep(min = 1, sep = separator))
+    private val portNumber = P(digits.rep(min = 1))
+    // FIXME: this is not correct yet. It accepts "-" as the beginning and end 
of a domain
+    private val domainComponent = P(alphaNumericWithUpper | "-").rep
+    private val domain = P(domainComponent.rep(min = 1, sep = ".") ~ (":" ~ 
portNumber).?)
+    private val name = P((domain.! ~ "/").? ~ pathComponent.!.rep(min = 1, sep 
= "/"))
+
+    private val reference = P(Start ~ name ~ (":" ~ tag.!).? ~ ("@" ~ 
digest.!).? ~ End)
 
 Review comment:
   Thanks to this PR today I learned about [Fastparse][1] and [sourcecode][2]. 
Neat and Precise solution ... and very close to [actual implementation][3] but 
type safe extraction!
   
   [1]: http://www.lihaoyi.com/fastparse/
   [2]: https://github.com/lihaoyi/sourcecode
   [3]: https://github.com/docker/distribution/blob/master/reference/regexp.go

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to