openfaas 简单试用
1. 安装 faas-cli
参考以前文章,或者使用官方的shell脚本
2. 简单例子
mkdir rong
cd rong
faas-cli new rong --lang python // 默认会有简单的测试code
// 生成的项目代码
rong rong.yml template
// 完整目录如下,部分是不需要的,只是一些模板,我们需要的就是Python 的
├── rong
│ ├── handler.py
│ └── requirements.txt
├── rong.yml
└── template
├── csharp
│ ├── Dockerfile
│ ├── function
│ │ ├── Function.csproj
│ │ └── FunctionHandler.cs
│ ├── Program.cs
│ └── root.csproj
├── go
│ ├── Dockerfile
│ ├── function
│ │ └── handler.go
│ └── main.go
├── node
│ ├── build.sh
│ ├── Dockerfile
│ ├── function
│ │ ├── handler.js
│ │ └── package.json
│ ├── index.js
│ └── package.json
├── node-arm64
│ ├── build.sh
│ ├── Dockerfile
│ ├── function
│ │ ├── handler.js
│ │ └── package.json
│ ├── index.js
│ └── package.json
├── node-armhf
│ └── Dockerfile
├── python
│ ├── Dockerfile
│ ├── function
│ │ ├── handler.py
│ │ └── requirements.txt
│ ├── index.py
│ └── requirements.txt
├── python3
│ ├── Dockerfile
│ ├── function
│ │ ├── handler.py
│ │ ├── __init__.py
│ │ └── requirements.txt
│ ├── index.py
│ └── requirements.txt
├── python-armhf
│ └── Dockerfile
└── ruby
├── Dockerfile
├── function
│ ├── Gemfile
│ └── handler.rb
├── Gemfile
└── index.rb
// 构建
faas-cli build -f ./rong.yml
// 具体的输出
[0] > Building: rong.
Clearing temporary build folder: ./build/rong/
Preparing ./rong/ ./build/rong/function
Building: rong with python template. Please wait..
docker build -t rong .
Sending build context to Docker daemon 6.144kB
Step 1/15 : FROM python:2.7-alpine
---> 9b06bbaac1c7
Step 2/15 : RUN apk --no-cache add curl && echo "Pulling watchdog binary from Github." && curl -sSL https://github.com/openfaas/faas/releases/download/0.6.1/fwatchdog > /usr/bin/fwatchdog && chmod +x /usr/bin/fwatchdog && apk del curl --no-cache
---> Using cache
---> bd048b13c8ba
Step 3/15 : WORKDIR /root/
---> Using cache
---> 54c96a75a92e
Step 4/15 : COPY index.py .
---> Using cache
---> b6f064e7ff22
Step 5/15 : COPY requirements.txt .
---> Using cache
---> c844fec1e035
Step 6/15 : RUN pip install -r requirements.txt
---> Using cache
---> ca4c6044fa4e
Step 7/15 : COPY function function
---> Using cache
---> 5cd07cf272ff
Step 8/15 : RUN touch ./function/__init__.py
---> Using cache
---> 9d4dd7aee98b
Step 9/15 : WORKDIR /root/function/
---> Using cache
---> 4a1374f1c1f5
Step 10/15 : COPY function/requirements.txt .
---> Using cache
---> 8c0facae743b
Step 11/15 : RUN pip install -r requirements.txt
---> Using cache
---> 62943c5906f8
Step 12/15 : WORKDIR /root/
---> Using cache
---> 907178d97644
Step 13/15 : ENV fprocess "python index.py"
---> Using cache
---> d65f459a52a3
Step 14/15 : HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1
---> Using cache
---> 3e19415c84b6
Step 15/15 : CMD fwatchdog
---> Using cache
---> e85c978e99a4
Successfully built e85c978e99a4
Successfully tagged rong:latest
Image: rong built.
[0] < Builder done.
// 发布
faas-cli deploy -f ./rong.yml
// 返回信息如下
Deploying: rong.
No existing service to remove
Deployed.
URL: http://localhost:8080/function/rong
200 OK
3. 使用
直接点击rong 输入参数,可以看到输出参数
![](https://images2017.cnblogs.com/blog/562987/201710/562987-20171008120840434-1287555385.png)