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 +1,2 @@
/hello
/func
vendor

View File

@@ -1,6 +1,5 @@
FROM iron/go
WORKDIR /function
ADD hello .
ADD func .
ENTRYPOINT ["./hello"]
ENTRYPOINT ["./func"]

View File

@@ -1,4 +1,77 @@
set -ex
# Hello Function Image (Go Language)
docker run --rm -v "$PWD":/go/src/github.com/treeder/hello -w /go/src/github.com/treeder/hello iron/go:dev go build -o hello
docker build -t iron/hello .
This images compares the payload info with the header.
## Requirements
- IronFunctions API
## Development
### Building image locally
```
# 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-hello-go:latest $USERNAME/func-hello-go:`cat VERSION`
# pushing to docker hub
docker push $USERNAME/func-hello-go
```
### 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-go",
"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
```

View File

@@ -1 +1 @@
0.0.2
0.0.1

View File

@@ -1,8 +1,8 @@
set -ex
#!/bin/bash
set -ex
USERNAME=iron
IMAGE=hello
FUNCPKG=$(pwd | sed "s|$GOPATH/src/||")
# build it
docker run --rm -v "$PWD":/go/src/github.com/iron/hello -w /go/src/github.com/iron/hello iron/go:dev go build -o hello
docker build -t $USERNAME/$IMAGE .
# build image
docker run --rm -v "$PWD":/go/src/$FUNCPKG -w /go/src/$FUNCPKG iron/go:dev go build -o func
docker build -t iron/func-hello-go .

View File

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

View File

@@ -1,17 +0,0 @@
set -ex
USERNAME=iron
IMAGE=hello
# build it
./build.sh
# test it
echo '{"name":"Johnny"}' | docker run --rm -i $USERNAME/hello
# tag it
docker run --rm -v "$PWD":/app treeder/bump patch
version=`cat VERSION`
echo "version: $version"
docker tag $USERNAME/$IMAGE:latest $USERNAME/$IMAGE:$version
# push it
docker push $USERNAME/$IMAGE:latest
docker push $USERNAME/$IMAGE:$version

9
examples/hello-go/test.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -x
./build.sh
PAYLOAD='{"name":"Johnny"}'
# test it
echo $PAYLOAD | docker run --rm -i iron/func-hello-go