pritidesai closed pull request #983: adding ruby runtime
URL: https://github.com/apache/incubator-openwhisk-wskdeploy/pull/983
 
 
   

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/parsers/manifest_parser.go b/parsers/manifest_parser.go
index 3223225e..ff2124bf 100644
--- a/parsers/manifest_parser.go
+++ b/parsers/manifest_parser.go
@@ -38,6 +38,7 @@ import (
        "github.com/apache/incubator-openwhisk-wskdeploy/wskenv"
        "github.com/apache/incubator-openwhisk-wskdeploy/wski18n"
        "github.com/apache/incubator-openwhisk-wskdeploy/wskprint"
+       "net/url"
 )
 
 const (
@@ -234,7 +235,8 @@ func (dm *YAMLParser) ComposeDependencies(pkg Package, 
projectPath string, fileP
                } else if dependencies.LocationIsGithub(location) {
 
                        // TODO() define const for the protocol prefix, etc.
-                       if !strings.HasPrefix(location, HTTPS) && 
!strings.HasPrefix(location, HTTP) {
+                       _, err := url.ParseRequestURI(location)
+                       if err != nil {
                                location = HTTPS + dependency.Location
                                location = 
wskenv.InterpolateStringWithEnvVar(location).(string)
                        }
diff --git a/runtimes/runtimes.go b/runtimes/runtimes.go
index 361c614d..5f2ef7fe 100644
--- a/runtimes/runtimes.go
+++ b/runtimes/runtimes.go
@@ -22,6 +22,7 @@ import (
        "encoding/json"
        "io/ioutil"
        "net/http"
+       "net/url"
        "strings"
        "time"
 
@@ -42,6 +43,13 @@ const (
        JAR_FILE_EXTENSION      = "jar"
        PHP_FILE_EXTENSION      = "php"
        ZIP_FILE_EXTENSION      = "zip"
+       RUBY_FILE_EXTENSION     = "rb"
+       NODEJS_RUNTIME          = "nodejs"
+       SWIFT_RUNTIME           = SWIFT_FILE_EXTENSION
+       PYTHON_RUNTIME          = "python"
+       JAVA_RUNTIME            = JAVA_FILE_EXTENSION
+       PHP_RUNTIME             = PHP_FILE_EXTENSION
+       RUBY_RUNTIME            = "ruby"
        HTTP_CONTENT_TYPE_KEY   = "Content-Type"
        HTTP_CONTENT_TYPE_VALUE = "application/json; charset=UTF-8"
        RUNTIME_NOT_SPECIFIED   = "NOT SPECIFIED"
@@ -58,11 +66,8 @@ type Limit struct {
 }
 
 type Runtime struct {
-       Image      string `json:"image"`
        Deprecated bool   `json:"deprecated"`
-       ReMain     bool   `json:"requireMain"`
        Default    bool   `json:"default"`
-       Attach     bool   `json:"attached"`
        Kind       string `json:"kind"`
 }
 
@@ -88,8 +93,12 @@ var FileRuntimeExtensionsMap map[string]string
 // `curl -k https://openwhisk.ng.bluemix.net`
 // hard coding it here in case of network unavailable or failure.
 func ParseOpenWhisk(apiHost string) (op OpenWhiskInfo, err error) {
-       url := HTTPS + apiHost
-       req, _ := http.NewRequest("GET", url, nil)
+       opURL := apiHost
+       _, err = url.ParseRequestURI(opURL)
+       if err != nil {
+               opURL = HTTPS + opURL
+       }
+       req, _ := http.NewRequest("GET", opURL, nil)
        req.Header.Set(HTTP_CONTENT_TYPE_KEY, HTTP_CONTENT_TYPE_VALUE)
        tlsConfig := &tls.Config{
                InsecureSkipVerify: true,
@@ -139,7 +148,7 @@ func ParseOpenWhisk(apiHost string) (op OpenWhiskInfo, err 
error) {
                b, _ := ioutil.ReadAll(res.Body)
                if b != nil && len(b) > 0 {
                        stdout := 
wski18n.T(wski18n.ID_MSG_UNMARSHAL_NETWORK_X_url_X,
-                               map[string]interface{}{"url": url})
+                               map[string]interface{}{"url": opURL})
                        wskprint.PrintOpenWhiskInfo(stdout)
                        err = json.Unmarshal(b, &op)
                        if err != nil {
@@ -182,17 +191,19 @@ func DefaultRuntimes(op OpenWhiskInfo) (rt 
map[string]string) {
 func FileExtensionRuntimes(op OpenWhiskInfo) (ext map[string]string) {
        ext = make(map[string]string)
        for k := range op.Runtimes {
-               if strings.Contains(k, NODEJS_FILE_EXTENSION) {
+               if strings.Contains(k, NODEJS_RUNTIME) {
                        ext[NODEJS_FILE_EXTENSION] = k
-               } else if strings.Contains(k, PYTHON_FILE_EXTENSION) {
+               } else if strings.Contains(k, PYTHON_RUNTIME) {
                        ext[PYTHON_FILE_EXTENSION] = k
-               } else if strings.Contains(k, SWIFT_FILE_EXTENSION) {
+               } else if strings.Contains(k, SWIFT_RUNTIME) {
                        ext[SWIFT_FILE_EXTENSION] = k
-               } else if strings.Contains(k, PHP_FILE_EXTENSION) {
+               } else if strings.Contains(k, PHP_RUNTIME) {
                        ext[PHP_FILE_EXTENSION] = k
-               } else if strings.Contains(k, JAVA_FILE_EXTENSION) {
+               } else if strings.Contains(k, JAVA_RUNTIME) {
                        ext[JAVA_FILE_EXTENSION] = k
                        ext[JAR_FILE_EXTENSION] = k
+               } else if strings.Contains(k, RUBY_RUNTIME) {
+                       ext[RUBY_FILE_EXTENSION] = k
                }
        }
        return
@@ -204,16 +215,18 @@ func FileRuntimeExtensions(op OpenWhiskInfo) (rte 
map[string]string) {
        for k, v := range op.Runtimes {
                for i := range v {
                        if !v[i].Deprecated {
-                               if strings.Contains(k, NODEJS_FILE_EXTENSION) {
+                               if strings.Contains(k, NODEJS_RUNTIME) {
                                        rte[v[i].Kind] = NODEJS_FILE_EXTENSION
-                               } else if strings.Contains(k, 
PYTHON_FILE_EXTENSION) {
+                               } else if strings.Contains(k, PYTHON_RUNTIME) {
                                        rte[v[i].Kind] = PYTHON_FILE_EXTENSION
-                               } else if strings.Contains(k, 
SWIFT_FILE_EXTENSION) {
+                               } else if strings.Contains(k, SWIFT_RUNTIME) {
                                        rte[v[i].Kind] = SWIFT_FILE_EXTENSION
-                               } else if strings.Contains(k, 
PHP_FILE_EXTENSION) {
+                               } else if strings.Contains(k, PHP_RUNTIME) {
                                        rte[v[i].Kind] = PHP_FILE_EXTENSION
-                               } else if strings.Contains(k, 
JAVA_FILE_EXTENSION) {
+                               } else if strings.Contains(k, JAVA_RUNTIME) {
                                        rte[v[i].Kind] = JAVA_FILE_EXTENSION
+                               } else if strings.Contains(k, RUBY_RUNTIME) {
+                                       rte[v[i].Kind] = RUBY_FILE_EXTENSION
                                }
                        }
                }
diff --git a/runtimes/runtimes.json b/runtimes/runtimes.json
index 857331ff..e9167595 100644
--- a/runtimes/runtimes.json
+++ b/runtimes/runtimes.json
@@ -10,122 +10,217 @@
     "runtimes": {
         "nodejs": [
             {
-                "image": "openwhisk/nodejsaction:latest",
+                "kind": "nodejs",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "nodejsaction",
+                    "tag": "latest"
+                },
                 "deprecated": true,
-                "requireMain": false,
-                "default": false,
-                "attached": false,
-                "kind": "nodejs"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             },
             {
-                "image": "openwhisk/nodejs6action:latest",
-                "deprecated": false,
-                "requireMain": false,
+                "kind": "nodejs:6",
                 "default": true,
-                "attached": false,
-                "kind": "nodejs:6"
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "nodejs6action",
+                    "tag": "latest"
+                },
+                "deprecated": false,
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                },
+                "stemCells": [{
+                    "count": 2,
+                    "memory": "256 MB"
+                }]
             },
             {
-                "image": "ibmfunctions/action-nodejs-v8:1.13.0",
-                "deprecated": false,
-                "requireMain": false,
+                "kind": "nodejs:8",
                 "default": false,
-                "attached": false,
-                "kind": "nodejs:8"
-            }
-        ],
-        "java": [
-            {
-                "image": "openwhisk/java8action:latest",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-nodejs-v8",
+                    "tag": "latest"
+                },
                 "deprecated": false,
-                "requireMain": true,
-                "default": true,
-                "attached": true,
-                "kind": "java"
-            }
-        ],
-        "php": [
-            {
-                "image": "openwhisk/action-php-v7.1:latest",
-                "deprecated": false,
-                "requireMain": false,
-                "default": true,
-                "attached": false,
-                "kind": "php:7.1"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             }
         ],
         "python": [
             {
-                "image": "openwhisk/python2action:latest",
+                "kind": "python",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "python2action",
+                    "tag": "latest"
+                },
                 "deprecated": false,
-                "requireMain": false,
-                "default": false,
-                "attached": false,
-                "kind": "python"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             },
             {
-                "image": "openwhisk/python2action:latest",
-                "deprecated": false,
-                "requireMain": false,
+                "kind": "python:2",
                 "default": true,
-                "attached": false,
-                "kind": "python:2"
-            },
-            {
-                "image": "openwhisk/python3action:latest",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "python2action",
+                    "tag": "latest"
+                },
                 "deprecated": false,
-                "requireMain": false,
-                "default": false,
-                "attached": false,
-                "kind": "python:3"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             },
             {
-                "image": "ibmfunctions/action-python-v3:1.6.0",
+                "kind": "python:3",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "python3action",
+                    "tag": "latest"
+                },
                 "deprecated": false,
-                "requireMain": false,
-                "default": false,
-                "attached": false,
-                "kind": "python-jessie:3"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             }
         ],
         "swift": [
             {
-                "image": "openwhisk/swiftaction:latest",
+                "kind": "swift",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "swiftaction",
+                    "tag": "latest"
+                },
                 "deprecated": true,
-                "requireMain": false,
-                "default": false,
-                "attached": false,
-                "kind": "swift"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             },
             {
-                "image": "openwhisk/swift3action:latest",
+                "kind": "swift:3",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "swift3action",
+                    "tag": "latest"
+                },
                 "deprecated": true,
-                "requireMain": false,
-                "default": false,
-                "attached": false,
-                "kind": "swift:3"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             },
             {
-                "image": "openwhisk/action-swift-v3.1.1:latest",
+                "kind": "swift:3.1.1",
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-swift-v3.1.1",
+                    "tag": "latest"
+                },
                 "deprecated": false,
-                "requireMain": false,
-                "default": true,
-                "attached": false,
-                "kind": "swift:3.1.1"
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
             },
             {
-                "image": "ibmfunctions/action-swift-v4.1:1.5.0",
+                "kind": "swift:4.1",
+                "default": true,
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-swift-v4.1",
+                    "tag": "latest"
+                },
                 "deprecated": false,
-                "requireMain": false,
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
+            }
+        ],
+        "java": [
+            {
+                "kind": "java",
+                "default": true,
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "java8action",
+                    "tag": "latest"
+                },
+                "deprecated": false,
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                },
+                "requireMain": true
+            }
+        ],
+        "php": [
+            {
+                "kind": "php:7.1",
                 "default": false,
-                "attached": false,
-                "kind": "swift:4.1"
+                "deprecated": false,
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-php-v7.1",
+                    "tag": "latest"
+                },
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
+            },
+            {
+                "kind": "php:7.2",
+                "default": true,
+                "deprecated": false,
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-php-v7.2",
+                    "tag": "latest"
+                },
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                }
+            }
+        ],
+        "ruby": [
+            {
+                "kind": "ruby:2.5",
+                "default": true,
+                "deprecated": false,
+                "attached": {
+                    "attachmentName": "codefile",
+                    "attachmentType": "text/plain"
+                },
+                "image": {
+                    "prefix": "openwhisk",
+                    "name": "action-ruby-v2.5",
+                    "tag": "latest"
+                }
             }
         ]
     },
-    "limits": {
-        "actions_per_minute": 5000,
-        "triggers_per_minute": 5000,
-        "concurrent_actions": 1000
-    }
-}
+    "blackboxes": [
+        {
+            "prefix": "openwhisk",
+            "name": "dockerskeleton",
+            "tag": "latest"
+        }
+    ]
+}
\ No newline at end of file
diff --git a/runtimes/runtimes_test.go b/runtimes/runtimes_test.go
index f7650e3c..f966e112 100644
--- a/runtimes/runtimes_test.go
+++ b/runtimes/runtimes_test.go
@@ -28,7 +28,7 @@ func TestParseOpenWhisk(t *testing.T) {
        assert.Equal(t, nil, err, "parse openwhisk info error happened.")
        converted := ConvertToMap(openwhisk)
        assert.Equal(t, 2, len(converted["nodejs"]), "not expected length")
-       assert.Equal(t, 1, len(converted["php"]), "not expected length")
+       assert.Equal(t, 2, len(converted["php"]), "not expected length")
        assert.Equal(t, 1, len(converted["java"]), "not expected length")
        assert.Equal(t, 4, len(converted["python"]), "not expected length")
        assert.Equal(t, 2, len(converted["swift"]), "not expected length")
diff --git a/tests/src/integration/helloworld/actions/hello.rb 
b/tests/src/integration/helloworld/actions/hello.rb
new file mode 100644
index 00000000..77a0609c
--- /dev/null
+++ b/tests/src/integration/helloworld/actions/hello.rb
@@ -0,0 +1,9 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+# license agreements; and to You under the Apache License, Version 2.0.
+
+def main(args)
+  name = args["name"] || "stranger"
+  greeting = "Hello #{name}!"
+  puts greeting
+  { "greeting" => greeting }
+end
diff --git a/tests/src/integration/helloworld/manifest.yaml 
b/tests/src/integration/helloworld/manifest.yaml
index e29a64be..9179be05 100644
--- a/tests/src/integration/helloworld/manifest.yaml
+++ b/tests/src/integration/helloworld/manifest.yaml
@@ -139,10 +139,21 @@ packages:
             payload:
               type: string
               description: a simple greeting message, Hello stranger!
+        helloRuby:
+          function: actions/hello.rb
+        helloRubyWithCode:
+          code: |
+                def main(args)
+                  name = args["name"] || "stranger"
+                  greeting = "Hello #{name}!"
+                  puts greeting
+                  { "greeting" => greeting }
+                end
+          runtime: ruby:2.5
       sequences:
         # sequence of helloworld in all four runtimes
         hello-world-series:
-          actions: helloNodejs, helloNodejsWithCode, helloJava, helloPython, 
helloPythonWithCode, helloSwift, helloSwiftWithCode
+          actions: helloNodejs, helloNodejsWithCode, helloJava, helloPython, 
helloPythonWithCode, helloSwift, helloSwiftWithCode, helloRuby, 
helloRubyWithCode
       triggers:
         # trigger to activate helloworld sequence
         triggerHelloworld:
diff --git a/wski18n/i18n_resources.go b/wski18n/i18n_resources.go
index 2a1c6432..e397a0b0 100644
--- a/wski18n/i18n_resources.go
+++ b/wski18n/i18n_resources.go
@@ -329,14 +329,14 @@ func AssetNames() []string {
 
 // _bindata is a table, holding each asset generator, mapped to its name.
 var _bindata = map[string]func() (*asset, error){
-       "wski18n/resources/de_DE.all.json": wski18nResourcesDe_deAllJson,
-       "wski18n/resources/en_US.all.json": wski18nResourcesEn_usAllJson,
-       "wski18n/resources/es_ES.all.json": wski18nResourcesEs_esAllJson,
-       "wski18n/resources/fr_FR.all.json": wski18nResourcesFr_frAllJson,
-       "wski18n/resources/it_IT.all.json": wski18nResourcesIt_itAllJson,
-       "wski18n/resources/ja_JA.all.json": wski18nResourcesJa_jaAllJson,
-       "wski18n/resources/ko_KR.all.json": wski18nResourcesKo_krAllJson,
-       "wski18n/resources/pt_BR.all.json": wski18nResourcesPt_brAllJson,
+       "wski18n/resources/de_DE.all.json":   wski18nResourcesDe_deAllJson,
+       "wski18n/resources/en_US.all.json":   wski18nResourcesEn_usAllJson,
+       "wski18n/resources/es_ES.all.json":   wski18nResourcesEs_esAllJson,
+       "wski18n/resources/fr_FR.all.json":   wski18nResourcesFr_frAllJson,
+       "wski18n/resources/it_IT.all.json":   wski18nResourcesIt_itAllJson,
+       "wski18n/resources/ja_JA.all.json":   wski18nResourcesJa_jaAllJson,
+       "wski18n/resources/ko_KR.all.json":   wski18nResourcesKo_krAllJson,
+       "wski18n/resources/pt_BR.all.json":   wski18nResourcesPt_brAllJson,
        "wski18n/resources/zh_Hans.all.json": wski18nResourcesZh_hansAllJson,
        "wski18n/resources/zh_Hant.all.json": wski18nResourcesZh_hantAllJson,
 }
@@ -380,17 +380,18 @@ type bintree struct {
        Func     func() (*asset, error)
        Children map[string]*bintree
 }
+
 var _bintree = &bintree{nil, map[string]*bintree{
        "wski18n": &bintree{nil, map[string]*bintree{
                "resources": &bintree{nil, map[string]*bintree{
-                       "de_DE.all.json": 
&bintree{wski18nResourcesDe_deAllJson, map[string]*bintree{}},
-                       "en_US.all.json": 
&bintree{wski18nResourcesEn_usAllJson, map[string]*bintree{}},
-                       "es_ES.all.json": 
&bintree{wski18nResourcesEs_esAllJson, map[string]*bintree{}},
-                       "fr_FR.all.json": 
&bintree{wski18nResourcesFr_frAllJson, map[string]*bintree{}},
-                       "it_IT.all.json": 
&bintree{wski18nResourcesIt_itAllJson, map[string]*bintree{}},
-                       "ja_JA.all.json": 
&bintree{wski18nResourcesJa_jaAllJson, map[string]*bintree{}},
-                       "ko_KR.all.json": 
&bintree{wski18nResourcesKo_krAllJson, map[string]*bintree{}},
-                       "pt_BR.all.json": 
&bintree{wski18nResourcesPt_brAllJson, map[string]*bintree{}},
+                       "de_DE.all.json":   
&bintree{wski18nResourcesDe_deAllJson, map[string]*bintree{}},
+                       "en_US.all.json":   
&bintree{wski18nResourcesEn_usAllJson, map[string]*bintree{}},
+                       "es_ES.all.json":   
&bintree{wski18nResourcesEs_esAllJson, map[string]*bintree{}},
+                       "fr_FR.all.json":   
&bintree{wski18nResourcesFr_frAllJson, map[string]*bintree{}},
+                       "it_IT.all.json":   
&bintree{wski18nResourcesIt_itAllJson, map[string]*bintree{}},
+                       "ja_JA.all.json":   
&bintree{wski18nResourcesJa_jaAllJson, map[string]*bintree{}},
+                       "ko_KR.all.json":   
&bintree{wski18nResourcesKo_krAllJson, map[string]*bintree{}},
+                       "pt_BR.all.json":   
&bintree{wski18nResourcesPt_brAllJson, map[string]*bintree{}},
                        "zh_Hans.all.json": 
&bintree{wski18nResourcesZh_hansAllJson, map[string]*bintree{}},
                        "zh_Hant.all.json": 
&bintree{wski18nResourcesZh_hantAllJson, map[string]*bintree{}},
                }},
@@ -443,4 +444,3 @@ func _filePath(dir, name string) string {
        cannonicalName := strings.Replace(name, "\\", "/", -1)
        return filepath.Join(append([]string{dir}, 
strings.Split(cannonicalName, "/")...)...)
 }
-


 

----------------------------------------------------------------
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