From a565c09c7fa47217c62b65ae432690e28a43ed6e Mon Sep 17 00:00:00 2001 From: Chad Arimura Date: Thu, 25 May 2017 14:28:00 -0700 Subject: [PATCH] reorging examples/tutorials a bit --- Gopkg.lock | 2 +- README.md | 59 +++++++++++------------- examples/README.md | 8 ++-- examples/hello/go/.gitignore | 7 --- examples/hello/go/README.md | 27 ----------- examples/hello/go/func.go | 17 ------- examples/hello/go/hello.payload.json | 3 -- examples/hello/node/.gitignore | 3 -- examples/hello/node/README.md | 41 ---------------- examples/hello/node/func.js | 9 ---- examples/hello/node/hello.payload.json | 3 -- examples/hello/node/package.json | 7 --- examples/hello/php/.gitignore | 1 - examples/hello/php/Dockerfile | 6 --- examples/hello/php/README.md | 48 ------------------- examples/hello/php/composer.json | 4 -- examples/hello/php/func.yaml | 5 -- examples/hello/php/hello.payload.json | 3 -- examples/hello/php/hello.php | 10 ---- examples/hello/python/.gitignore | 2 - examples/hello/python/Dockerfile | 6 --- examples/hello/python/README.md | 48 ------------------- examples/hello/python/hello.payload.json | 3 -- examples/hello/python/hello.py | 12 ----- examples/hello/python/requirements.txt | 0 examples/hello/ruby/.gitignore | 5 -- examples/hello/ruby/Gemfile | 4 -- examples/hello/ruby/README.md | 44 ------------------ examples/hello/ruby/func.rb | 12 ----- examples/hello/ruby/hello.payload.json | 3 -- examples/hello/rust/Cargo.toml | 6 --- examples/hello/rust/README.md | 33 ------------- examples/hello/rust/src/main.rs | 10 ---- examples/hotfunctions/http/func.go | 45 ------------------ examples/hotfunctions/http/hotroute.json | 9 ---- fn/init.go | 11 +++-- 36 files changed, 37 insertions(+), 479 deletions(-) delete mode 100644 examples/hello/go/.gitignore delete mode 100644 examples/hello/go/README.md delete mode 100644 examples/hello/go/func.go delete mode 100644 examples/hello/go/hello.payload.json delete mode 100644 examples/hello/node/.gitignore delete mode 100644 examples/hello/node/README.md delete mode 100644 examples/hello/node/func.js delete mode 100644 examples/hello/node/hello.payload.json delete mode 100644 examples/hello/node/package.json delete mode 100644 examples/hello/php/.gitignore delete mode 100644 examples/hello/php/Dockerfile delete mode 100644 examples/hello/php/README.md delete mode 100644 examples/hello/php/composer.json delete mode 100644 examples/hello/php/func.yaml delete mode 100644 examples/hello/php/hello.payload.json delete mode 100644 examples/hello/php/hello.php delete mode 100644 examples/hello/python/.gitignore delete mode 100644 examples/hello/python/Dockerfile delete mode 100644 examples/hello/python/README.md delete mode 100644 examples/hello/python/hello.payload.json delete mode 100644 examples/hello/python/hello.py delete mode 100644 examples/hello/python/requirements.txt delete mode 100644 examples/hello/ruby/.gitignore delete mode 100644 examples/hello/ruby/Gemfile delete mode 100644 examples/hello/ruby/README.md delete mode 100644 examples/hello/ruby/func.rb delete mode 100644 examples/hello/ruby/hello.payload.json delete mode 100644 examples/hello/rust/Cargo.toml delete mode 100644 examples/hello/rust/README.md delete mode 100644 examples/hello/rust/src/main.rs delete mode 100644 examples/hotfunctions/http/func.go delete mode 100644 examples/hotfunctions/http/hotroute.json diff --git a/Gopkg.lock b/Gopkg.lock index 8c11b20c6..a915373dc 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -383,7 +383,7 @@ memo = "bd1e1a24b7655bd27880d6b3d752e400a4e36e7b1d7129a1a9e54a11fac75c9c" branch = "master" name = "github.com/moby/moby" packages = ["pkg/jsonmessage"] - revision = "da3c3ec1458588d5d263dc3babd3dca95fdc7d8d" + revision = "e925820bfd5af066497800a02c597d6846988398" [[projects]] name = "github.com/opencontainers/go-digest" diff --git a/README.md b/README.md index 72585ef52..cb2338358 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ -Oracle Functions is an open source [serverless](serverless.md) platform, or as we like to refer to it, Functions as a Service (FaaS) platform that you can run anywhere. Some of it's key features: +Oracle Functions is an event-driven, open source, [functions-as-a-service](serverless.md) compute +platform that you can run anywhere. Some of it's key features: * Write once * [Any language](docs/faq.md#which-languages-are-supported) @@ -13,6 +14,7 @@ Oracle Functions is an open source [serverless](serverless.md) platform, or as w * Easy to use [for developers](docs/README.md#for-developers) * Easy to manage [for operators](docs/README.md#for-operators) * Written in [Go](https://golang.org) +* Simple yet powerful extensibility ## Prequisites @@ -65,14 +67,11 @@ configuration options [here](docs/operating/options.md). If you are on Windows, --> -### Writing Your First Function +### Your First Function Functions are small but powerful blocks of code that generally do one simple thing. Forget about monoliths when using functions, just focus on the task that you want the function to perform. -Start with this readme tutorial, and then you can learn more about function best practices in -our section [Writing Functions](docs/writing.md). - -The following is a simple Go program that outputs a string to STDOUT. Copy and paste the code below into a file called `func.go`. +The following is a simple Go program that outputs a string to STDOUT. Copy and paste the code below into a file called `func.go`. Currently the function must be named func.your_language_extention (ie func.go, func.js, etc.) ```go package main @@ -82,30 +81,30 @@ import ( ) func main() { - fmt.Println("Boom. Oracle Functions.") + fmt.Println("Hello from Oracle Functions!") } ``` -Now run the following commands to build your function and deploy it: +Now run the following CLI commands: ```sh # Create your first application fn apps create myapp -# Initilizes your function w/ prebuilt func.yaml -# Replace $USERNAME with your DockerHub username -fn init $USERNAME/hello +# Initialize your function +# This detects your runtime from the code above and creates a func.yaml +fn init /hello # Test your function # This will run inside a container exactly how it will on the server fn run -# Deploy it to your functions server (default localhost:8080) +# Deploy your functions to the Oracle Functions server (default localhost:8080) # This will create a route to your function as well fn deploy myapp ``` -Boom. Now you can call your function: +Now you can call your function: ```sh curl http://localhost:8080/r/myapp/hello @@ -116,36 +115,32 @@ Or in a browser: [http://localhost:8080/r/myapp/hello](http://localhost:8080/r/m That's it! You just deployed your first function and called it. Now to update your function you can update your code and run ```fn deploy myapp``` again. -## Learning More +## To Learn More -### Documentation +- Walk through the following [tutorial series](docs/tutorial) +- See our [full documentation](docs/README.md) +- View our [examples directory](/examples) +- You can also write your functions in AWS [Lambda format](docs/lambda/README.md) -See [docs/](docs/README.md) for full documentation. +## Get Involved -More on [Writing Functions](docs/writing.md). - -And you can find a bunch of examples in the [/examples](/examples) directory. - -You can also write your functions in AWS's [Lambda format](docs/lambda/README.md). - -### Get Involved - -TODO: Slack or Discord community. - -See [contributing](CONTRIBUTING.md). +- TODO: Slack or Discord community +- Learn how to [contribute](CONTRIBUTING.md) +- See [milestones](https://gitlab.oracledx.com/odx/functions/milestones) for detailed issues -## Functions UI +## User Interface + +This is the graphical user interface for Oracle Functions. It is currently not buildable. ```sh docker run --rm -it --link functions:api -p 4000:4000 -e "API_URL=http://api:8080" treeder/functions-ui ``` -For more information, see: https://github.com/treeder/functions-ui +For more information, see: [https://github.com/treeder/functions-ui](https://github.com/treeder/functions-ui) -## Roadmap - -See [milestones](https://gitlab.oracledx.com/odx/functions/milestones) for detailed issues. +## Next up: Walk through the following [tutorial series](docs/tutorial/) --> + diff --git a/examples/README.md b/examples/README.md index 3b6ea228f..135c2daf1 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,9 +1,7 @@ # Example Functions -This directory has a collection of example functions you can look at to learn more about how to write them -or just copy one and build on it to get started faster. +This directory has a collection of example functions you can look at to learn more about how to write them or just copy one and build on it to get started faster. -## Hello World Examples +## Tutorial Series -The [Hello World examples](hello/) are the most basic functions you can write and we'll try to have an example in most major languages. -This is a good place to start and good examples to copy and build upon. +The [Tutorial Series](tutorial/) will demonstrate some of Oracle Functions capabilities through a series of exmaples. We'll try to examples in most major languages. This is a great place to start! diff --git a/examples/hello/go/.gitignore b/examples/hello/go/.gitignore deleted file mode 100644 index 47868d339..000000000 --- a/examples/hello/go/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -vendor/ -/hello -/go -/app -/__uberscript__ - -func.yaml diff --git a/examples/hello/go/README.md b/examples/hello/go/README.md deleted file mode 100644 index ced7b8d99..000000000 --- a/examples/hello/go/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Quick Example for a Go Function (3 minutes) - -This example will show you how to test and deploy Go (Golang) code to Oracle Functions. - -```sh -# create your func.yaml file -fn init /hello -# 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 you can call your function on Oracle Functions: - -```sh -curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/myapp/hello -``` - -## Dependencies - -Be sure you're dependencies are in the `vendor/` directory and that's it. - diff --git a/examples/hello/go/func.go b/examples/hello/go/func.go deleted file mode 100644 index bf0518407..000000000 --- a/examples/hello/go/func.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "os" -) - -type Person struct { - Name string -} - -func main() { - p := &Person{Name: "World"} - json.NewDecoder(os.Stdin).Decode(p) - fmt.Printf("Hello %v!", p.Name) -} diff --git a/examples/hello/go/hello.payload.json b/examples/hello/go/hello.payload.json deleted file mode 100644 index 97e136b69..000000000 --- a/examples/hello/go/hello.payload.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Johnny" -} diff --git a/examples/hello/node/.gitignore b/examples/hello/node/.gitignore deleted file mode 100644 index 8977e475d..000000000 --- a/examples/hello/node/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules/ -func.yaml -Dockerfile diff --git a/examples/hello/node/README.md b/examples/hello/node/README.md deleted file mode 100644 index 2a4baff97..000000000 --- a/examples/hello/node/README.md +++ /dev/null @@ -1,41 +0,0 @@ -## Quick Example for a NodeJS Function (4 minutes) - -This example will show you how to test and deploy a Node function to Oracle Functions. - -```sh -# create your func.yaml file -fn init /hello -# 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 [package.json](https://docs.npmjs.com/getting-started/using-a-package.json) file in your functions directory. - -Run: - -```sh -docker run --rm -v "$PWD":/function -w /function funcy/node:dev npm install -``` - -Then everything should work. - -For example, using the `package.json` file in this directory which includes the [request](https://www.npmjs.com/package/request) package, you can add this to func.js and it will work: - -```js -var request = require('request'); -request('http://www.google.com', function (error, response, body) { - if (!error && response.statusCode == 200) { - console.log(body) // Show the HTML for the Google homepage. - } -}) -``` diff --git a/examples/hello/node/func.js b/examples/hello/node/func.js deleted file mode 100644 index 356544e81..000000000 --- a/examples/hello/node/func.js +++ /dev/null @@ -1,9 +0,0 @@ -name = "World"; -fs = require('fs'); -try { - obj = JSON.parse(fs.readFileSync('/dev/stdin').toString()) - if (obj.name != "") { - name = obj.name - } -} catch(e) {} -console.log("Hello", name, "from Node!"); diff --git a/examples/hello/node/hello.payload.json b/examples/hello/node/hello.payload.json deleted file mode 100644 index 97e136b69..000000000 --- a/examples/hello/node/hello.payload.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Johnny" -} diff --git a/examples/hello/node/package.json b/examples/hello/node/package.json deleted file mode 100644 index f332baddb..000000000 --- a/examples/hello/node/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "my-awesome-func", - "version": "1.0.0", - "dependencies": { - "request": "^2.78.0" - } -} \ No newline at end of file diff --git a/examples/hello/php/.gitignore b/examples/hello/php/.gitignore deleted file mode 100644 index 48b8bf907..000000000 --- a/examples/hello/php/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vendor/ diff --git a/examples/hello/php/Dockerfile b/examples/hello/php/Dockerfile deleted file mode 100644 index 1da497e06..000000000 --- a/examples/hello/php/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM funcy/php - -WORKDIR /app -ADD . /app - -ENTRYPOINT ["php", "hello.php"] diff --git a/examples/hello/php/README.md b/examples/hello/php/README.md deleted file mode 100644 index 1ccc9b1d1..000000000 --- a/examples/hello/php/README.md +++ /dev/null @@ -1,48 +0,0 @@ -## Quick Example for a PHP Function (4 minutes) - -This example will show you how to test and deploy Go (Golang) code to Oracle Functions. - -### 1. Prepare the `func.yaml` file: - -At func.yaml you will find: - -```yml -name: USERNAME/hello -version: 0.0.1 -path: /hello -build: -- docker run --rm -v "$PWD":/worker -w /worker funcy/php:dev composer install -``` - -The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note: -the application name is `phpapp` and the route for incoming requests is `/hello`. These informations are relevant for -the moment you try to test this function. - -### 2. Build: - -```sh -# 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 phpapp /hello -``` - -`-v` is optional, but it allows you to see how this function is being built. - -### 3. Queue jobs for your function - -Now you can start jobs on your function. Let's quickly queue up a job to try it out. - -```sh -cat hello.payload.json | fn call phpapp /hello -``` - -Here's a curl example to show how easy it is to do in any language: - -```sh -curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/phpapp/hello -``` \ No newline at end of file diff --git a/examples/hello/php/composer.json b/examples/hello/php/composer.json deleted file mode 100644 index df8dd9cf8..000000000 --- a/examples/hello/php/composer.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "require": { - } -} diff --git a/examples/hello/php/func.yaml b/examples/hello/php/func.yaml deleted file mode 100644 index 027b012ee..000000000 --- a/examples/hello/php/func.yaml +++ /dev/null @@ -1,5 +0,0 @@ -name: USERNAME/hello -version: 0.0.1 -path: /hello -build: -- docker run --rm -v "$PWD":/worker -w /worker funcy/php:dev composer install diff --git a/examples/hello/php/hello.payload.json b/examples/hello/php/hello.payload.json deleted file mode 100644 index 97e136b69..000000000 --- a/examples/hello/php/hello.payload.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Johnny" -} diff --git a/examples/hello/php/hello.php b/examples/hello/php/hello.php deleted file mode 100644 index 7828f1f95..000000000 --- a/examples/hello/php/hello.php +++ /dev/null @@ -1,10 +0,0 @@ - 0.14.0' -gem 'json', '> 1.8.2' diff --git a/examples/hello/ruby/README.md b/examples/hello/ruby/README.md deleted file mode 100644 index 05ef81eea..000000000 --- a/examples/hello/ruby/README.md +++ /dev/null @@ -1,44 +0,0 @@ -## 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 /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 -``` diff --git a/examples/hello/ruby/func.rb b/examples/hello/ruby/func.rb deleted file mode 100644 index a16a04030..000000000 --- a/examples/hello/ruby/func.rb +++ /dev/null @@ -1,12 +0,0 @@ -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!" diff --git a/examples/hello/ruby/hello.payload.json b/examples/hello/ruby/hello.payload.json deleted file mode 100644 index 97e136b69..000000000 --- a/examples/hello/ruby/hello.payload.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "Johnny" -} diff --git a/examples/hello/rust/Cargo.toml b/examples/hello/rust/Cargo.toml deleted file mode 100644 index 7c3608e1d..000000000 --- a/examples/hello/rust/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "func" -version = "0.1.0" -authors = ["Seif Lotfy "] - -[dependencies] diff --git a/examples/hello/rust/README.md b/examples/hello/rust/README.md deleted file mode 100644 index 895f3ba51..000000000 --- a/examples/hello/rust/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Using rust with functions - -The easiest way to create a function in rust is via ***cargo*** and ***fn***. - -## Prerequisites - -First create an epty rust project as follows: - -```bash -cargo init --name func --bin -``` - -Make sure the project name is ***func*** and is of type ***bin***. Now just edit your code, once done you can create a function. - -## Creating a function - -Simply run - -```bash -fn init --runtime=rust / -``` - -This will create the ```func.yaml``` file required by functions, which can be built by running: - -```bash -fn build -``` - -## Testing - -```bash -fn run -``` diff --git a/examples/hello/rust/src/main.rs b/examples/hello/rust/src/main.rs deleted file mode 100644 index 020c757b1..000000000 --- a/examples/hello/rust/src/main.rs +++ /dev/null @@ -1,10 +0,0 @@ -use std::io; -use std::io::Read; - -fn main() { - let mut buffer = String::new(); - let stdin = io::stdin(); - if stdin.lock().read_to_string(&mut buffer).is_ok() { - println!("Hello {}", buffer.trim()); - } -} diff --git a/examples/hotfunctions/http/func.go b/examples/hotfunctions/http/func.go deleted file mode 100644 index cba961f2e..000000000 --- a/examples/hotfunctions/http/func.go +++ /dev/null @@ -1,45 +0,0 @@ -package main - -import ( - "bufio" - "bytes" - "fmt" - "io/ioutil" - "net/http" - "os" - "strconv" -) - -func main() { - for { - res := http.Response{ - Proto: "HTTP/1.1", - ProtoMajor: 1, - ProtoMinor: 1, - StatusCode: 200, - Status: "OK", - } - - r := bufio.NewReader(os.Stdin) - req, err := http.ReadRequest(r) - - var buf bytes.Buffer - if err != nil { - res.StatusCode = 500 - res.Status = http.StatusText(res.StatusCode) - fmt.Fprintln(&buf, err) - } else { - l, _ := strconv.Atoi(req.Header.Get("Content-Length")) - p := make([]byte, l) - r.Read(p) - fmt.Fprintf(&buf, "Hello %s\n", p) - for k, vs := range req.Header { - fmt.Fprintf(&buf, "ENV: %s %#v\n", k, vs) - } - } - - res.Body = ioutil.NopCloser(&buf) - res.ContentLength = int64(buf.Len()) - res.Write(os.Stdout) - } -} diff --git a/examples/hotfunctions/http/hotroute.json b/examples/hotfunctions/http/hotroute.json deleted file mode 100644 index af7e65172..000000000 --- a/examples/hotfunctions/http/hotroute.json +++ /dev/null @@ -1,9 +0,0 @@ -{"route":{ - "app_name": "myapp", - "path": "/hot", - "image": "USERNAME/hchttp", - "memory": 64, - "type": "sync", - "config": null, - "format": "http" -}} diff --git a/fn/init.go b/fn/init.go index 4e46293f8..dc9904786 100644 --- a/fn/init.go +++ b/fn/init.go @@ -17,8 +17,8 @@ import ( "strings" - "gitlab.oracledx.com/odx/functions/fn/langs" "github.com/urfave/cli" + "gitlab.oracledx.com/odx/functions/fn/langs" ) var ( @@ -157,9 +157,10 @@ func (a *initFnCmd) buildFuncFile(c *cli.Context) error { return err } a.runtime = rt - fmt.Printf("assuming %v runtime\n", rt) + fmt.Printf("Found %v, assuming %v runtime.\n", rt, rt) + } else { + fmt.Println("Runtime:", a.runtime) } - fmt.Println("runtime:", a.runtime) if _, ok := acceptableFnRuntimes[a.runtime]; !ok { return fmt.Errorf("init does not support the %s runtime, you'll have to create your own Dockerfile for this function", a.runtime) } @@ -180,7 +181,7 @@ func (a *initFnCmd) buildFuncFile(c *cli.Context) error { } } if a.entrypoint == "" && a.cmd == "" { - return fmt.Errorf("could not detect entrypoint or cmd for %v, use --entrypoint and/or --cmd to set them explicitly", a.runtime) + return fmt.Errorf("Could not detect entrypoint or cmd for %v, use --entrypoint and/or --cmd to set them explicitly", a.runtime) } return nil @@ -193,5 +194,5 @@ func detectRuntime(path string) (runtime string, err error) { return runtime, nil } } - return "", fmt.Errorf("no supported files found to guess runtime, please set runtime explicitly with --runtime flag") + return "", fmt.Errorf("No supported files found to guess runtime, please set runtime explicitly with --runtime flag") }