Skip to content

Commit

Permalink
Add ruby support (#916)
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo authored and tj committed Dec 13, 2018
1 parent 2d55de7 commit ff99a6d
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*.zip
.DS_Store
examples/go/main
_examples/ruby/functions/dependency/.bundle/
_examples/ruby/functions/dependency/Gemfile.lock
cov.out
node_modules
vendor/
Expand Down
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Currently supports:
- Node.js
- Golang
- Python
- Ruby
- Java
- Rust
- Clojure
Expand Down
14 changes: 14 additions & 0 deletions _examples/ruby/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

To run the example first setup your [AWS Credentials](http://apex.run/#aws-credentials), and ensure "role" in ./project.json is set to your Lambda function ARN.

Deploy the functions:

```
$ apex deploy
```

Try it out:

```
$ apex invoke simple < event.json
```
3 changes: 3 additions & 0 deletions _examples/ruby/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "world"
}
2 changes: 2 additions & 0 deletions _examples/ruby/functions/dependency/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source 'https://rubygems.org'
gem 'activesupport'
10 changes: 10 additions & 0 deletions _examples/ruby/functions/dependency/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
The build hook can be used to install required libraries using bundle. You need to install these libraries at function level so that they become part of the zip files.

The requirements are mentioned in the Gemfile and the build hook is used to install the dependencies before the build

```
"hooks":{
"build": "bundle install && bundle install --deployment"
}
```

6 changes: 6 additions & 0 deletions _examples/ruby/functions/dependency/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"description": "Example with ruby dependency on an external package",
"hooks":{
"build": "bundle install && bundle install --deployment"
}
}
7 changes: 7 additions & 0 deletions _examples/ruby/functions/dependency/lambda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
puts "start dependency function"

require 'active_support/core_ext/object/blank'

def handler(event:, context:)
puts "event.blank?: #{event.blank?}"
end
5 changes: 5 additions & 0 deletions _examples/ruby/functions/simple/lambda.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
puts "start simple function"

def handler(event:, context:)
puts "processing event: #{event}"
end
5 changes: 5 additions & 0 deletions _examples/ruby/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "ruby",
"description": "Ruby example project",
"role": "arn:aws:iam::293503197324:role/apex_lambda_function"
}
1 change: 1 addition & 0 deletions cmd/apex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
_ "github.com/apex/apex/plugins/java"
_ "github.com/apex/apex/plugins/nodejs"
_ "github.com/apex/apex/plugins/python"
_ "github.com/apex/apex/plugins/ruby"
_ "github.com/apex/apex/plugins/rust_gnu"
_ "github.com/apex/apex/plugins/rust_musl"
_ "github.com/apex/apex/plugins/shim"
Expand Down
1 change: 1 addition & 0 deletions docs/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Runtimes supported:
- __java__ (Java 8)
- __python2.7__ (Python 2.7)
- __python3.6__ (Python 3.6)
- __ruby2.5__ (Ruby 2.5)
- __nodejs4.3__ (Node.js 4.3)
- __nodejs4.3-edge__ (Node.js 4.3 Edge)
- __nodejs6.10__ (Node.js 6.10)
Expand Down
1 change: 1 addition & 0 deletions function/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var defaultPlugins = []string{
"rust-gnu",
"golang",
"python",
"ruby",
"nodejs",
"java",
"clojure",
Expand Down
1 change: 1 addition & 0 deletions function/function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
_ "github.com/apex/apex/plugins/inference"
_ "github.com/apex/apex/plugins/nodejs"
_ "github.com/apex/apex/plugins/python"
_ "github.com/apex/apex/plugins/ruby"
_ "github.com/apex/apex/plugins/shim"

"github.com/apex/log"
Expand Down
2 changes: 2 additions & 0 deletions plugins/inference/inference.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/apex/apex/plugins/java"
"github.com/apex/apex/plugins/nodejs"
"github.com/apex/apex/plugins/python"
"github.com/apex/apex/plugins/ruby"
)

func init() {
Expand All @@ -20,6 +21,7 @@ func init() {
"main.go": golang.Runtime,
"target/apex.jar": java.Runtime,
"build/libs/apex.jar": java.Runtime,
"lambda.rb": ruby.Runtime,
},
})
}
Expand Down
37 changes: 37 additions & 0 deletions plugins/ruby/ruby.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Package ruby implements the "ruby" runtime.
package ruby

import (
"strings"

"github.com/apex/apex/function"
)

const (
// Runtime for inference.
Runtime = "ruby2.5"
)

func init() {
function.RegisterPlugin("ruby", &Plugin{})
}

// Plugin implementation.
type Plugin struct{}

// Open adds ruby defaults.
func (p *Plugin) Open(fn *function.Function) error {
if !strings.HasPrefix(fn.Runtime, "ruby") {
return nil
}

if fn.Runtime == "ruby" {
fn.Runtime = Runtime
}

if fn.Handler == "" {
fn.Handler = "lambda.handler"
}

return nil
}

0 comments on commit ff99a6d

Please # to comment.