mirror of
https://github.com/openfaas/faas.git
synced 2025-06-17 12:46:59 +00:00
Using faas-cli new for function generation
Signed-off-by: Jono Finger <jono@foodnotblogs.com>
This commit is contained in:
parent
78c8451df2
commit
a024d4a6fb
@ -45,74 +45,67 @@ Here we are using a basic local registry. You can deploy it elsewhere and use vo
|
|||||||
|
|
||||||
This is a helper for using and deploying functions to OpenFaaS.
|
This is a helper for using and deploying functions to OpenFaaS.
|
||||||
|
|
||||||
On a Mac if you're using brew then you can type in
|
|
||||||
```
|
|
||||||
$ brew install faas-cli
|
|
||||||
```
|
|
||||||
|
|
||||||
On Linux
|
On Linux
|
||||||
|
|
||||||
```
|
```
|
||||||
$ curl -sSL https://cli.openfaas.com | sh
|
$ curl -sSL https://cli.openfaas.com | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
On a Mac if you're using brew then you can type in
|
||||||
|
```
|
||||||
|
$ brew install faas-cli
|
||||||
|
```
|
||||||
|
|
||||||
## Create a function
|
## Create a function
|
||||||
|
|
||||||
|
Generate function from a template
|
||||||
|
|
||||||
```
|
```
|
||||||
$ mkdir -p ~/functions/hello-python
|
$ mkdir functions && cd ~/functions
|
||||||
$ cd ~/functions
|
$ faas-cli new hello-python --lang=python --gateway=http://localhost:8080
|
||||||
```
|
```
|
||||||
|
|
||||||
*hello-python/handler.py*
|
Update the print method in *hello-python/handler.py*
|
||||||
```
|
```
|
||||||
import socket
|
import socket
|
||||||
def handle(req):
|
def handle(req):
|
||||||
print("Hello world from " + socket.gethostname())
|
print("Hello world from " + socket.gethostname())
|
||||||
```
|
```
|
||||||
|
|
||||||
*stack.yml*
|
Update the image in *hello-python.yml* to read
|
||||||
```
|
```
|
||||||
provider:
|
image: localhost:5000/hello-python
|
||||||
name: faas
|
|
||||||
gateway: http://localhost:8080
|
|
||||||
|
|
||||||
functions:
|
|
||||||
hello-python:
|
|
||||||
lang: python
|
|
||||||
handler: ./hello-python/
|
|
||||||
image: localhost:5000/faas-hello-python
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Let's build the function
|
Let's build the function
|
||||||
```
|
```
|
||||||
$ faas-cli build -f ./stack.yml
|
$ faas-cli build -f hello-python.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
Upload the function to our registry
|
Upload the function to our registry
|
||||||
```
|
```
|
||||||
$ faas-cli push -f ./stack.yml
|
$ faas-cli push -f hello-python.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
Check that the image made it to the registry
|
Check that the image made it to the registry
|
||||||
```
|
```
|
||||||
$ curl localhost:5000/v2/faas-hello-python/tags/list
|
$ curl localhost:5000/v2/hello-python/tags/list
|
||||||
{"name":"faas-hello-python","tags":["latest"]}
|
{"name":"hello-python","tags":["latest"]}
|
||||||
```
|
```
|
||||||
|
|
||||||
Now we will delete the local image to be sure the deployment happens from the registry
|
Now we will delete the local image to be sure the deployment happens from the registry
|
||||||
```
|
```
|
||||||
$ docker rmi localhost:5000/faas-hello-python
|
$ docker rmi localhost:5000/hello-python
|
||||||
$ docker images | grep hello | wc -l
|
$ docker images | grep hello | wc -l
|
||||||
0
|
0
|
||||||
```
|
```
|
||||||
|
|
||||||
Deploy the function from the registry
|
Deploy the function from the registry
|
||||||
```
|
```
|
||||||
$ faas-cli deploy -f ./stack.yml
|
$ faas-cli deploy -f hello-python.yml
|
||||||
Deploying: hello-python.
|
Deploying: hello-python.
|
||||||
No existing service to remove
|
|
||||||
Deployed.
|
Deployed. 200 OK.
|
||||||
200 OK
|
|
||||||
URL: http://localhost:8080/function/hello-python
|
URL: http://localhost:8080/function/hello-python
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -132,9 +125,9 @@ def handle(req):
|
|||||||
```
|
```
|
||||||
Now we can rebuild, push and deploy it to the swarm.
|
Now we can rebuild, push and deploy it to the swarm.
|
||||||
```
|
```
|
||||||
$ faas-cli build -f ./stack.yml && \
|
$ faas-cli build -f hello-python.yml && \
|
||||||
faas-cli push -f ./stack.yml && \
|
faas-cli push -f hello-python.yml && \
|
||||||
faas-cli deploy -f ./stack.yml
|
faas-cli deploy -f hello-python.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
See that the update works
|
See that the update works
|
||||||
|
Loading…
x
Reference in New Issue
Block a user