https://github.com/zq2599/blog_demos
内容:所有原创文章分类汇总及配套源码,涉及Java、Docker、Kubernetes、DevOPS等;
如下所示,faas其实就是faas-cli的链接,因此,平时输入命令用faas更简单:
[root@node1 template]# ls -l /usr/local/bin/faas
lrwxrwxrwx. 1 root root 23 11月 19 11:06 /usr/local/bin/faas -> /usr/local/bin/faas-cli
faas template pull
执行完毕后,当前目录下出现名为template的文件夹,里面是所有官方模板
[root@node1 21]# ls
template
[root@node1 21]# cd template/
[root@node1 template]# ls
csharp dockerfile go java11 java11-vert-x node node12 php7 python python3 python3-debian ruby
[root@node1 template]# cd ..
[root@node1 21]# tree template/
template/
├── csharp
│ ├── Dockerfile
│ ├── function
│ │ ├── Function.csproj
│ │ └── FunctionHandler.cs
│ ├── Program.cs
│ ├── root.csproj
│ └── template.yml
├── dockerfile
│ ├── function
│ │ └── Dockerfile
│ └── template.yml
...
faas template store list
返回信息如下(太多了,省略部分):
NAME SOURCE DESCRIPTION
csharp openfaas Classic C# template
dockerfile openfaas Classic Dockerfile template
go openfaas Classic Golang template
java8 openfaas Java 8 template
java11 openfaas Java 11 template
rust-http openfaas-incubator Rust HTTP template
bash-streaming openfaas-incubator Bash Streaming template
...
3. 查看当前目录下可用的模板:
```shell
faas new --list
终端显示:
[root@node1 21]# faas new --list
Languages available as templates:
- csharp
- dockerfile
- go
- java11
- java11-vert-x
- node
- node12
- php7
- python
- python3
- python3-debian
- ruby
faas-cli new --lang java11 java-function
成功后,修改此文件添加业务代码:./src/main/Handler.java;
faas-cli template store pull openfaas-incubator/rust-http
以上是模板的基本操作,此刻您可能有疑问:那些都是官方模板,第三方的模板怎么获取?另外如果我想自己做模板给别人用,又该如何操作?这些问题,接下来逐个解答;
4. 下载上述模板仓库的命令(注意,找个干净的文件夹执行命令):
faas template pull https://github.com/zq2599/openfaas-templates
可见就是把仓库地址作为参数放在整个命令的末尾
[root@node1 333]# faas template pull https://github.com/zq2599/openfaas-templates
Fetch templates from repository: https://github.com/zq2599/openfaas-templates at master
2020/11/22 11:19:53 Attempting to expand templates from https://github.com/zq2599/openfaas-templates
2020/11/22 11:19:58 Fetched 2 template(s) : [dockerfile java11extend] from https://github.com/zq2599/openfaas-templates
[root@node1 333]# ls
template
[root@node1 333]# tree template/
template/
├── dockerfile
│ ├── function
│ │ └── Dockerfile
│ └── template.yml
└── java11extend
├── build.gradle
├── Dockerfile
├── function
│ ├── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── settings.gradle
│ └── src
│ ├── main
│ │ └── java
│ │ └── com
│ │ └── openfaas
│ │ └── function
│ │ └── Handler.java
│ └── test
│ └── java
│ └── HandlerTest.java
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── README.md
├── settings.gradle
└── template.yml
16 directories, 17 files
[root@node1 333]# faas new --list
Languages available as templates:
- dockerfile
- java11extend
faas-cli new java11extend-function --lang java11extend -p bolingcavalry
faas-cli build -f ./java11extend-function.yml
控制台输出以下信息,提示镜像制作成功:
Step 29/30 : HEALTHCHECK --interval=5s CMD [ -e /tmp/.lock ] || exit 1
---> Running in 6b68ca763980
Removing intermediate container 6b68ca763980
---> 50cea9002e9c
Step 30/30 : CMD ["fwatchdog"]
---> Running in c2f87a87c8f4
Removing intermediate container c2f87a87c8f4
---> 8094a5064a20
Successfully built 8094a5064a20
Successfully tagged bolingcavalry/java11extend-function:latest
Image: bolingcavalry/java11extend-function:latest built.
[0] < Building java11extend-function done in 81.75s.
[0] Worker done.
Total build time: 81.76s
经历了前面的实战,对于如何制作模板仓库,相信您心中已经有了答案,这里简单小结一下需要遵守的原则:
faas template pull https://github.com/zq2599/openfaas-templates
最后有两处温馨提醒,请注意:
尽管在列表中可以看到java8,但是OpenFaaS的官方文档宣布java8模板已经废弃,不建议使用,如下图红框,文档地址:https://docs.openfaas.com/cli/templates/#java
微信搜索「程序员欣宸」,我是欣宸,期待与您一同畅游Java世界...
https://github.com/zq2599/blog_demos
原文:https://www.cnblogs.com/bolingcavalry/p/15095142.html