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:
3
examples/hello-go/.gitignore
vendored
3
examples/hello-go/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/hello
|
||||
/func
|
||||
vendor
|
||||
@@ -1,6 +1,5 @@
|
||||
FROM iron/go
|
||||
|
||||
WORKDIR /function
|
||||
ADD hello .
|
||||
ADD func .
|
||||
|
||||
ENTRYPOINT ["./hello"]
|
||||
ENTRYPOINT ["./func"]
|
||||
@@ -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
|
||||
```
|
||||
@@ -1 +1 @@
|
||||
0.0.2
|
||||
0.0.1
|
||||
@@ -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 .
|
||||
3
examples/hello-go/functions.yml
Normal file
3
examples/hello-go/functions.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
image: iron/func-hello-gp
|
||||
build:
|
||||
- ./build.sh
|
||||
@@ -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
9
examples/hello-go/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 iron/func-hello-go
|
||||
Reference in New Issue
Block a user