mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Added hello example.
This commit is contained in:
@@ -21,31 +21,3 @@ docker run --env-file .env --rm -it --privileged -p 8080:8080 iron/functions
|
||||
```sh
|
||||
./release.sh
|
||||
```
|
||||
|
||||
## FOR INFLUX AND ANALYTICS
|
||||
|
||||
|
||||
```sh
|
||||
docker run -p 8083:8083 -p 8086:8086 \
|
||||
-v $PWD:/var/lib/influxdb \
|
||||
--rm --name influxdb \
|
||||
influxdb:alpine
|
||||
```
|
||||
|
||||
CLI:
|
||||
|
||||
```sh
|
||||
docker run --rm --link influxdb -it influxdb:alpine influx -host influxdb
|
||||
```
|
||||
|
||||
chronograf:
|
||||
|
||||
```sh
|
||||
# they don't have an alpine image yet chronograf
|
||||
docker run -p 10000:10000 --link influxdb chronograf
|
||||
```
|
||||
|
||||
Open UI: http://localhost:10000
|
||||
|
||||
Add server with host `influxdb`
|
||||
|
||||
|
||||
42
README.md
42
README.md
@@ -23,7 +23,7 @@ iron create app APP_NAME
|
||||
curl -H "Content-Type: application/json" -X POST -d '{"name":"APP_NAME"}' http://localhost:8080/api/v1/apps
|
||||
```
|
||||
|
||||
### Create a Route
|
||||
### Create a Route for your Function
|
||||
|
||||
Now add routes to the app. First we'll add a route to the output of a docker container:
|
||||
|
||||
@@ -33,14 +33,24 @@ iron add route myapp /hello iron/hello
|
||||
curl -H "Content-Type: application/json" -X POST -d '{"path":"/hello", "image":"iron/hello"}' http://localhost:8080/api/v1/apps/myapp/routes
|
||||
```
|
||||
|
||||
Surf to your function: http://localhost:8080/hello?app=APP_NAME . Boom!
|
||||
|
||||
And how about a [slackbot](https://github.com/treeder/slackbots/tree/master/guppy) endpoint:
|
||||
And how about a [slackbot](https://github.com/treeder/slackbots/tree/master/guppy) too:
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d '{"path":"/guppy","image":"treeder/guppy:0.0.2", "content_type": "application/json"}' http://localhost:8080/api/v1/apps/myapp/routes
|
||||
```
|
||||
|
||||
### Calling your Function
|
||||
|
||||
Surf to your function: http://localhost:8080/hello?app=APP_NAME . Boom!
|
||||
|
||||
#### To pass in data to your function,
|
||||
|
||||
Your function will get the body of the request as is, and the headers of the request will be passed in as env vars.
|
||||
|
||||
```sh
|
||||
curl -H "Content-Type: application/json" -X POST -d '{"name":"Johnny"}' http://localhost:8080/hello?app=APP_NAME
|
||||
```
|
||||
|
||||
### Using IronFunctions Hosted by Iron.io
|
||||
|
||||
Simply point to https://functions.iron.io instead of localhost and add your Iron.io Authentication header (TODO: link), like this:
|
||||
@@ -55,7 +65,29 @@ And you'll get an ironfunctions.com host:
|
||||
APP_NAME.ironfunctions.com/PATH
|
||||
```
|
||||
|
||||
## Updating Your Images
|
||||
### Updating Your Images
|
||||
|
||||
Tag your images with a version, eg `treeder/guppy:0.0.5` then use that including the tag and update
|
||||
the route.
|
||||
|
||||
## Examples
|
||||
|
||||
TODO: Link to examples in various languages
|
||||
TODO: Link to slackbots (easiest way to host slackbots?)
|
||||
|
||||
## Operations
|
||||
|
||||
This is info on how to run and manage IronFunctions.
|
||||
|
||||
### Logging
|
||||
|
||||
Run logspout container on your server.
|
||||
|
||||
#### Monitoring
|
||||
|
||||
TODO
|
||||
|
||||
### Scaling
|
||||
|
||||
TODO
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
|
||||
|
||||
Test with:
|
||||
|
||||
ruby -run -e httpd . -p 9090
|
||||
@@ -1 +0,0 @@
|
||||
<iframe height="346" width="560" src="http://localhost:10000/embed_graph/1" frameborder="0" allowfullscreen scrolling="no"></iframe>
|
||||
2
examples/hello/.gitignore
vendored
Normal file
2
examples/hello/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
bundle/
|
||||
.bundle/
|
||||
9
examples/hello/Dockerfile
Normal file
9
examples/hello/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM iron/ruby:dev
|
||||
|
||||
WORKDIR /worker
|
||||
ADD Gemfile* /worker/
|
||||
RUN bundle install
|
||||
|
||||
ADD . /worker/
|
||||
|
||||
ENTRYPOINT ["ruby", "hello.rb"]
|
||||
3
examples/hello/Gemfile
Normal file
3
examples/hello/Gemfile
Normal file
@@ -0,0 +1,3 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'json', '> 1.8.2'
|
||||
13
examples/hello/Gemfile.lock
Normal file
13
examples/hello/Gemfile.lock
Normal file
@@ -0,0 +1,13 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
json (1.8.3)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
json (> 1.8.2)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.5
|
||||
33
examples/hello/README.md
Normal file
33
examples/hello/README.md
Normal file
@@ -0,0 +1,33 @@
|
||||
This is a worker that just echoes the "input" param in the payload.
|
||||
|
||||
eg:
|
||||
|
||||
This input:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Johnny Utah"
|
||||
}
|
||||
```
|
||||
|
||||
Will output:
|
||||
|
||||
```
|
||||
Hello Johnny Utah!
|
||||
```
|
||||
|
||||
## Building Image
|
||||
|
||||
```
|
||||
# SET BELOW TO YOUR DOCKER HUB USERNAME
|
||||
USERNAME=YOUR_DOCKER_HUB_USERNAME
|
||||
# build it
|
||||
docker build -t $USERNAME/hello .
|
||||
# test it
|
||||
docker run -e 'PAYLOAD={"name": "Johnny"}' $USERNAME/hello
|
||||
# tag it
|
||||
docker run --rm -v "$PWD":/app treeder/bump patch
|
||||
docker tag $USERNAME/hello:latest $USERNAME/hello:`cat VERSION`
|
||||
# push it
|
||||
docker push $USERNAME/hello
|
||||
```
|
||||
1
examples/hello/VERSION
Normal file
1
examples/hello/VERSION
Normal file
@@ -0,0 +1 @@
|
||||
0.0.27
|
||||
15
examples/hello/hello.rb
Normal file
15
examples/hello/hello.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
require 'json'
|
||||
|
||||
name = "World"
|
||||
|
||||
# payload = STDIN.read
|
||||
# or using env vars: ENV['PAYLOAD']
|
||||
payload = ENV['PAYLOAD']
|
||||
|
||||
puts 'ARGF: ' + payload.inspect
|
||||
if payload != ""
|
||||
payload = JSON.parse(payload)
|
||||
name = payload['name']
|
||||
end
|
||||
|
||||
puts "Hello #{name}!"
|
||||
Reference in New Issue
Block a user