Sleeper update to use fn tool (#372)

* Updated sleeper to use fn tool

* sending something to stdout
This commit is contained in:
Travis Reeder
2016-12-01 08:54:06 -08:00
committed by C Cirello
parent 44ebaed7ca
commit dbb6c4001a
6 changed files with 11 additions and 90 deletions

View File

@@ -1,77 +1,10 @@
# Sleeper Function Image
This images compares the payload info with the header.
This function sleeps for some number of seconds that you pass in.
## Requirements
- IronFunctions API
## Development
### Building image locally
Test it with:
```
# 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
```sh
fn build
echo '{"sleep": 5}' | fn run
```

View File

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

View File

@@ -0,0 +1,2 @@
name: iron/sleeper
version: 0.0.2

View File

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

View File

@@ -7,8 +7,10 @@ if payload != ""
# payload contains checks
if payload["sleep"]
i = payload['sleep'].to_i
puts "Sleeping for #{i} seconds..."
STDERR.puts "Sleeping for #{i} seconds..."
sleep i
puts "I'm awake!"
puts "I'm awake!" # sending this to stdout for sync response
end
else
STDERR.puts "ERROR: please pass in a sleep value: {\"sleep\": 5}"
end

View File

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