Examples changes (#201)

This commit is contained in:
Pedro Nasser
2016-11-01 18:15:27 -02:00
committed by C Cirello
parent 570fdea062
commit 5d9269e186
91 changed files with 967 additions and 424 deletions

View File

@@ -1,9 +1,9 @@
FROM iron/ruby:dev
WORKDIR /worker
ADD Gemfile* /worker/
WORKDIR /function
ADD Gemfile* /function/
RUN bundle install
ADD . /worker/
ADD . /function/
ENTRYPOINT ["ruby", "sleeper.rb"]
ENTRYPOINT ["ruby", "function.rb"]

View File

@@ -1,13 +0,0 @@
GEM
remote: https://rubygems.org/
specs:
json (1.8.3)
PLATFORMS
ruby
DEPENDENCIES
json (> 1.8.2)
BUNDLED WITH
1.10.5

View File

@@ -1,23 +1,77 @@
This is a worker that just echoes the "input" param in the payload.
# Sleeper Function Image
eg:
This images compares the payload info with the header.
This input:
## Requirements
```json
{
"sleep": 5
}
```
- IronFunctions API
Will make this container sleep for 5 seconds.
## Development
## Building Image
Install [dj](https://github.com/treeder/dj/), then run:
### Building image locally
```
docker build -t iron/sleeper .
docker run -e 'PAYLOAD={"sleep": 5}' iron/sleeper
# SET BELOW TO YOUR DOCKER HUB USERNAME
USERNAME=YOUR_DOCKER_HUB_USERNAME
# build it
./build.sh
```
### Publishing to DockerHub
```
# tagging
docker run --rm -v "$PWD":/app treeder/bump patch
docker tag $USERNAME/func-sleeper:latest $USERNAME/func-sleeper:`cat VERSION`
# pushing to docker hub
docker push $USERNAME/func-sleeper
```
### Testing image
```
./test.sh
```
## Running it on IronFunctions
### Let's define some environment variables
```
# Set your Function server address
# Eg. 127.0.0.1:8080
FUNCAPI=YOUR_FUNCTIONS_ADDRESS
```
### Running with IronFunctions
With this command we are going to create an application with name `sleeper`.
```
curl -X POST --data '{
"app": {
"name": "sleeper",
}
}' http://$FUNCAPI/v1/apps
```
Now, we can create our route
```
curl -X POST --data '{
"route": {
"image": "'$USERNAME'/func-sleeper",
"path": "/sleeper",
}
}' http://$FUNCAPI/v1/apps/sleeper/routes
```
#### Testing function
Now that we created our IronFunction route, let's test our new route
```
curl -X POST --data '{"sleep": 5}' http://$FUNCAPI/r/sleeper/sleeper
```

4
examples/sleeper/build.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
set -ex
docker build -t iron/func-sleeper .

View File

@@ -0,0 +1,14 @@
require 'json'
payload = STDIN.read
if payload != ""
payload = JSON.parse(payload)
# payload contains checks
if payload["sleep"]
i = payload['sleep'].to_i
puts "Sleeping for #{i} seconds..."
sleep i
puts "I'm awake!"
end
end

View File

@@ -0,0 +1,3 @@
image: iron/func-sleeper
build:
- ./build.sh

View File

@@ -1,8 +0,0 @@
require 'json'
payload = JSON.parse(ENV['PAYLOAD'])
i = payload['sleep'].to_i
puts "Sleeping for #{i} seconds..."
sleep i
puts "I'm awake!"

9
examples/sleeper/test.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -x
./build.sh
PAYLOAD='{"sleep": 5}'
# test it
echo $PAYLOAD | docker run --rm -i -e TEST=1 iron/func-sleeper