-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Ruby2.5 runtime support #3725
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<!-- | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
--> | ||
|
||
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with #3680, the image prefix and tag should be specified explicitly (to
openwhisk
andlatest
respectively).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made a change as a result of #3680
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
prefix
andname
temporarily to workaround the build failure. (thank you @rabbah for the quick advice to fix this)