diff --git a/examples/sleeper/README.md b/examples/sleeper/README.md index 4ee6d371b..5a9137de3 100644 --- a/examples/sleeper/README.md +++ b/examples/sleeper/README.md @@ -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 ``` diff --git a/examples/sleeper/build.sh b/examples/sleeper/build.sh deleted file mode 100755 index c062b83ee..000000000 --- a/examples/sleeper/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -ex - -docker build -t iron/func-sleeper . \ No newline at end of file diff --git a/examples/sleeper/func.yaml b/examples/sleeper/func.yaml new file mode 100644 index 000000000..c6c42b691 --- /dev/null +++ b/examples/sleeper/func.yaml @@ -0,0 +1,2 @@ +name: iron/sleeper +version: 0.0.2 diff --git a/examples/sleeper/func.yml b/examples/sleeper/func.yml deleted file mode 100644 index d3ac44833..000000000 --- a/examples/sleeper/func.yml +++ /dev/null @@ -1,3 +0,0 @@ -image: iron/func-sleeper -build: - - ./build.sh \ No newline at end of file diff --git a/examples/sleeper/function.rb b/examples/sleeper/function.rb index bdb56cd3d..12506b30e 100644 --- a/examples/sleeper/function.rb +++ b/examples/sleeper/function.rb @@ -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!" + STDERR.puts "I'm awake!" end +else + STDERR.puts "ERROR: please pass in a sleep value: {\"sleep\": 5}" end diff --git a/examples/sleeper/test.sh b/examples/sleeper/test.sh deleted file mode 100755 index e1c80fa6c..000000000 --- a/examples/sleeper/test.sh +++ /dev/null @@ -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 \ No newline at end of file