From b3dd8aff308a84089931a77e1b9e0bc3dfb05cca Mon Sep 17 00:00:00 2001 From: dingjiahuichina Date: Sun, 18 May 2025 20:21:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81Devkit=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=A5=97=E4=BB=B6=E5=BF=AB=E9=80=9F=E9=83=A8=E7=BD=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/devkit-pipeline-v1.1/config.yaml | 47 +++++++++++++++++++ plugins/devkit-pipeline-v1.1/main.yaml | 19 ++++++++ .../workspace/download-package.yml | 33 +++++++++++++ .../workspace/generate-config.yml | 17 +++++++ .../workspace/machine-auto.j2 | 20 ++++++++ .../workspace/run-deploy.yml | 13 +++++ .../workspace/setup-ssh.yml | 32 +++++++++++++ 7 files changed, 181 insertions(+) create mode 100644 plugins/devkit-pipeline-v1.1/config.yaml create mode 100644 plugins/devkit-pipeline-v1.1/main.yaml create mode 100644 plugins/devkit-pipeline-v1.1/workspace/download-package.yml create mode 100644 plugins/devkit-pipeline-v1.1/workspace/generate-config.yml create mode 100644 plugins/devkit-pipeline-v1.1/workspace/machine-auto.j2 create mode 100644 plugins/devkit-pipeline-v1.1/workspace/run-deploy.yml create mode 100644 plugins/devkit-pipeline-v1.1/workspace/setup-ssh.yml diff --git a/plugins/devkit-pipeline-v1.1/config.yaml b/plugins/devkit-pipeline-v1.1/config.yaml new file mode 100644 index 0000000..1bc7682 --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/config.yaml @@ -0,0 +1,47 @@ +all: + children: + controller: + hosts: + # 控制节点只能有一个,可以127.0.0.1 + 192.168.0.10: + ansible_host: 192.168.0.10 + ansible_port: 22 + ansible_user: root + ansible_password: "" + deploy_nodes: + hosts: + # 部署节点可以有任意个,允许包含控制节点,但不可以是127.0.0.1 + 192.168.0.10: + ansible_host: 192.168.0.10 + ansible_port: 22 + ansible_user: root + ansible_password: "" + vars: + pipeline: + download_url: "https://gitee.com/openeuler/devkit-pipeline/releases/download/v1.1/devkit-pipeline-v1.1.tar.gz" + install_dir: "/home/pipeline" + machine_config: + user: root + pkey: /root/.ssh/id_rsa + # 以下的节点IP必须来自deploy_nodes + # 每个项目中的IP可以有多个 + # 如果不希望安装某个项目,请将项目和对应的IP删除或注释 + scanner: + - 192.168.0.10 + c_builder_gcc: + - 192.168.0.10 + c_builder_bisheng_compiler: + - 192.168.0.10 + java_builder_jdk8: + - 192.168.0.10 + java_builder_jdk17: + - 192.168.0.10 + compatibility: + - 192.168.0.10 + tester: + - 192.168.0.10 + devkit: + - 192.168.0.10 + clamav: + - 192.168.0.10 + ansible_ssh_common_args: "-o StrictHostKeyChecking=no" \ No newline at end of file diff --git a/plugins/devkit-pipeline-v1.1/main.yaml b/plugins/devkit-pipeline-v1.1/main.yaml new file mode 100644 index 0000000..69d5d8a --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/main.yaml @@ -0,0 +1,19 @@ +name: devkit-pipeline-v1.1 +version: 1.0.0-1 +description: 部署devkit-pipeline-v1.1工具链 +action: + install: + description: 安装devkit-pipeline-v1.1 + tasks: + - name: 配置SSH免密登录 + playbook: setup-ssh.yml + scope: controller + - name: 下载并解压软件包 + playbook: download-package.yml + scope: controller + - name: 生成machine-auto.yaml配置文件 + playbook: generate-config.yml + scope: controller + - name: 执行部署命令 + playbook: run-deploy.yml + scope: controller \ No newline at end of file diff --git a/plugins/devkit-pipeline-v1.1/workspace/download-package.yml b/plugins/devkit-pipeline-v1.1/workspace/download-package.yml new file mode 100644 index 0000000..a0477b8 --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/workspace/download-package.yml @@ -0,0 +1,33 @@ +--- +- name: Download and extract devkit-pipeline package + hosts: controller + gather_facts: false + vars: + package_name: "{{ pipeline.download_url | basename | regex_replace('\\.tar\\.gz$', '') }}" + tasks: + - name: Ensure SELinux Python bindings are installed + yum: + name: + - python3-libselinux + - tar + - wget + state: present + + - name: Create installation directory + ansible.builtin.file: + path: "{{ pipeline.install_dir }}" + state: directory + mode: '0755' + + - name: Download package + ansible.builtin.get_url: + url: "{{ pipeline.download_url }}" + dest: "{{ pipeline.install_dir }}/{{ package_name }}.tar.gz" + mode: '0644' + + - name: Extract package + ansible.builtin.unarchive: + src: "{{ pipeline.install_dir }}/{{ package_name }}.tar.gz" + dest: "{{ pipeline.install_dir }}" + remote_src: yes + creates: "{{ pipeline.install_dir }}/{{ package_name }}" diff --git a/plugins/devkit-pipeline-v1.1/workspace/generate-config.yml b/plugins/devkit-pipeline-v1.1/workspace/generate-config.yml new file mode 100644 index 0000000..e28e929 --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/workspace/generate-config.yml @@ -0,0 +1,17 @@ +--- +- name: Generate machine-auto.yaml configuration + hosts: controller + vars: + package_name: "{{ pipeline.download_url | basename | regex_replace('\\.tar\\.gz$', '') }}" + tasks: + - name: Create config directory + ansible.builtin.file: + path: "{{ pipeline.install_dir }}/{{ package_name }}/linux" + state: directory + mode: '0755' + + - name: Generate machine-auto.yaml + ansible.builtin.template: + src: machine-auto.j2 + dest: "{{ pipeline.install_dir }}/{{ package_name }}/linux/machine-auto.yaml" + mode: '0644' \ No newline at end of file diff --git a/plugins/devkit-pipeline-v1.1/workspace/machine-auto.j2 b/plugins/devkit-pipeline-v1.1/workspace/machine-auto.j2 new file mode 100644 index 0000000..e8c349b --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/workspace/machine-auto.j2 @@ -0,0 +1,20 @@ +user: {{ pipeline.machine_config.user }} +pkey: {{ pipeline.machine_config.pkey }} +scanner: +{{ pipeline.machine_config.scanner | to_nice_yaml | indent(2) }} +c_builder_gcc: +{{ pipeline.machine_config.c_builder_gcc | to_nice_yaml | indent(2) }} +c_builder_bisheng_compiler: +{{ pipeline.machine_config.c_builder_bisheng_compiler | to_nice_yaml | indent(2) }} +java_builder_jdk8: +{{ pipeline.machine_config.java_builder_jdk8 | to_nice_yaml | indent(2) }} +java_builder_jdk17: +{{ pipeline.machine_config.java_builder_jdk17 | to_nice_yaml | indent(2) }} +compatibility: +{{ pipeline.machine_config.compatibility | to_nice_yaml | indent(2) }} +tester: +{{ pipeline.machine_config.tester | to_nice_yaml | indent(2) }} +devkit: +{{ pipeline.machine_config.devkit | to_nice_yaml | indent(2) }} +clamav: +{{ pipeline.machine_config.clamav | to_nice_yaml | indent(2) }} \ No newline at end of file diff --git a/plugins/devkit-pipeline-v1.1/workspace/run-deploy.yml b/plugins/devkit-pipeline-v1.1/workspace/run-deploy.yml new file mode 100644 index 0000000..cc1f625 --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/workspace/run-deploy.yml @@ -0,0 +1,13 @@ +--- +- name: Run deployment command + hosts: controller + gather_facts: false + vars: + package_name: "{{ pipeline.download_url | basename | regex_replace('\\.tar\\.gz$', '') }}" + tasks: + - name: Execute deploy_tool + ansible.builtin.shell: | + cd {{ pipeline.install_dir }}/{{ package_name }}/linux + ./deploy_tool -f ./machine-auto.yaml + args: + executable: /bin/bash \ No newline at end of file diff --git a/plugins/devkit-pipeline-v1.1/workspace/setup-ssh.yml b/plugins/devkit-pipeline-v1.1/workspace/setup-ssh.yml new file mode 100644 index 0000000..3e4c6db --- /dev/null +++ b/plugins/devkit-pipeline-v1.1/workspace/setup-ssh.yml @@ -0,0 +1,32 @@ +--- +- name: Configure SSH key-based authentication + hosts: controller + gather_facts: false + tasks: + - name: Check if SSH key exists + ansible.builtin.stat: + path: /root/.ssh/id_rsa + register: ssh_key + + - name: Generate SSH key pair if not exists + ansible.builtin.openssh_keypair: + path: /root/.ssh/id_rsa + type: rsa + size: 2048 + force: false + register: keygen_result + when: not ssh_key.stat.exists + + - name: Get public key content + ansible.builtin.shell: cat /root/.ssh/id_rsa.pub + register: public_key + when: keygen_result is changed or ssh_key.stat.exists + + - name: Distribute public key to deploy nodes + ansible.builtin.authorized_key: + user: root + key: "{{ public_key.stdout }}" + state: present + delegate_to: "{{ item }}" + loop: "{{ groups['deploy_nodes'] }}" + when: public_key is defined and public_key.stdout != "" \ No newline at end of file -- Gitee