联调图形设计化-构建流水线yaml

This commit is contained in:
xxq250 2024-05-24 15:31:29 +08:00
parent 15fc5b84fe
commit 8325fa7367
1 changed files with 286 additions and 444 deletions

View File

@ -82,8 +82,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
def build_pipeline_yaml(pipeline_name, pipeline_json) def build_pipeline_yaml(pipeline_name, pipeline_json)
if pipeline_json.present? if pipeline_json.present?
@pipeline_name = pipeline_name @pipeline_name = pipeline_name
params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) }
on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) }
@on_nodes = build_nodes(on_nodes) @on_nodes = build_nodes(on_nodes)
@steps_nodes = build_nodes(params_nodes) @steps_nodes = build_nodes(params_nodes)
yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding)
@ -97,26 +97,26 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
def build_test_yaml def build_test_yaml
@pipeline_name = "I like it" @pipeline_name = "I like it"
params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["component_name"]) } params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) }
on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["component_name"]) } on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) }
@on_nodes = build_nodes(on_nodes) @on_nodes = build_nodes(on_nodes)
@steps_nodes = [] @steps_nodes = []
params_nodes.each do |input_node| params_nodes.each do |input_node|
# Rails.logger.info "input_node=====0===#{input_node["component_name"]}======#{input_node["in_parameters"]}" # Rails.logger.info "input_node=====0===#{input_node["name"]}======#{input_node["inputs"]}"
node = Action::Node.find_by(name: input_node["component_name"]) node = Action::Node.find_by(name: input_node["name"])
next if node.blank? next if node.blank?
node.cust_name = input_node["component_label"] if input_node["component_label"].present? node.cust_name = input_node["label"] if input_node["label"].present?
run_values = {} run_values = {}
input_values = {} input_values = {}
if input_node["in_parameters"].present? if input_node["inputs"].present?
# Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"]}" Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}"
input_node["in_parameters"].each_key do |input_key| input_node["inputs"].each do |input|
# Rails.logger.info "@in_parameters.input_key===#{input_key}" # Rails.logger.info "@inputs.input_name===#{input[:name]}"
# Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" # Rails.logger.info "@inputs.input_value===#{input["value"]}"
if input_key.to_s.gsub("--", "") == "run" if input[:name].to_s.gsub("--", "") == "run"
run_values = run_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
else else
input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
end end
end end
node.run_values = run_values node.run_values = run_values
@ -166,26 +166,24 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
def build_nodes(params_nodes) def build_nodes(params_nodes)
steps_nodes = [] steps_nodes = []
params_nodes.each do |input_node| params_nodes.each do |input_node|
node = Action::Node.find_by(name: input_node["component_name"]) node = Action::Node.find_by(name: input_node["name"])
next if node.blank? next if node.blank?
node.cust_name = input_node["component_label"] if input_node["component_label"].present? node.cust_name = input_node["labelf"] if input_node["label"].present?
run_values = {} run_values = {}
input_values = {} input_values = {}
if input_node["in_parameters"].present? if input_node["inputs"].present?
Rails.logger.info "@in_parameters=====11===#{input_node["component_name"]}======#{input_node["in_parameters"].keys}" Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}"
input_node["in_parameters"].keys.each do |input_key| input_node["inputs"].each do |input|
# Rails.logger.info "@in_parameters.input_key===#{input_key}" # Rails.logger.info "@inputs.input_name===#{input[:name]}"
# Rails.logger.info "@in_parameters.input_value===#{input_node["in_parameters"][input_key]["value"]}" # Rails.logger.info "@inputs.input_value===#{input["value"]}"
if input_key.to_s.gsub("--", "") == "run" if input[:name].to_s.gsub("--", "") == "run"
run_values = run_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
else else
input_values = input_values.merge({ "#{input_key.gsub("--", "")}": "#{input_node["in_parameters"][input_key]["value"]}" }) input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
end end
end end
node.run_values = run_values node.run_values = run_values
# Rails.logger.info "@input_values node1===#{input_values}"
node.input_values = input_values node.input_values = input_values
# Rails.logger.info "@input_values node===#{node.input_values.to_json}"
end end
steps_nodes.push(node) steps_nodes.push(node)
end end
@ -194,423 +192,267 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController
def demo def demo
{ {
"nodes": [ "nodes": [{
{ "id": "on-schedule-2fcf505",
"id": "git-clone-245734ab", "name": "on-schedule",
"category_id": 1, "full_name": "on-schedule",
"component_name": "on-schedule", "description": " 定时器计划器",
"component_label": "触发器", "icon": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1",
"working_directory": "", "action_node_types_id": 3,
"command": "", "yaml": "",
"in_parameters": { "sort_no": 0,
"--cron": { "use_count": 0,
"type": "str", "inputs": [{
"item_type": "", "id": 8,
"label": "push代码", "name": "cron",
"require": 1, "input_type": "input",
"choice": [], "description": "示例:\r\n- cron: '20 8 * * *'",
"default": "", "is_required": true,
"placeholder": "私有仓库填写ssh地址公有仓库填写https git地址", "value": "- corn: '0 10 * * *'"
"describe": "代码仓库地址", }],
"editable": 1, "x": 586,
"condition": "", "y": 165.328125,
"value": "15 4,5 * * *" "label": "on-schedule",
}, "img": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1",
"--paths-ignore": { "isCluster": false,
"type": "str", "type": "rect-node",
"item_type": "", "size": [110, 36],
"label": "push代码", "labelCfg": {
"require": 1, "style": {
"choice": [], "fill": "transparent",
"default": "", "fontSize": 0,
"placeholder": "私有仓库填写ssh地址公有仓库填写https git地址", "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)",
"describe": "代码仓库地址", "overflow": "hidden",
"editable": 1, "x": -20,
"condition": "", "y": 0,
"value": "**.md" "textAlign": "left",
} "textBaseline": "middle"
}, }
"out_parameters": { },
"--code_output": { "style": {
"type": "str", "active": {
"label": "代码输出路径", "fill": "rgb(247, 250, 255)",
"path": "/code", "stroke": "rgb(95, 149, 255)",
"require": 1, "lineWidth": 2,
"value": "/code" "shadowColor": "rgb(95, 149, 255)",
} "shadowBlur": 10
}, },
"description": "代码拉取组件", "selected": {
"icon_path": "component-icon-1", "fill": "rgb(255, 255, 255)",
"create_by": "admin", "stroke": "rgb(95, 149, 255)",
"create_time": "2024-03-02T05:41:25.000+00:00", "lineWidth": 4,
"update_by": "admin", "shadowColor": "rgb(95, 149, 255)",
"update_time": "2024-03-02T05:41:25.000+00:00", "shadowBlur": 10,
"state": 1, "text-shape": {
"image": "172.20.32.187/pipeline-component/built-in/git:202312071000", "fontWeight": 500
"env_variables": "", }
"x": 532, },
"y": 202, "highlight": {
"label": "代码拉取", "fill": "rgb(223, 234, 255)",
"img": "/assets/images/component-icon-1.png", "stroke": "#4572d9",
"isCluster": false, "lineWidth": 2,
"type": "rect-node", "text-shape": {
"size": [110, 36], "fontWeight": 500
"--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", }
"--branch": "train_ci_test", },
"--depth": "1", "inactive": {
"--code_output": "/code" "fill": "rgb(247, 250, 255)",
}, "stroke": "rgb(191, 213, 255)",
{ "lineWidth": 1
"id": "git-clone-245734ab", },
"category_id": 1, "disable": {
"component_name": "git-clone", "fill": "rgb(250, 250, 250)",
"component_label": "代码拉取", "stroke": "rgb(224, 224, 224)",
"working_directory": "", "lineWidth": 1
"command": "", },
"in_parameters": { "nodeSelected": {
"fill": "red",
}, "shadowColor": "red",
"out_parameters": { "stroke": "red",
"--code_output": { "text-shape": {
"type": "str", "fill": "red",
"label": "代码输出路径", "stroke": "red"
"path": "/code", }
"require": 1, },
"value": "/code" "fill": "#fff",
} "stroke": "transparent",
}, "cursor": "pointer",
"description": "代码拉取组件", "radius": 10,
"icon_path": "component-icon-1", "overflow": "hidden",
"create_by": "admin", "lineWidth": 0.5,
"create_time": "2024-03-02T05:41:25.000+00:00", "shadowColor": "rgba(75,84,137,0.05)",
"update_by": "admin", "shadowBlur": 12
"update_time": "2024-03-02T05:41:25.000+00:00", },
"state": 1, "cron": "- corn: '0 10 * * *'",
"image": "172.20.32.187/pipeline-component/built-in/git:202312071000", "depth": 0
"env_variables": "", }, {
"x": 532, "id": "actions/setup-node@v3-257f29d",
"y": 202, "name": "node",
"label": "代码拉取", "full_name": "actions/setup-node@v3",
"img": "/assets/images/component-icon-1.png", "description": "",
"isCluster": false, "icon": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6",
"type": "rect-node", "action_node_types_id": 1,
"size": [110, 36], "yaml": "",
"--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", "sort_no": 0,
"--branch": "train_ci_test", "use_count": 0,
"--depth": "1", "inputs": [{
"--code_output": "/code" "id": 2,
}, "name": "node-version",
{ "input_type": "select",
"id": "git-clone-245734ab", "is_required": false,
"category_id": 1, "value": 55
"component_name": "setup-java", }],
"component_label": "安装java环境", "x": 608,
"working_directory": "", "y": 357.328125,
"command": "", "label": "node",
"in_parameters": { "img": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6",
"--distribution": { "isCluster": false,
"type": "str", "type": "rect-node",
"item_type": "", "size": [110, 36],
"label": "代码仓库地址", "labelCfg": {
"require": 1, "style": {
"choice": [], "fill": "transparent",
"default": "", "fontSize": 0,
"placeholder": "私有仓库填写ssh地址公有仓库填写https git地址", "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)",
"describe": "代码仓库地址", "overflow": "hidden",
"editable": 1, "x": -20,
"condition": "", "y": 0,
"value": "jdkfile" "textAlign": "left",
}, "textBaseline": "middle"
"--java-version": { }
"type": "str", },
"item_type": "", "style": {
"label": "代码分支/tag", "active": {
"require": 1, "fill": "rgb(247, 250, 255)",
"choice": [], "stroke": "rgb(95, 149, 255)",
"default": "master", "lineWidth": 2,
"placeholder": "", "shadowColor": "rgb(95, 149, 255)",
"describe": "代码分支或者tag", "shadowBlur": 10
"editable": 1, },
"condition": "", "selected": {
"value": "11.0.0" "fill": "rgb(255, 255, 255)",
}, "stroke": "rgb(95, 149, 255)",
"--architecture": { "lineWidth": 4,
"type": "str", "shadowColor": "rgb(95, 149, 255)",
"item_type": "", "shadowBlur": 10,
"label": "克隆深度", "text-shape": {
"require": 0, "fontWeight": 500
"choice": [], }
"default": "1", },
"placeholder": "", "highlight": {
"describe": "代码克隆深度", "fill": "rgb(223, 234, 255)",
"editable": 1, "stroke": "#4572d9",
"condition": "", "lineWidth": 2,
"value": "x64" "text-shape": {
}, "fontWeight": 500
"--mvn-toolchain-vendor": { }
"type": "str", },
"item_type": "", "inactive": {
"label": "ssh私钥", "fill": "rgb(247, 250, 255)",
"require": 0, "stroke": "rgb(191, 213, 255)",
"choice": [], "lineWidth": 1
"default": "1", },
"placeholder": "", "disable": {
"describe": "ssh私钥确保ssh公钥已经托管到代码平台否则可能拉取失败", "fill": "rgb(250, 250, 250)",
"editable": 1, "stroke": "rgb(224, 224, 224)",
"value": "Oracle" "lineWidth": 1
} },
}, "nodeSelected": {
"out_parameters": { "fill": "red",
"--code_output": { "shadowColor": "red",
"type": "str", "stroke": "red",
"label": "代码输出路径", "text-shape": {
"path": "/code", "fill": "red",
"require": 1, "stroke": "red"
"value": "/code" }
} },
}, "fill": "#fff",
"description": "代码拉取组件", "stroke": "transparent",
"icon_path": "component-icon-1", "cursor": "pointer",
"create_by": "admin", "radius": 10,
"create_time": "2024-03-02T05:41:25.000+00:00", "overflow": "hidden",
"update_by": "admin", "lineWidth": 0.5,
"update_time": "2024-03-02T05:41:25.000+00:00", "shadowColor": "rgba(75,84,137,0.05)",
"state": 1, "shadowBlur": 12
"image": "172.20.32.187/pipeline-component/built-in/git:202312071000", },
"env_variables": "", "depth": 0,
"x": 532, "node-version": 55
"y": 202, }],
"label": "代码拉取", "edges": [{
"img": "/assets/images/component-icon-1.png", "source": "on-schedule-2fcf505",
"isCluster": false, "target": "actions/setup-node@v3-257f29d",
"type": "rect-node", "style": {
"size": [110, 36], "active": {
"--code_path": "https://openi.pcl.ac.cn/somunslotus/somun202304241505581.git", "stroke": "rgb(95, 149, 255)",
"--branch": "train_ci_test", "lineWidth": 1
"--depth": "1", },
"--code_output": "/code" "selected": {
}, "stroke": "rgb(95, 149, 255)",
{ "lineWidth": 2,
"id": "git-clone-245734ab", "shadowColor": "rgb(95, 149, 255)",
"category_id": 1, "shadowBlur": 10,
"component_name": "shell", "text-shape": {
"component_label": "执行shell命令", "fontWeight": 500
"working_directory": "", }
"command": "", },
"in_parameters": { "highlight": {
"--run": { "stroke": "rgb(95, 149, 255)",
"type": "str", "lineWidth": 2,
"item_type": "", "text-shape": {
"label": "代码仓库地址", "fontWeight": 500
"require": 1, }
"choice": [], },
"default": "", "inactive": {
"placeholder": "私有仓库填写ssh地址公有仓库填写https git地址", "stroke": "rgb(234, 234, 234)",
"describe": "代码仓库地址", "lineWidth": 1
"editable": 1, },
"condition": "", "disable": {
"value": "service nginx restart" "stroke": "rgb(245, 245, 245)",
} "lineWidth": 1
} },
}, "endArrow": {
{ "path": "M 6,0 L 9,-1.5 L 9,1.5 Z",
"id": "git-clone-245734ab", "d": 4.5,
"category_id": 1, "fill": "#CDD0DC"
"component_name": "shell", },
"component_label": "执行shell命令", "cursor": "pointer",
"working_directory": "", "lineWidth": 1,
"command": "", "opacity": 1,
"in_parameters": { "stroke": "#CDD0DC",
"--run": { "radius": 1
"type": "str", },
"item_type": "", "nodeStateStyle": {
"label": "代码仓库地址", "hover": {
"require": 1, "opacity": 1,
"choice": [], "stroke": "#8fe8ff"
"default": "", }
"placeholder": "私有仓库填写ssh地址公有仓库填写https git地址", },
"describe": "代码仓库地址", "labelCfg": {
"editable": 1, "autoRotate": true,
"condition": "", "style": {
"value": "echo env" "fontSize": 10,
} "fill": "#FFF"
} }
}, },
{ "id": "edge-0.96904321945951241716516719464",
"id": "git-clone-245734ab", "startPoint": {
"category_id": 1, "x": 586,
"component_name": "scp", "y": 183.578125,
"component_label": "scp", "anchorIndex": 1
"working_directory": "", },
"command": "", "endPoint": {
"in_parameters": { "x": 608,
"--host": { "y": 339.078125,
"type": "str", "anchorIndex": 0
"item_type": "", },
"label": "代码仓库地址", "sourceAnchor": 1,
"require": 1, "targetAnchor": 0,
"choice": [], "type": "cubic-vertical",
"default": "", "curveOffset": [0, 0],
"placeholder": "私有仓库填写ssh地址公有仓库填写https git地址", "curvePosition": [0.5, 0.5],
"describe": "代码仓库地址", "minCurveOffset": [0, 0]
"editable": 1, }],
"condition": "", "combos": []
"value": "192.168.1.114"
}
}
}
],
# "edges": [
# {
# "source": "git-clone-245734ab",
# "target": "model-train-09b1491",
# "style": {
# "active": {
# "stroke": "rgb(95, 149, 255)",
# "lineWidth": 1
# },
# "selected": {
# "stroke": "rgb(95, 149, 255)",
# "lineWidth": 2,
# "shadowColor": "rgb(95, 149, 255)",
# "shadowBlur": 10,
# "text-shape": {
# "fontWeight": 500
# }
# },
# "highlight": {
# "stroke": "rgb(95, 149, 255)",
# "lineWidth": 2,
# "text-shape": {
# "fontWeight": 500
# }
# },
# "inactive": {
# "stroke": "rgb(234, 234, 234)",
# "lineWidth": 1
# },
# "disable": {
# "stroke": "rgb(245, 245, 245)",
# "lineWidth": 1
# },
# "endArrow": {
# "path": "M 6,0 L 9,-1.5 L 9,1.5 Z",
# "d": 4.5,
# "fill": "#CDD0DC"
# },
# "cursor": "pointer",
# "lineWidth": 1,
# "opacity": 1,
# "stroke": "#CDD0DC",
# "radius": 1
# },
# "nodeStateStyle": {
# "hover": {
# "opacity": 1,
# "stroke": "#8fe8ff"
# }
# },
# "labelCfg": {
# "autoRotate": true,
# "style": {
# "fontSize": 10,
# "fill": "#FFF"
# }
# },
# "id": "edge-0.11773197923997381714446043619",
# "startPoint": {
# "x": 532,
# "y": 220.25,
# "anchorIndex": 1
# },
# "endPoint": {
# "x": 530,
# "y": 304.75,
# "anchorIndex": 0
# },
# "targetAnchor": 0,
# "type": "cubic-vertical",
# "curveOffset": [0, 0],
# "curvePosition": [0.5, 0.5],
# "minCurveOffset": [0, 0],
# "depth": 0
# },
# {
# "source": "model-train-09b1491",
# "target": "model-evaluate-b401ff0",
# "style": {
# "active": {
# "stroke": "rgb(95, 149, 255)",
# "lineWidth": 1
# },
# "selected": {
# "stroke": "rgb(95, 149, 255)",
# "lineWidth": 2,
# "shadowColor": "rgb(95, 149, 255)",
# "shadowBlur": 10,
# "text-shape": {
# "fontWeight": 500
# }
# },
# "highlight": {
# "stroke": "rgb(95, 149, 255)",
# "lineWidth": 2,
# "text-shape": {
# "fontWeight": 500
# }
# },
# "inactive": {
# "stroke": "rgb(234, 234, 234)",
# "lineWidth": 1
# },
# "disable": {
# "stroke": "rgb(245, 245, 245)",
# "lineWidth": 1
# },
# "endArrow": {
# "path": "M 6,0 L 9,-1.5 L 9,1.5 Z",
# "d": 4.5,
# "fill": "#CDD0DC"
# },
# "cursor": "pointer",
# "lineWidth": 1,
# "opacity": 1,
# "stroke": "#CDD0DC",
# "radius": 1
# },
# "nodeStateStyle": {
# "hover": {
# "opacity": 1,
# "stroke": "#8fe8ff"
# }
# },
# "labelCfg": {
# "autoRotate": true,
# "style": {
# "fontSize": 10,
# "fill": "#FFF"
# }
# },
# "id": "edge-0.28238605806531771714446047075",
# "startPoint": {
# "x": 530,
# "y": 341.25,
# "anchorIndex": 1
# },
# "endPoint": {
# "x": 520,
# "y": 431.75,
# "anchorIndex": 0
# },
# "targetAnchor": 0,
# "type": "cubic-vertical",
# "curveOffset": [0, 0],
# "curvePosition": [0.5, 0.5],
# "minCurveOffset": [0, 0],
# "depth": 0
# }
# ]
} }
end end
end end