Serverless-Devs
Serverless-Devs copied to clipboard
Devs本身是不是可以定义一些全局操作
在思考是不是可以引入拓展的能力,在整个项目使用之前和使用之后,进行一些拓展操作。
例如,部署完成之后,可以根据用户的配置,进行某些操作,包括dingding告警,邮件告警,这样用户做完了CD之后就可以在群里看到我们成功失败的信息了?
目前的想法是:
extensions:
finish-deploy:
- plugin: dingding-robot
inputs:
type: ip
hook: http://www.dingding.com
keyword: test
error-deploy:
- plugin: email-robot
pre-deploy:
- run: npm install
path: ./src
名字形式,主要包括:
pre-${mathod}: 执行前执行什么功能post-${mathod}: 执行后执行什么功能(如果失败了就不会被执行)finish-${mathod}: 执行完成执行什么功能(无论成功失败都会执行)error-${mathod}: 执行出错执行什么功能
具体格式包括:
- 插件:
plugin: dingding-robot inputs: type: ip hook: http://www.dingding.com keyword: test - 命令:
run: npm install path: ./src
欢迎讨论
pre-${mathod}: 执行前执行什么功能success-${mathod}: 执行后执行什么功能(如果失败了就不会被执行)complete-${mathod}: 执行完成执行什么功能(无论成功失败都会执行)failed-${mathod}: 执行出错执行什么功能
- 增加全局的actions
- 单个服务下的actions - post进行兼容性变更
- ${mathod}需要支持一个list的形式,例如
pre-[deploy, invoke, local start]待讨论
传递一个list: 0. Service 名称
- 执行时间
- 失败时间
- 执行状态
- 入参
- 出参
- 密钥信息
需求总结
Serverless Devs 的 Yaml 规范,目前支持单 Service 下的 Actions 能力,但是随着时间的发展,这个能力已经没办法逐渐的满足更多的需求,所以:
- 增加全局 Actions 能力
- 细化 Actions 能力
增加全局 Actions 能力
在 yaml 中可以声明以下内容:
actions:
complete-deploy:
- plugin: dingding-robot
args:
type: ip
hook: http://www.dingding.com
keyword: test
fail-deploy:
- plugin: email-robot
pre-deploy:
- run: npm install
path: ./src
主要支持四种形式:
pre-${mathod}: 执行前执行什么功能success-${mathod}: 执行成功后执行什么内容complete-${mathod}: 执行完成执行什么内容fail-${mathod}: 执行失败后执行什么内容
例如,一个 yaml 中有 Service1,Service2,Service3 三个服务,如果配置了:
actions:
pre-deploy:
- action1
complete-deploy:
- action2
success-deploy:
- action3
fail-deploy:
- action4
- 如果 Service1,Service2,Service3 都部署成功,顺序是这样的:
pre-deploy -> Service1,Service2,Service3 -> success-deploy -> complete-deploy - 如果 Service1,部署成功,Service2 部署失败,顺序是这样的:
pre-deploy -> Service1,Service2,-> fail-deploy -> complete-deploy - 如果 Service1,部署成功,Service2 部署失败,fail-deploy 执行失败,顺序是这样的:
pre-deploy -> Service1,Service2,-> fail-deploy -> complete-deploy
在全局变量中,应该给定足够的信息,以供全局插件进行使用:
- pre:
{
"command": "",
"project": {
"projectName": "",
"access": ""
},
"credentials": {},
"args": "",
"argsObj": [],
"services" : [
{
"serviceName": "xxx",
"component": "fc",
"access" ?: "",
"credentials" ?: {},
"actions": {},
"prop": {}
"output" ?: {},
"status" ?:"error" / "success",
}
]
}
- 其他:
{
"command": "",
"project": {
"projectName": "",
"access": ""
},
"credentials": {},
"args": "",
"argsObj": [],
"services" : [
{
"serviceName": "xxx",
"component": "fc",
"access" ?: "",
"credentials" ?: {},
"actions": {},
"prop": {},
"output": {},
"status":"error" / "success",
}
],
// 以下为整体的输出结果
"output": {},
"status":"error" / "success",
}
细化 Actions 能力
目前,actions里面有两种状态:
- pre: 表示执行之前进行,保持现有不变
- post: 表示执行之后进行,保持现有不变,同时弱化post,并升级为
success
除此之外,新增:
- complete: 完成的时候执行
- fail: 失败的时候执行
其中pre, success, complete, fail的执行顺序与上面全局变量的一致。
另外,其参数的基本格式也进行一定的升级
{
"command": "",
"project": {
"projectName": "",
"component": "",
"provider": "",
"access": ""
},
"credentials": {},
"prop": {},
"args": "",
"argsObj": [],
"output": {},
"status":"error" / "success",
}
注意同步更新文档: https://github.com/Serverless-Devs/Serverless-Devs/blob/master/spec/zh/0.0.2/serverless_package_model/package_model.md#%E6%8F%92%E4%BB%B6%E6%A8%A1%E5%9E%8B%E8%A7%84%E8%8C%83
https://github.com/Serverless-Devs/Serverless-Devs/blob/master/spec/en/0.0.2/serverless_package_model/package_model.md#plugin-model-code-specification
https://github.com/devsapp/start-devs-packages/blob/master/readme.md#%E6%8F%92%E4%BB%B6%E5%BC%80%E5%8F%91%E8%AF%B4%E6%98%8E
https://github.com/devsapp/start-devs-packages/blob/master/readme_en.md#Plugin-development-instructions
https://github.com/devsapp/start-devs-packages/blob/master/start-plugin/readme.md
https://github.com/devsapp/start-devs-packages/blob/master/start-plugin/readme_en.md
https://github.com/devsapp/start-devs-packages/blob/master/start-plugin/src/readme.md
https://github.com/devsapp/start-devs-packages/blob/master/start-plugin/src/readme_en.md
3.0 已经实现,使用 @serverless-devs/s3 -g ,欢迎使用3.0版本