mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Updated sleeper to use fn tool
This commit is contained in:
@@ -1,77 +1,10 @@
|
|||||||
# Sleeper Function Image
|
# 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
|
Test it with:
|
||||||
|
|
||||||
- IronFunctions API
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
### Building image locally
|
|
||||||
|
|
||||||
```
|
```sh
|
||||||
# SET BELOW TO YOUR DOCKER HUB USERNAME
|
fn build
|
||||||
USERNAME=YOUR_DOCKER_HUB_USERNAME
|
echo '{"sleep": 5}' | fn run
|
||||||
|
|
||||||
# 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
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
docker build -t iron/func-sleeper .
|
|
||||||
2
examples/sleeper/func.yaml
Normal file
2
examples/sleeper/func.yaml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name: iron/sleeper
|
||||||
|
version: 0.0.2
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
image: iron/func-sleeper
|
|
||||||
build:
|
|
||||||
- ./build.sh
|
|
||||||
@@ -7,8 +7,10 @@ if payload != ""
|
|||||||
# payload contains checks
|
# payload contains checks
|
||||||
if payload["sleep"]
|
if payload["sleep"]
|
||||||
i = payload['sleep'].to_i
|
i = payload['sleep'].to_i
|
||||||
puts "Sleeping for #{i} seconds..."
|
STDERR.puts "Sleeping for #{i} seconds..."
|
||||||
sleep i
|
sleep i
|
||||||
puts "I'm awake!"
|
STDERR.puts "I'm awake!"
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
STDERR.puts "ERROR: please pass in a sleep value: {\"sleep\": 5}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user