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