mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Examples changes (#201)
This commit is contained in:
@@ -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", "hello.rb"]
|
||||
ENTRYPOINT ["ruby", "function.rb"]
|
||||
|
||||
@@ -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
|
||||
@@ -1,23 +1,77 @@
|
||||
This is a worker that just echoes the "input" param in the payload.
|
||||
# Hello Function Image (Ruby)
|
||||
|
||||
eg:
|
||||
This images compares the payload info with the header.
|
||||
|
||||
This input:
|
||||
## Requirements
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Johnny Utah"
|
||||
}
|
||||
```
|
||||
- IronFunctions API
|
||||
|
||||
Will output:
|
||||
## Development
|
||||
|
||||
### Building image locally
|
||||
|
||||
```
|
||||
Hello Johnny Utah!
|
||||
# SET BELOW TO YOUR DOCKER HUB USERNAME
|
||||
USERNAME=YOUR_DOCKER_HUB_USERNAME
|
||||
|
||||
# build it
|
||||
./build.sh
|
||||
```
|
||||
|
||||
## Try it
|
||||
### Publishing to DockerHub
|
||||
|
||||
```
|
||||
echo '{"name":"Johnny"}' | docker run --rm -i iron/hello
|
||||
# tagging
|
||||
docker run --rm -v "$PWD":/app treeder/bump patch
|
||||
docker tag $USERNAME/func-hello-ruby:latest $USERNAME/func-hello-ruby:`cat VERSION`
|
||||
|
||||
# pushing to docker hub
|
||||
docker push $USERNAME/func-hello-ruby
|
||||
```
|
||||
|
||||
### 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 `hello`.
|
||||
|
||||
```
|
||||
curl -X POST --data '{
|
||||
"app": {
|
||||
"name": "hello",
|
||||
}
|
||||
}' http://$FUNCAPI/v1/apps
|
||||
```
|
||||
|
||||
Now, we can create our route
|
||||
|
||||
```
|
||||
curl -X POST --data '{
|
||||
"route": {
|
||||
"image": "'$USERNAME'/func-hello-ruby",
|
||||
"path": "/hello",
|
||||
}
|
||||
}' http://$FUNCAPI/v1/apps/hello/routes
|
||||
```
|
||||
|
||||
#### Testing function
|
||||
|
||||
Now that we created our IronFunction route, let's test our new route
|
||||
|
||||
```
|
||||
curl -X POST --data '{"name": "Johnny"}' http://$FUNCAPI/r/hello/hello
|
||||
```
|
||||
@@ -1 +1 @@
|
||||
0.0.30
|
||||
0.0.1
|
||||
|
||||
4
examples/hello-ruby/build.sh
Executable file
4
examples/hello-ruby/build.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
set -ex
|
||||
|
||||
docker build -t iron/func-hello-ruby .
|
||||
3
examples/hello-ruby/functions.yml
Normal file
3
examples/hello-ruby/functions.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
image: iron/func-hello-ruby
|
||||
build:
|
||||
- ./build.sh
|
||||
@@ -1,9 +0,0 @@
|
||||
USERNAME=iron
|
||||
# build it
|
||||
docker build -t $USERNAME/hello:ruby .
|
||||
# test it
|
||||
echo '{"name":"Johnny"}' | docker run --rm -i $USERNAME/hello
|
||||
# tag it
|
||||
docker run --rm -v "$PWD":/app treeder/bump patch
|
||||
# push it
|
||||
docker push $USERNAME/hello:ruby
|
||||
9
examples/hello-ruby/test.sh
Executable file
9
examples/hello-ruby/test.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -x
|
||||
|
||||
./build.sh
|
||||
|
||||
PAYLOAD='{"name":"Johnny"}'
|
||||
|
||||
# test it
|
||||
echo $PAYLOAD | docker run --rm -i -e TEST=1 iron/func-hello-ruby
|
||||
Reference in New Issue
Block a user