From 0e28e7cca832c2c7321c25645924f18eeed10fc9 Mon Sep 17 00:00:00 2001 From: Kei Date: Tue, 5 Jun 2018 22:01:55 +0900 Subject: [PATCH 1/2] Add Ruby2.5 runtime to runtimes manifest --- ansible/files/runtimes.json | 12 +++ .../src/main/resources/apiv1swagger.json | 10 ++- docs/actions-ruby.md | 87 +++++++++++++++++++ docs/actions.md | 1 + docs/parameters.md | 3 +- 5 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 docs/actions-ruby.md diff --git a/ansible/files/runtimes.json b/ansible/files/runtimes.json index 03f8096d8ac..d770b38d879 100644 --- a/ansible/files/runtimes.json +++ b/ansible/files/runtimes.json @@ -142,6 +142,18 @@ "tag": "latest" } } + ], + "ruby": [ + { + "kind": "ruby:2.5", + "default": true, + "deprecated": false, + "image": { + "prefix": "remore", + "name": "openwhisk-runtime-ruby", + "tag": "latest" + } + } ] }, "blackboxes": [ diff --git a/core/controller/src/main/resources/apiv1swagger.json b/core/controller/src/main/resources/apiv1swagger.json index bc07b96e57d..80eefbbfd19 100644 --- a/core/controller/src/main/resources/apiv1swagger.json +++ b/core/controller/src/main/resources/apiv1swagger.json @@ -1495,15 +1495,17 @@ "kind": { "type": "string", "enum": [ + "blackbox", + "java", "nodejs:6", "nodejs:8", - "python:2", - "python:3", "php:7.1", "php:7.2", + "python:2", + "python:3", + "ruby:2.5", "swift:3.1.1", - "java", - "blackbox" + "swift:4.1" ], "description": "the type of action" }, diff --git a/docs/actions-ruby.md b/docs/actions-ruby.md new file mode 100644 index 00000000000..540592a723f --- /dev/null +++ b/docs/actions-ruby.md @@ -0,0 +1,87 @@ + + +## Creating and invoking Ruby actions + +The process of creating Ruby actions is similar to that of [other actions](actions.md#the-basics). +The following sections guide you through creating and invoking a single Ruby action, +and demonstrate how to bundle multiple Ruby files and third party dependencies. + +Ruby actions are executed using Ruby 2.5. To use this runtime, specify the `wsk` CLI parameter +`--kind ruby:2.5` when creating or updating an action. This is the default when creating an action +with file that has a `.rb` extension. + +An action is simply a top-level Ruby method. For example, create a file called `hello.rb` +with the following source code: + +```ruby +def main(args) + name = args["name"] || "stranger" + greeting = "Hello #{name}!" + print greeting + { "greeting" => greeting } +end +``` + +Ruby actions always consume a Hash and return a Hash. +The entry method for the action is `main` by default but may be specified explicitly +when creating the action with the `wsk` CLI using `--main`, as with any other action type. + +You can create an OpenWhisk action called `hello_ruby` from this function as follows: + +``` +wsk action create hello_ruby hello.rb +``` + +The CLI automatically infers the type of the action from the source file extension. +For `.rb` source files, the action runs using a Ruby 2.5 runtime. + +Action invocation is the same for Ruby actions as it is for [any other action](actions.md#the-basics). + +``` +wsk action invoke --result hello_ruby --param name World +``` + +```json +{ + "greeting": "Hello World!" +} +``` + +Find out more about parameters in the [Working with parameters](./parameters.md) section. + +## Packaging Ruby actions in zip files + +You can package a Ruby action along with other files and dependent packages in a zip file. +The filename of the source file containing the entry point (e.g., `main`) must be `main.rb`. +For example, to create an action that includes a second file called `helper.rb`, +first create an archive containing your source files: + +```bash +zip -r hello_ruby.zip main.rb helper.rb +``` + +and then create the action: + +```bash +wsk action create hello_ruby --kind ruby:2.5 hello_ruby.zip +``` + +A few Ruby gems such as `mechanize` and `jwt` are available in addition to the default and bundled gems. +You can use arbitrary gems so long as you use zipped actions to package all the dependencies. diff --git a/docs/actions.md b/docs/actions.md index 8f69813e5d8..9954911cdd7 100644 --- a/docs/actions.md +++ b/docs/actions.md @@ -58,6 +58,7 @@ paths more suitable. Or, you can [create a new runtime](actions-new.md). * [JavaScript](actions-node.md) * [PHP](actions-php.md) * [Python](actions-python.md) +* [Ruby](actions-ruby.md) * [Swift](actions-swift.md) * [Docker and native binaries](actions-docker.md) diff --git a/docs/parameters.md b/docs/parameters.md index 03d3a3f51b5..19945b4e396 100644 --- a/docs/parameters.md +++ b/docs/parameters.md @@ -25,7 +25,8 @@ This page outlines how to configure parameters when deploying packages and actio ### Passing parameters to an action at invoke time -Parameters can be passed to the action when it is invoked. These examples use JavaScript but all the other languages work the same way (see documentation on [Swift actions](./actions.md#creating-swift-actions), [Python actions](./actions.mdcreating-python-actions), [Java actions](./actions.mdcreating-java-actions), [PHP actions](./actions.mdcreating-php-actions), [Docker actions](./actions.mdcreating-docker-actions) or [Go actions](./actions.mdcreating-go-actions) as appropriate for more detailed examples). +Parameters can be passed to the action when it is invoked. These examples use JavaScript but all [the other +languages](actions.md#languages-and-runtimes) work the same way. 1. Use parameters in the action. For example, create 'hello.js' file with the following content: From 95a44146a3276c607bf431c4c640eb0611b5315d Mon Sep 17 00:00:00 2001 From: Rodric Rabbah Date: Sun, 29 Jul 2018 10:11:39 -0400 Subject: [PATCH 2/2] Add system test and update image name. --- ansible/files/runtimes.json | 4 ++-- tests/dat/actions/unicode.tests/ruby-2.5.txt | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 tests/dat/actions/unicode.tests/ruby-2.5.txt diff --git a/ansible/files/runtimes.json b/ansible/files/runtimes.json index d770b38d879..4efd81468e2 100644 --- a/ansible/files/runtimes.json +++ b/ansible/files/runtimes.json @@ -149,8 +149,8 @@ "default": true, "deprecated": false, "image": { - "prefix": "remore", - "name": "openwhisk-runtime-ruby", + "prefix": "openwhisk", + "name": "action-ruby-v2.5", "tag": "latest" } } diff --git a/tests/dat/actions/unicode.tests/ruby-2.5.txt b/tests/dat/actions/unicode.tests/ruby-2.5.txt new file mode 100644 index 00000000000..0326ab00f3b --- /dev/null +++ b/tests/dat/actions/unicode.tests/ruby-2.5.txt @@ -0,0 +1,8 @@ +# 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) + str = args["delimiter"] + " ☃ " + args["delimiter"] + puts str + { "winter" => str } +end