Serverless-Devs icon indicating copy to clipboard operation
Serverless-Devs copied to clipboard

Devs本身是不是可以定义一些全局操作

Open anycodes opened this issue 3 years ago • 5 comments

在思考是不是可以引入拓展的能力,在整个项目使用之前和使用之后,进行一些拓展操作。

例如,部署完成之后,可以根据用户的配置,进行某些操作,包括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
    

anycodes avatar Dec 29 '21 04:12 anycodes

欢迎讨论

anycodes avatar Dec 29 '21 04:12 anycodes

  • pre-${mathod} : 执行前执行什么功能
  • success-${mathod} : 执行后执行什么功能(如果失败了就不会被执行)
  • complete-${mathod} : 执行完成执行什么功能(无论成功失败都会执行)
  • failed-${mathod} : 执行出错执行什么功能
  1. 增加全局的actions
  2. 单个服务下的actions - post进行兼容性变更
  3. ${mathod}需要支持一个list的形式,例如pre-[deploy, invoke, local start]

    待讨论

anycodes avatar Apr 24 '22 10:04 anycodes

传递一个list: 0. Service 名称

  1. 执行时间
  2. 失败时间
  3. 执行状态
  4. 入参
  5. 出参
  6. 密钥信息

anycodes avatar Apr 24 '22 10:04 anycodes

需求总结

Serverless Devs 的 Yaml 规范,目前支持单 Service 下的 Actions 能力,但是随着时间的发展,这个能力已经没办法逐渐的满足更多的需求,所以:

  1. 增加全局 Actions 能力
  2. 细化 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",
}

anycodes avatar Apr 24 '22 13:04 anycodes

注意同步更新文档: 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

anycodes avatar Apr 24 '22 13:04 anycodes

3.0 已经实现,使用 @serverless-devs/s3 -g ,欢迎使用3.0版本

heimanba avatar Dec 04 '23 03:12 heimanba