Merge branch 'chad-update-tutorial' into 'master'

adding rust, fixing python/php, adding ability to detect rusts src/main.rs file. Updates all tutorials as well.

See merge request !39
This commit is contained in:
James Jeffrey
2017-06-05 15:52:31 -07:00
25 changed files with 274 additions and 216 deletions

38
Gopkg.lock generated
View File

@@ -32,10 +32,10 @@
revision = "bbf7a2afc14f93e1e0a5c06df524fbd75e5031e5"
[[projects]]
branch = "master"
name = "github.com/Sirupsen/logrus"
packages = [".","hooks/syslog"]
revision = "ba1b36c82c5e05c4f912a88eab0dcd91a171688f"
version = "v0.11.5"
revision = "5e5dc898656f695e2a086b8e12559febbfc01562"
[[projects]]
branch = "master"
@@ -51,9 +51,9 @@
[[projects]]
name = "github.com/aws/aws-sdk-go"
packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/corehandlers","aws/credentials","aws/credentials/ec2rolecreds","aws/credentials/endpointcreds","aws/credentials/stscreds","aws/defaults","aws/ec2metadata","aws/endpoints","aws/request","aws/session","aws/signer/v4","private/protocol","private/protocol/json/jsonutil","private/protocol/jsonrpc","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/restjson","private/protocol/xml/xmlutil","service/lambda","service/sts"]
revision = "a479673916dcc0f62674f085bb4112272b8d8560"
version = "v1.8.31"
packages = ["aws","aws/awserr","aws/awsutil","aws/client","aws/client/metadata","aws/corehandlers","aws/credentials","aws/credentials/ec2rolecreds","aws/credentials/endpointcreds","aws/credentials/stscreds","aws/defaults","aws/ec2metadata","aws/endpoints","aws/request","aws/session","aws/signer/v4","internal/shareddefaults","private/protocol","private/protocol/json/jsonutil","private/protocol/jsonrpc","private/protocol/query","private/protocol/query/queryutil","private/protocol/rest","private/protocol/restjson","private/protocol/xml/xmlutil","service/lambda","service/sts"]
revision = "f9a14dadf426ac17058f5ed3ec9bac9a61b5990b"
version = "v1.8.33"
[[projects]]
name = "github.com/boltdb/bolt"
@@ -119,7 +119,7 @@
branch = "master"
name = "github.com/docker/cli"
packages = ["cli/config/configfile"]
revision = "6c59636498e96f8d826764f92e9f71599857229d"
revision = "30af87981d8d464c385b247f524fcbc503207940"
[[projects]]
name = "github.com/docker/distribution"
@@ -176,10 +176,10 @@
version = "1.1.1"
[[projects]]
branch = "master"
name = "github.com/gin-gonic/gin"
packages = [".","binding","render"]
revision = "e2212d40c62a98b388a5eb48ecbdcf88534688ba"
version = "v1.1.4"
revision = "d5b353c5d5a560322e6d96121c814115562501f7"
[[projects]]
name = "github.com/go-ini/ini"
@@ -254,16 +254,16 @@
version = "v0.12"
[[projects]]
branch = "master"
name = "github.com/go-sql-driver/mysql"
packages = ["."]
revision = "a0583e0143b1624142adab07e0e97fe106d99561"
version = "v1.3"
revision = "e3f0fdcf52770a162d5a4540ddb8d9957ff456d1"
[[projects]]
branch = "master"
name = "github.com/golang/protobuf"
packages = ["proto"]
revision = "9f174c986221c608fb5143bd623b6076a71feae3"
revision = "6e4cc92cc905d5f4a73041c1b8228ea08f4c6147"
[[projects]]
branch = "master"
@@ -394,8 +394,8 @@
[[projects]]
name = "github.com/pelletier/go-toml"
packages = ["."]
revision = "13d49d4606eb801b8f01ae542b4afc4c6ee3d84a"
version = "v0.5.0"
revision = "5ccdfb18c776b740aecaf085c4d9a2779199c279"
version = "v1.0.0"
[[projects]]
branch = "master"
@@ -404,16 +404,16 @@
revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4"
[[projects]]
branch = "master"
name = "github.com/pkg/errors"
packages = ["."]
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
version = "v0.8.0"
revision = "c605e284fe17294bda444b34710735b29d1a9d90"
[[projects]]
branch = "master"
name = "github.com/satori/go.uuid"
packages = ["."]
revision = "879c5887cd475cd7864858769793b2ceb0d44feb"
version = "v1.1.0"
revision = "5bf94b69c6b68ee1b541973bb8e1144db23a194b"
[[projects]]
branch = "master"
@@ -461,7 +461,7 @@
branch = "master"
name = "golang.org/x/crypto"
packages = ["bcrypt","blowfish"]
revision = "7e9105388ebff089b3f99f0ef676ea55a6da3a7e"
revision = "e1a4589e7d3ea14a3352255d04b6f1a418845e5e"
[[projects]]
branch = "master"
@@ -502,6 +502,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "d512d36ab747f5eee6b2a62ee56cfde7a18fc185ffd5c99b104cf664819be05d"
inputs-digest = "961ede3bad03a1a3f5ac22d03ac3861a800943fbae4f66de32279d5f9fc85061"
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -71,8 +71,8 @@
name = "code.cloudfoundry.org/bytefmt"
[[constraint]]
branch = "master"
name = "github.com/Sirupsen/logrus"
version = "0.11.5"
[[constraint]]
branch = "master"
@@ -80,7 +80,7 @@
[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.8.31"
version = "1.8.32"
[[constraint]]
name = "github.com/boltdb/bolt"
@@ -131,8 +131,8 @@
version = "1.1.1"
[[constraint]]
branch = "master"
name = "github.com/gin-gonic/gin"
version = "1.1.4"
[[constraint]]
branch = "master"
@@ -163,8 +163,8 @@
name = "github.com/go-openapi/validate"
[[constraint]]
branch = "master"
name = "github.com/go-sql-driver/mysql"
version = "1.3.0"
[[constraint]]
branch = "master"
@@ -195,12 +195,12 @@
version = "1.13.1"
[[constraint]]
branch = "master"
name = "github.com/pkg/errors"
version = "0.8.0"
[[constraint]]
branch = "master"
name = "github.com/satori/go.uuid"
version = "1.1.0"
[[constraint]]
branch = "master"

View File

@@ -1,5 +1,4 @@
vendor/
/hello
/go
/app
/__uberscript__

View File

@@ -6,30 +6,31 @@ This example will show you how to test and deploy Go (Golang) code to Oracle Fun
```sh
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello
fn init <DOCKERHUB_USERNAME>/hello-go
# Test your function. This will run inside a container exactly how it will on the server
fn run
# Now try with an input
cat hello.payload.json | fn run
cat sample.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
fn deploy myapp
```
### Now call your function:
```sh
curl http://localhost:8080/r/myapp/hello
curl http://localhost:8080/r/myapp/hello-go
```
Or call from a browser: [http://localhost:8080/r/myapp/hello](http://localhost:8080/r/myapp/hello)
Or call from a browser: [http://localhost:8080/r/myapp/go](http://localhost:8080/r/myapp/hello-go)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/myapp/hello
curl -H "Content-Type: application/json" -X POST -d @sample.payload.json http://localhost:8080/r/myapp/hello-go
```
That's it!
@@ -42,7 +43,7 @@ In Go, simply put them all in the `vendor/` directory.
1. We piped JSON data into the function at the command line
```sh
cat hello.payload.json | fn run
cat sample.payload.json | fn run
```
2. We received our function input through **stdin**
@@ -62,4 +63,4 @@ In Go, simply put them all in the `vendor/` directory.
# Next Up
## [Tutorial 2: Input Parameters](examples/tutorial/params)
## [Tutorial 2: Input Parameters](examples/tutorial/params)

View File

@@ -1,43 +1,51 @@
# Oracle Functions: Java
This is a hello world example of a Oracle Function using the Java runtime.
This example will show you how to test and deploy Java code to Oracle Functions. It will also demonstrate passing data in through stdin.
Firstly, we initialize our function by creating a `func.yaml` using `fn init`. This command can optionally take a `--runtime` flag to explicitly specify the target function runtime. In this example, the target runtime is implied to be Java because there is a `Func.java` file in the working directory.
### First, run the following commands:
```sh
$ fn init <YOUR_DOCKERHUB_USERNAME>/hello-java
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello-java
# Test your function. This will run inside a container exactly how it will on the server
fn run
# Now try with an input
echo "Michael FassBender" | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
fn deploy myapp
```
This is what our `func.yaml` looks like now.
```
name: mhaji/hello-java
version: 0.0.1
runtime: java
entrypoint: java Func
path: /hello-java
max_concurrency: 1
```
Next, we build and run our function using `fn run`.
### Now call your function:
```sh
$ fn run
Hello, world!
curl http://localhost:8080/r/myapp/hello-java
```
You can also pipe input via `stdin` into to the function as follows:
Or call from a browser: [http://localhost:8080/r/myapp/hello-java](http://localhost:8080/r/myapp/hello-java)
```sh
$ echo "Michael FassBender" | fn run
Hello Michael FassBender!
```
That's it!
To execute your function via a HTTP trigger:
```sh
fn apps create myapp
fn routes create myapp /hello
curl -H "Content-Type: text/plain" -X POST -d "Michael FassBender" http://localhost:8080/r/myapp/hello
```
# In Review
1. We passed in data through stdin
```sh
echo "Michael FassBender" | fn run
```
2. We received our function input through **stdin**
```go
String name = bufferedReader.readLine();
```
3. We wrote our output to **stdout**
```go
System.out.println("Hello, " + name + "!");
```
# Next Up
## [Tutorial 2: Input Parameters](examples/tutorial/params)

View File

@@ -6,14 +6,14 @@ This example will show you how to test and deploy Node code to Oracle Functions.
```sh
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello
fn init <DOCKERHUB_USERNAME>/hello-node
# Test your function.
# This will run inside a container exactly how it will on the server. It will also install and vendor dependencies from Gemfile
fn run
# Now try with an input
cat hello.payload.json | fn run
cat sample.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
@@ -22,30 +22,24 @@ fn deploy myapp
### Now call your function:
```sh
curl http://localhost:8080/r/myapp/hello
curl http://localhost:8080/r/myapp/hello-node
```
Or call from a browser: [http://localhost:8080/r/myapp/hello](http://localhost:8080/r/myapp/hello)
Or call from a browser: [http://localhost:8080/r/myapp/hello-node](http://localhost:8080/r/myapp/hello-node)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/myapp/hello
curl -H "Content-Type: application/json" -X POST -d @sample.payload.json http://localhost:8080/r/myapp/hello-node
```
That's it!
That's it! Our `fn deploy` packaged our function and sent it to the Oracle Functions server. Try editing `func.js`
and then doing another `fn deploy`.
### Note on 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.
Create a [package.json](https://docs.npmjs.com/getting-started/using-a-package.json) file in your functions directory. The CLI should pick that up and build in all
your dependencies on `fn run` and `fn deploy`.
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:
@@ -63,7 +57,7 @@ request('http://www.google.com', function (error, response, body) {
1. We piped JSON data into the function at the command line
```sh
cat hello.payload.json | fn run
cat sample.payload.json | fn run
```
2. We received our function input through **stdin**

View File

@@ -6,14 +6,14 @@ This example will show you how to test and deploy PHP code to Oracle Functions.
```sh
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello
fn init <DOCKERHUB_USERNAME>/hello-php
# Test your function.
# This will run inside a container exactly how it will on the server. It will also install and vendor dependencies from Gemfile
fn run
# Now try with an input
cat hello.payload.json | fn run
cat sample.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
@@ -22,27 +22,24 @@ fn deploy myapp
### Now call your function:
```sh
curl http://localhost:8080/r/myapp/hello
curl http://localhost:8080/r/myapp/hello-php
```
Or call from a browser: [http://localhost:8080/r/myapp/hello](http://localhost:8080/r/myapp/hello)
Or call from a browser: [http://localhost:8080/r/myapp/hello-php](http://localhost:8080/r/myapp/hello-php)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/myapp/hello
curl -H "Content-Type: application/json" -X POST -d @sample.payload.json http://localhost:8080/r/myapp/hello-php
```
That's it!
That's it! Our `fn deploy` packaged our function and sent it to the Oracle Functions server. Try editing `func.php`
and then doing another `fn deploy`.
### Note on Dependencies
In PHP, you can create a [composer](https://getcomposer.org/) file in your function directory, then run:
```sh
fn build
```
This will rebuild your gems and vendor them. PHP doesn't pick them up automatically, so you'll have to add this to the top of your `func.php` file:
```php
@@ -52,21 +49,11 @@ require 'vendor/autoload.php';
Open `func.php` to see it in action.
### 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
```
# In Review
1. We piped JSON data into the function at the command line
```sh
cat hello.payload.json | fn run
cat sample.payload.json | fn run
```
2. We received our function input through **stdin**

View File

@@ -1,6 +0,0 @@
name: carimura2/hello
version: 0.0.2
runtime: php
entrypoint: php func.php
path: /hello
max_concurrency: 1

View File

@@ -1,6 +0,0 @@
FROM funcy/python:2
WORKDIR /app
ADD . /app
ENTRYPOINT ["python", "hello.py"]

View File

@@ -1,48 +1,67 @@
## Quick Example for a Python Function (4 minutes)
# Tutorial 1: Python Function w/ Input (3 minutes)
This example will show you how to test and deploy Go (Golang) code to Oracle Functions.
This example will show you how to test and deploy Python code to Oracle Functions. It will also demonstrate passing data in through stdin.
### 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/python:2-dev pip install -t packages -r requirements.txt
```
The important step here is to ensure you replace `USERNAME` with your Docker Hub account name. Some points of note:
the application name is `pythonapp` and the route for incoming requests is `/hello`. These informations are relevant for
the moment you try to test this function.
### 2. Build:
### First, run the following commands:
```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 pythonapp /hello
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello-python
# Test your function.
# This will run inside a container exactly how it will on the server. It will also install and vendor dependencies from Gemfile
fn run
# Now try with an input
cat sample.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
fn deploy myapp
```
`-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.
### Now call your function:
```sh
cat hello.payload.json | fn call pythonapp /hello
curl http://localhost:8080/r/myapp/hello-python
```
Here's a curl example to show how easy it is to do in any language:
Or call from a browser: [http://localhost:8080/r/myapp/hello-python](http://localhost:8080/r/myapp/hello-python)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/pythonapp/hello
curl -H "Content-Type: application/json" -X POST -d @sample.payload.json http://localhost:8080/r/myapp/hello-python
```
That's it! Our `fn deploy` packaged our function and sent it to the Oracle Functions server. Try editing `func.py`
and then doing another `fn deploy`.
### Note on Dependencies
In Python, we create a [requirements](https://pip.pypa.io/en/stable/user_guide/) file in your function directory then `fn deploy` will build and deploy with these dependencies.
# In Review
1. We piped JSON data into the function at the command line
```sh
cat sample.payload.json | fn run
```
2. We received our function input through **stdin**
```python
obj = json.loads(sys.stdin.read())
```
3. We wrote our output to **stdout**
```python
print "Hello", name, "!"
```
4. We sent **stderr** to the server logs
```python
sys.stderr.write("Starting Python Function\n")
```
# Next Up
## [Tutorial 2: Input Parameters](examples/tutorial/params)

View File

@@ -0,0 +1,18 @@
import sys
sys.path.append("packages")
import os
import json
sys.stderr.write("Starting Python Function\n")
name = "World"
try:
if not os.isatty(sys.stdin.fileno()):
obj = json.loads(sys.stdin.read())
if obj["name"] != "":
name = obj["name"]
except:
pass
print "Hello", name, "!"

View File

@@ -1,12 +0,0 @@
import sys
sys.path.append("packages")
import os
import json
name = "World"
if not os.isatty(sys.stdin.fileno()):
obj = json.loads(sys.stdin.read())
if obj["name"] != "":
name = obj["name"]
print "Hello", name, "!!!"

View File

@@ -6,14 +6,14 @@ This example will show you how to test and deploy Ruby code to Oracle Functions.
```sh
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello
fn init <DOCKERHUB_USERNAME>/hello-ruby
# Test your function.
# This will run inside a container exactly how it will on the server. It will also install and vendor dependencies from Gemfile
fn run
# Now try with an input
cat hello.payload.json | fn run
cat sample.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
@@ -22,28 +22,27 @@ fn deploy myapp
### Now call your function:
```sh
curl http://localhost:8080/r/myapp/hello
curl http://localhost:8080/r/myapp/hello-ruby
```
Or call from a browser: [http://localhost:8080/r/myapp/hello](http://localhost:8080/r/myapp/hello)
Or call from a browser: [http://localhost:8080/r/myapp/hello-ruby](http://localhost:8080/r/myapp/hello-ruby)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @hello.payload.json http://localhost:8080/r/myapp/hello
curl -H "Content-Type: application/json" -X POST -d @sample.payload.json http://localhost:8080/r/myapp/hello-ruby
```
That's it!
That's it! Our `fn deploy` packaged our function and sent it to the Oracle Functions server. Try editing `func.rb`
and then doing another `fn deploy`.
### Note on Dependencies
In Ruby, we create a [Gemfile](http://bundler.io/gemfile.html) file in your function directory, then run:
In Ruby, we create a [Gemfile](http://bundler.io/gemfile.html) file in your function directory. Then any `fn run`
or `fn deploy` will rebuild your gems and vendor them.
```sh
fn build
```
This will rebuild your gems and vendor them. Ruby doesn't pick up the gems automatically, so you'll have to add this to the top of your `func.rb` file:
Note: 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'
@@ -51,21 +50,11 @@ require_relative 'bundle/bundler/setup'
Open `func.rb` to see it in action.
To update dependencies:
```sh
# Let's run bundle update
docker run --rm -it -v ${PWD}:/worker -w /worker funcy/ruby:dev bundle update
# Then bundle install again to vendor them
docker run --rm -it -v ${PWD}:/worker -w /worker funcy/ruby:dev bundle install --standalone --clean
```
# In Review
1. We piped JSON data into the function at the command line
```sh
cat hello.payload.json | fn run
cat sample.payload.json | fn run
```
2. We received our function input through **stdin**

View File

@@ -0,0 +1,2 @@
func.yaml
Cargo.lock

View File

@@ -1,33 +1,93 @@
# Using rust with functions
# Tutorial 1: Rust Function w/ Input (3 minutes)
This example will show you how to test and deploy Rust code to Oracle Functions. It will also demonstrate passing data in through stdin.
The easiest way to create a function in rust is via ***cargo*** and ***fn***.
## Prerequisites
### Prerequisites
First create an epty rust project as follows:
Create an empty 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.
Make sure the project name is ***func*** and is of type ***bin***.
## Creating a function
Now put the following code in ```main.rs``` (can also copy directly from the file in this repo):
Simply run
```rust
use std::io;
use std::io::Read;
```bash
fn init --runtime=rust <username>/<funcname>
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());
}
}
```
This will create the ```func.yaml``` file required by functions, which can be built by running:
```bash
fn build
```
### Now run the following commands:
## Testing
```sh
# Initialize your function creating a func.yaml file
fn init <DOCKERHUB_USERNAME>/hello-rust
```bash
# Test your function. This will run inside a container exactly how it will on the server
fn run
# Now try with an input (copy sample.payload.json from this repo)
cat sample.payload.json | fn run
# Deploy your functions to the Oracle Functions server (default localhost:8080)
# This will create a route to your function as well
fn deploy myapp
```
### Now call your function:
```sh
curl http://localhost:8080/r/myapp/hello-rust
```
Or call from a browser: [http://localhost:8080/r/myapp/hello-rust](http://localhost:8080/r/myapp/hello-rust)
And now with the JSON input:
```sh
curl -H "Content-Type: application/json" -X POST -d @sample.payload.json http://localhost:8080/r/myapp/hello-rust
```
That's it!
### Note on Dependencies
# In Review
1. We piped JSON data into the function at the command line
```sh
cat sample.payload.json | fn run
```
2. We received our function input through **stdin**
```rust
read_to_string(&mut buffer)
```
3. We wrote our output to **stdout**
```rust
println!("Hello {}", buffer.trim());
```
4. We sent **stderr** to the server logs
```rust
TODO
```
# Next Up
## [Tutorial 2: Input Parameters](examples/tutorial/params)

View File

@@ -0,0 +1,3 @@
{
"name": "Johnny"
}

View File

@@ -7,4 +7,5 @@ fn main() {
if stdin.lock().read_to_string(&mut buffer).is_ok() {
println!("Hello {}", buffer.trim());
}
//todo: decode json from payload
}

View File

@@ -23,14 +23,14 @@ import (
var (
fileExtToRuntime = map[string]string{
".go": "go",
".js": "node",
".rb": "ruby",
".py": "python",
".php": "php",
".rs": "rust",
".cs": "dotnet",
".fs": "dotnet",
".go": "go",
".js": "node",
".rb": "ruby",
".py": "python",
".php": "php",
".rs": "rust",
".cs": "dotnet",
".fs": "dotnet",
".java": "java",
}
@@ -214,9 +214,10 @@ func (a *initFnCmd) buildFuncFile(c *cli.Context) error {
func detectRuntime(path string) (runtime string, err error) {
for ext, runtime := range fileExtToRuntime {
filenames := []string {
filenames := []string{
filepath.Join(path, fmt.Sprintf("func%s", ext)),
filepath.Join(path, fmt.Sprintf("Func%s", ext)),
filepath.Join(path, fmt.Sprintf("src/main%s", ext)), // rust
}
for _, filename := range filenames {
if exists(filename) {

View File

@@ -2,8 +2,8 @@ package langs
import (
"errors"
"os"
"fmt"
"os"
)
var (
@@ -20,7 +20,7 @@ func GetLangHelper(lang string) LangHelper {
case "ruby":
return &RubyLangHelper{}
case "python":
return &PythonHelper{}
return &PythonLangHelper{}
case "php":
return &PhpLangHelper{}
case "rust":
@@ -54,8 +54,8 @@ type LangHelper interface {
type BaseHelper struct {
}
func (h *BaseHelper) Cmd() string { return "" }
func (h *BaseHelper) HasBoilerplate() bool { return false }
func (h *BaseHelper) Cmd() string { return "" }
func (h *BaseHelper) HasBoilerplate() bool { return false }
func (h *BaseHelper) GenerateBoilerplate() error { return nil }
func exists(name string) bool {
@@ -69,4 +69,4 @@ func exists(name string) bool {
func dockerBuildError(err error) error {
return fmt.Errorf("error running docker build: %v", err)
}
}

View File

@@ -7,20 +7,20 @@ import (
"strings"
)
type PythonHelper struct {
type PythonLangHelper struct {
BaseHelper
}
func (lh *PythonHelper) Entrypoint() string {
func (lh *PythonLangHelper) Entrypoint() string {
return "python2 func.py"
}
func (lh *PythonHelper) HasPreBuild() bool {
func (lh *PythonLangHelper) HasPreBuild() bool {
return true
}
// PreBuild for Go builds the binary so the final image can be as small as possible
func (lh *PythonHelper) PreBuild() error {
func (lh *PythonLangHelper) PreBuild() error {
wd, err := os.Getwd()
if err != nil {
return err
@@ -40,6 +40,6 @@ func (lh *PythonHelper) PreBuild() error {
return nil
}
func (lh *PythonHelper) AfterBuild() error {
func (lh *PythonLangHelper) AfterBuild() error {
return nil
}