mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
more tutorial
This commit is contained in:
5
examples/tutorial/hello/ruby/.gitignore
vendored
Normal file
5
examples/tutorial/hello/ruby/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
bundle/
|
||||
.bundle/
|
||||
func.yaml
|
||||
Dockerfile
|
||||
Gemfile.lock
|
||||
4
examples/tutorial/hello/ruby/Gemfile
Normal file
4
examples/tutorial/hello/ruby/Gemfile
Normal file
@@ -0,0 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'httparty', '~> 0.14.0'
|
||||
gem 'json', '> 1.8.2'
|
||||
44
examples/tutorial/hello/ruby/README.md
Normal file
44
examples/tutorial/hello/ruby/README.md
Normal file
@@ -0,0 +1,44 @@
|
||||
## Quick Example for a Ruby Function (4 minutes)
|
||||
|
||||
This example will show you how to test and deploy a Ruby function to Oracle Functions.
|
||||
|
||||
```sh
|
||||
# create your func.yaml file
|
||||
fn init <YOUR_DOCKERHUB_USERNAME>/hello
|
||||
# install dependencies, we need the json gem to run this
|
||||
docker run --rm -it -v ${pwd}:/worker -w /worker funcy/ruby:dev bundle install --standalone --clean
|
||||
# build the function
|
||||
fn build
|
||||
# test it
|
||||
cat hello.payload.json | fn run
|
||||
# push it to Docker Hub
|
||||
fn push
|
||||
# Create a route to this function on Oracle Functions
|
||||
fn routes create myapp /hello
|
||||
```
|
||||
|
||||
Now surf to: http://localhost:8080/r/myapp/hello
|
||||
|
||||
## Dependencies
|
||||
|
||||
Create a [Gemfile](http://bundler.io/gemfile.html) file in your function directory, then run:
|
||||
|
||||
```sh
|
||||
docker run --rm -it -v ${pwd}:/worker -w /worker funcy/ruby:dev bundle install --standalone --clean
|
||||
```
|
||||
|
||||
Ruby doesn't pick up the gems automatically, so you'll have to add this to the top of your `func.rb` file:
|
||||
|
||||
```ruby
|
||||
require_relative 'bundle/bundler/setup'
|
||||
```
|
||||
|
||||
Open `func.rb` to see it in action.
|
||||
|
||||
To update dependencies:
|
||||
|
||||
```sh
|
||||
docker run --rm -it -v ${pwd}:/worker -w /worker funcy/ruby:dev bundle update
|
||||
# then install again to vendor them
|
||||
docker run --rm -it -v ${pwd}:/worker -w /worker funcy/ruby:dev bundle update
|
||||
```
|
||||
12
examples/tutorial/hello/ruby/func.rb
Normal file
12
examples/tutorial/hello/ruby/func.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
require_relative 'bundle/bundler/setup'
|
||||
require 'json'
|
||||
|
||||
name = "World"
|
||||
|
||||
payload = STDIN.read
|
||||
if payload != ""
|
||||
payload = JSON.parse(payload)
|
||||
name = payload['name']
|
||||
end
|
||||
|
||||
puts "Hello #{name} from Ruby!"
|
||||
3
examples/tutorial/hello/ruby/hello.payload.json
Normal file
3
examples/tutorial/hello/ruby/hello.payload.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"name": "Johnny"
|
||||
}
|
||||
Reference in New Issue
Block a user