feat: add export copy func (#2875)

feat: add export copy func



feat: add export copy func

Signed-off-by: xuesongzuo@yunify.com <xuesongzuo@yunify.com>
This commit is contained in:
zuoxuesong-worker 2025-11-28 15:58:00 +08:00 committed by GitHub
parent 867aca2b7d
commit bd780ee397
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 296 additions and 6 deletions

View File

@ -15,7 +15,5 @@
- localhost
roles:
- download
tasks:
- name: Export artifact
command: |
cd {{ .binary_dir }} && tar -czvf {{ .artifact_file }} *
- copy

View File

@ -0,0 +1,176 @@
- name: Binary | Ensure etcd binary is present
tags: ["etcd"]
loop: "{{ .download.arch | toJson }}"
when:
- .etcd.deployment_type | eq "external"
- .etcd.etcd_version | empty | not
command: |
artifact_name={{ get .download.artifact_url.etcd .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/etcd/{{ .etcd.etcd_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/etcd/{{ .etcd.etcd_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure Kubernetes binaries are present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when: .kubernetes.kube_version | empty | not
command: |
kube_path={{ .binary_dir }}/kube/{{ .kubernetes.kube_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/kube/{{ .kubernetes.kube_version }}/{{ .item }}
mkdir -p $target_path
cp $kube_path/kubelet $target_path/
cp $kube_path/kubeadm $target_path/
cp $kube_path/kubectl $target_path/
- name: Binary | Ensure CNI plugins are present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when: .cni.cni_plugins_version | empty | not
command: |
artifact_name={{ get .download.artifact_url.cni_plugins .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cni/plugins/{{ .cni.cni_plugins_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/plugins/{{ .cni.cni_plugins_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure Helm binary is present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when: .kubernetes.helm_version | empty | not
command: |
artifact_name={{ get .download.artifact_url.helm .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/helm/{{ .kubernetes.helm_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/helm/{{ .kubernetes.helm_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure crictl binary is present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when: .cri.crictl_version | empty | not
command: |
artifact_name={{ get .download.artifact_url.crictl .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/crictl/{{ .cri.crictl_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/crictl/{{ .cri.crictl_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure Docker binary is present
tags: ["kubernetes","image_registry"]
loop: "{{ .download.arch | toJson }}"
when:
- .cri.docker_version | empty | not
- or (.image_registry.type | empty | not) (.cri.container_manager | eq "docker")
command: |
artifact_name={{ get .download.artifact_url.docker .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/docker/{{ .cri.docker_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/docker/{{ .cri.docker_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure cri-dockerd binary is present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when:
- .cri.cridockerd_version | empty | not
- .cri.container_manager | eq "docker"
- .kubernetes.kube_version | semverCompare ">=v1.24.0"
command: |
artifact_name={{ get .download.artifact_url.cridockerd .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cri-dockerd/{{ .cri.cridockerd_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cri-dockerd/{{ .cri.cridockerd_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure containerd binary is present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when:
- .cri.containerd_version | empty | not
- .cri.container_manager | eq "containerd"
command: |
artifact_name={{ get .download.artifact_url.containerd .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/containerd/{{ .cri.containerd_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/containerd/{{ .cri.containerd_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure runc binary is present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when:
- .cri.runc_version | empty | not
- .cri.container_manager | eq "containerd"
command: |
artifact_name={{ get .download.artifact_url.runc .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/runc/{{ .cri.runc_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/runc/{{ .cri.runc_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure calicoctl binary is present
tags: ["kubernetes"]
loop: "{{ .download.arch | toJson }}"
when:
- .cni.calico_version | empty | not
- .cni.type | eq "calico"
command: |
artifact_name=calicoctl
artifact_path={{ .binary_dir }}/cni/calico/{{ .cni.calico_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/calico/{{ .cni.calico_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure Docker Registry binary is present
tags: ["image_registry"]
loop: "{{ .download.arch | toJson }}"
when:
- .image_registry.docker_registry_version | empty | not
- .image_registry.type | eq "docker-registry"
command: |
artifact_name={{ get .download.artifact_url.docker_registry .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/image-registry/docker-registry/{{ .image_registry.docker_registry_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/docker-registry/{{ .image_registry.docker_registry_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Binary | Ensure docker-compose binary is present
tags: ["image_registry"]
loop: "{{ .download.arch | toJson }}"
when:
- .cri.dockercompose_version | empty | not
- .image_registry.type | eq "harbor"
command: |
compose_name=docker-compose
compose_path={{ .binary_dir }}/image-registry/docker-compose/{{ .cri.dockercompose_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/docker-compose/{{ .cri.dockercompose_version }}/{{ .item }}
mkdir -p $target_path
cp $compose_path/$compose_name $target_path/
- name: Binary | Ensure Harbor binary is present
tags: ["image_registry"]
loop: "{{ .download.arch | toJson }}"
when:
- .image_registry.harbor_version | empty | not
- .image_registry.type | eq "harbor"
command: |
harbor_name={{ get .download.artifact_url.harbor .item | splitList "/" | last }}
harbor_path={{ .binary_dir }}/image-registry/harbor/{{ .image_registry.harbor_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/harbor/{{ .image_registry.harbor_version }}/{{ .item }}
mkdir -p $target_path
cp $harbor_path/$harbor_name $target_path/
- name: Binary | Ensure keepalived binary is present
tags: ["image_registry"]
loop: "{{ .download.arch | toJson }}"
when:
- .image_registry.keepalived_version | empty | not
- .image_registry.ha_vip | empty | not
- .groups.image_registry | len | lt 1
command: |
artifact_name={{ get .download.artifact_url.keepalived .item | splitList "/" | last }}
artifact_path={{ .binary_dir }}/image-registry/keepalived/{{ .keepalived_version }}/{{ .item }}
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/keepalived/{{ .keepalived_version }}/{{ .item }}
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/

View File

@ -0,0 +1,66 @@
---
- name: Helm | Ensure the Calico binary is available
when:
- .cni.calico_version | empty | not
- .cni.type | eq "calico"
command: |
artifact_name={{ .download.artifact_url.calico | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cni/calico
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/calico
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Helm | Ensure the Cilium binary is available
when:
- .cni.cilium_version | empty | not
- .cni.type | eq "cilium"
command: |
artifact_name={{ .download.artifact_url.cilium | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cni/cilium
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/cilium
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Helm | Ensure the Flannel binary is available
when:
- .cni.flannel_version | empty | not
- .cni.type | eq "flannel"
command: |
artifact_name={{ .download.artifact_url.flannel | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cni/flannel
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/flannel
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Helm | Ensure the Kube-OVN binary is available
when:
- .kubeovn_version | empty | not
- .cni.type | eq "kubeovn"
command: |
artifact_name={{ .download.artifact_url.kubeovn | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cni/kubeovn
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/kubeovn
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Helm | Ensure the Hybridnet binary is available
when:
- .cni.hybridnet_version | empty | not
- .cni.type | eq "hybridnet"
command: |
artifact_name={{ .download.artifact_url.hybridnet | splitList "/" | last }}
artifact_path={{ .binary_dir }}/cni/hybridnet
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/hybridnet
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/
- name: Helm | Ensure the NFS Provisioner binary is available
when:
- .storage_class.nfs_provisioner_version | empty | not
- .storage_class.nfs.enabled
command: |
artifact_name={{ .download.artifact_url.nfs_provisioner | splitList "/" | last }}
artifact_path={{ .binary_dir }}/sc
target_path={{ .artifact_file_dir }}/kubekey/kubekey/sc
mkdir -p $target_path
cp $artifact_path/$artifact_name $target_path/

View File

@ -0,0 +1,12 @@
- name: Image | Ensure container images is available
image:
copy:
from:
path: >-
{{ .binary_dir }}/images/
manifests: "{{ .image_manifests | toJson }}"
to:
path: >-
{{ .artifact_file_dir }}/kubekey/kubekey/images/
when:
- .image_manifests | default list | empty | not

View File

@ -0,0 +1,10 @@
---
- name: ISO | Ensure ISO files is available
when: .download.iso_url.urls | empty | not
loop: "{{ .download.iso_url.urls | toJson }}"
command: |
iso_path={{ .binary_dir }}/repository/{{ .item | splitList "/" | last }}
if [ ! -f {{ .artifact_file_dir }}/kubekey/kubekey/repository/ ];then
mkdir -p {{ .artifact_file_dir }}/kubekey/kubekey/repository/
fi
cp $iso_path {{ .artifact_file_dir }}/kubekey/kubekey/repository/

View File

@ -0,0 +1,28 @@
---
- name: Copy | Set artifact file dir
when:
- .artifact_file | empty | not
set_fact:
artifact_file_dir: >-
{{ .artifact_file | dir }}/artifact
- name: Copy | Create artifact file dir
command: >-
mkdir -p {{ .artifact_file_dir }}/kubekey/kubekey/
- name: Artifact | Copy required binaries and images
when: .artifact_file_dir | empty | not
block:
# Download core binaries
- include_tasks: binary.yaml
# Download Helm and CNI binaries
- include_tasks: helm.yaml
tags: ["kubernetes"]
# Download remote images to the local images directory
- include_tasks: images.yaml
tags: ["kubernetes", "image_registry"]
- include_tasks: iso.yaml
- name: Export artifact
command: |
cd {{ .artifact_file_dir }} && tar -czvf {{ .artifact_file }} *

View File

@ -159,10 +159,10 @@ if [ $? -ne 0 ]; then
fi
echo "Preparing offline package directory..."
mkdir -p offline/kubekey/kubekey
mkdir -p offline/
echo "Extracting artifact.tgz to offline/ ..."
tar -xzf artifact.tgz -C offline/kubekey/kubekey --no-same-owner
tar -xzf artifact.tgz -C offline/ --no-same-owner
echo "Extracting web-installer.tgz to offline/ ..."
tar -xzf web-installer.tgz -C offline/ --no-same-owner