Skip to content

Commit bd780ee

Browse files
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>
1 parent 867aca2 commit bd780ee

File tree

7 files changed

+296
-6
lines changed

7 files changed

+296
-6
lines changed

builtin/core/playbooks/artifact_export.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,5 @@
1515
- localhost
1616
roles:
1717
- download
18-
tasks:
19-
- name: Export artifact
20-
command: |
21-
cd {{ .binary_dir }} && tar -czvf {{ .artifact_file }} *
18+
- copy
19+
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
- name: Binary | Ensure etcd binary is present
2+
tags: ["etcd"]
3+
loop: "{{ .download.arch | toJson }}"
4+
when:
5+
- .etcd.deployment_type | eq "external"
6+
- .etcd.etcd_version | empty | not
7+
command: |
8+
artifact_name={{ get .download.artifact_url.etcd .item | splitList "/" | last }}
9+
artifact_path={{ .binary_dir }}/etcd/{{ .etcd.etcd_version }}/{{ .item }}
10+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/etcd/{{ .etcd.etcd_version }}/{{ .item }}
11+
mkdir -p $target_path
12+
cp $artifact_path/$artifact_name $target_path/
13+
14+
- name: Binary | Ensure Kubernetes binaries are present
15+
tags: ["kubernetes"]
16+
loop: "{{ .download.arch | toJson }}"
17+
when: .kubernetes.kube_version | empty | not
18+
command: |
19+
kube_path={{ .binary_dir }}/kube/{{ .kubernetes.kube_version }}/{{ .item }}
20+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/kube/{{ .kubernetes.kube_version }}/{{ .item }}
21+
mkdir -p $target_path
22+
cp $kube_path/kubelet $target_path/
23+
cp $kube_path/kubeadm $target_path/
24+
cp $kube_path/kubectl $target_path/
25+
26+
- name: Binary | Ensure CNI plugins are present
27+
tags: ["kubernetes"]
28+
loop: "{{ .download.arch | toJson }}"
29+
when: .cni.cni_plugins_version | empty | not
30+
command: |
31+
artifact_name={{ get .download.artifact_url.cni_plugins .item | splitList "/" | last }}
32+
artifact_path={{ .binary_dir }}/cni/plugins/{{ .cni.cni_plugins_version }}/{{ .item }}
33+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/plugins/{{ .cni.cni_plugins_version }}/{{ .item }}
34+
mkdir -p $target_path
35+
cp $artifact_path/$artifact_name $target_path/
36+
37+
- name: Binary | Ensure Helm binary is present
38+
tags: ["kubernetes"]
39+
loop: "{{ .download.arch | toJson }}"
40+
when: .kubernetes.helm_version | empty | not
41+
command: |
42+
artifact_name={{ get .download.artifact_url.helm .item | splitList "/" | last }}
43+
artifact_path={{ .binary_dir }}/helm/{{ .kubernetes.helm_version }}/{{ .item }}
44+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/helm/{{ .kubernetes.helm_version }}/{{ .item }}
45+
mkdir -p $target_path
46+
cp $artifact_path/$artifact_name $target_path/
47+
48+
- name: Binary | Ensure crictl binary is present
49+
tags: ["kubernetes"]
50+
loop: "{{ .download.arch | toJson }}"
51+
when: .cri.crictl_version | empty | not
52+
command: |
53+
artifact_name={{ get .download.artifact_url.crictl .item | splitList "/" | last }}
54+
artifact_path={{ .binary_dir }}/crictl/{{ .cri.crictl_version }}/{{ .item }}
55+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/crictl/{{ .cri.crictl_version }}/{{ .item }}
56+
mkdir -p $target_path
57+
cp $artifact_path/$artifact_name $target_path/
58+
59+
- name: Binary | Ensure Docker binary is present
60+
tags: ["kubernetes","image_registry"]
61+
loop: "{{ .download.arch | toJson }}"
62+
when:
63+
- .cri.docker_version | empty | not
64+
- or (.image_registry.type | empty | not) (.cri.container_manager | eq "docker")
65+
command: |
66+
artifact_name={{ get .download.artifact_url.docker .item | splitList "/" | last }}
67+
artifact_path={{ .binary_dir }}/docker/{{ .cri.docker_version }}/{{ .item }}
68+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/docker/{{ .cri.docker_version }}/{{ .item }}
69+
mkdir -p $target_path
70+
cp $artifact_path/$artifact_name $target_path/
71+
72+
- name: Binary | Ensure cri-dockerd binary is present
73+
tags: ["kubernetes"]
74+
loop: "{{ .download.arch | toJson }}"
75+
when:
76+
- .cri.cridockerd_version | empty | not
77+
- .cri.container_manager | eq "docker"
78+
- .kubernetes.kube_version | semverCompare ">=v1.24.0"
79+
command: |
80+
artifact_name={{ get .download.artifact_url.cridockerd .item | splitList "/" | last }}
81+
artifact_path={{ .binary_dir }}/cri-dockerd/{{ .cri.cridockerd_version }}/{{ .item }}
82+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cri-dockerd/{{ .cri.cridockerd_version }}/{{ .item }}
83+
mkdir -p $target_path
84+
cp $artifact_path/$artifact_name $target_path/
85+
86+
- name: Binary | Ensure containerd binary is present
87+
tags: ["kubernetes"]
88+
loop: "{{ .download.arch | toJson }}"
89+
when:
90+
- .cri.containerd_version | empty | not
91+
- .cri.container_manager | eq "containerd"
92+
command: |
93+
artifact_name={{ get .download.artifact_url.containerd .item | splitList "/" | last }}
94+
artifact_path={{ .binary_dir }}/containerd/{{ .cri.containerd_version }}/{{ .item }}
95+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/containerd/{{ .cri.containerd_version }}/{{ .item }}
96+
mkdir -p $target_path
97+
cp $artifact_path/$artifact_name $target_path/
98+
99+
- name: Binary | Ensure runc binary is present
100+
tags: ["kubernetes"]
101+
loop: "{{ .download.arch | toJson }}"
102+
when:
103+
- .cri.runc_version | empty | not
104+
- .cri.container_manager | eq "containerd"
105+
command: |
106+
artifact_name={{ get .download.artifact_url.runc .item | splitList "/" | last }}
107+
artifact_path={{ .binary_dir }}/runc/{{ .cri.runc_version }}/{{ .item }}
108+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/runc/{{ .cri.runc_version }}/{{ .item }}
109+
mkdir -p $target_path
110+
cp $artifact_path/$artifact_name $target_path/
111+
112+
- name: Binary | Ensure calicoctl binary is present
113+
tags: ["kubernetes"]
114+
loop: "{{ .download.arch | toJson }}"
115+
when:
116+
- .cni.calico_version | empty | not
117+
- .cni.type | eq "calico"
118+
command: |
119+
artifact_name=calicoctl
120+
artifact_path={{ .binary_dir }}/cni/calico/{{ .cni.calico_version }}/{{ .item }}
121+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/calico/{{ .cni.calico_version }}/{{ .item }}
122+
mkdir -p $target_path
123+
cp $artifact_path/$artifact_name $target_path/
124+
125+
- name: Binary | Ensure Docker Registry binary is present
126+
tags: ["image_registry"]
127+
loop: "{{ .download.arch | toJson }}"
128+
when:
129+
- .image_registry.docker_registry_version | empty | not
130+
- .image_registry.type | eq "docker-registry"
131+
command: |
132+
artifact_name={{ get .download.artifact_url.docker_registry .item | splitList "/" | last }}
133+
artifact_path={{ .binary_dir }}/image-registry/docker-registry/{{ .image_registry.docker_registry_version }}/{{ .item }}
134+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/docker-registry/{{ .image_registry.docker_registry_version }}/{{ .item }}
135+
mkdir -p $target_path
136+
cp $artifact_path/$artifact_name $target_path/
137+
138+
- name: Binary | Ensure docker-compose binary is present
139+
tags: ["image_registry"]
140+
loop: "{{ .download.arch | toJson }}"
141+
when:
142+
- .cri.dockercompose_version | empty | not
143+
- .image_registry.type | eq "harbor"
144+
command: |
145+
compose_name=docker-compose
146+
compose_path={{ .binary_dir }}/image-registry/docker-compose/{{ .cri.dockercompose_version }}/{{ .item }}
147+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/docker-compose/{{ .cri.dockercompose_version }}/{{ .item }}
148+
mkdir -p $target_path
149+
cp $compose_path/$compose_name $target_path/
150+
151+
- name: Binary | Ensure Harbor binary is present
152+
tags: ["image_registry"]
153+
loop: "{{ .download.arch | toJson }}"
154+
when:
155+
- .image_registry.harbor_version | empty | not
156+
- .image_registry.type | eq "harbor"
157+
command: |
158+
harbor_name={{ get .download.artifact_url.harbor .item | splitList "/" | last }}
159+
harbor_path={{ .binary_dir }}/image-registry/harbor/{{ .image_registry.harbor_version }}/{{ .item }}
160+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/harbor/{{ .image_registry.harbor_version }}/{{ .item }}
161+
mkdir -p $target_path
162+
cp $harbor_path/$harbor_name $target_path/
163+
164+
- name: Binary | Ensure keepalived binary is present
165+
tags: ["image_registry"]
166+
loop: "{{ .download.arch | toJson }}"
167+
when:
168+
- .image_registry.keepalived_version | empty | not
169+
- .image_registry.ha_vip | empty | not
170+
- .groups.image_registry | len | lt 1
171+
command: |
172+
artifact_name={{ get .download.artifact_url.keepalived .item | splitList "/" | last }}
173+
artifact_path={{ .binary_dir }}/image-registry/keepalived/{{ .keepalived_version }}/{{ .item }}
174+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/image-registry/keepalived/{{ .keepalived_version }}/{{ .item }}
175+
mkdir -p $target_path
176+
cp $artifact_path/$artifact_name $target_path/
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
- name: Helm | Ensure the Calico binary is available
3+
when:
4+
- .cni.calico_version | empty | not
5+
- .cni.type | eq "calico"
6+
command: |
7+
artifact_name={{ .download.artifact_url.calico | splitList "/" | last }}
8+
artifact_path={{ .binary_dir }}/cni/calico
9+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/calico
10+
mkdir -p $target_path
11+
cp $artifact_path/$artifact_name $target_path/
12+
13+
- name: Helm | Ensure the Cilium binary is available
14+
when:
15+
- .cni.cilium_version | empty | not
16+
- .cni.type | eq "cilium"
17+
command: |
18+
artifact_name={{ .download.artifact_url.cilium | splitList "/" | last }}
19+
artifact_path={{ .binary_dir }}/cni/cilium
20+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/cilium
21+
mkdir -p $target_path
22+
cp $artifact_path/$artifact_name $target_path/
23+
24+
- name: Helm | Ensure the Flannel binary is available
25+
when:
26+
- .cni.flannel_version | empty | not
27+
- .cni.type | eq "flannel"
28+
command: |
29+
artifact_name={{ .download.artifact_url.flannel | splitList "/" | last }}
30+
artifact_path={{ .binary_dir }}/cni/flannel
31+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/flannel
32+
mkdir -p $target_path
33+
cp $artifact_path/$artifact_name $target_path/
34+
35+
- name: Helm | Ensure the Kube-OVN binary is available
36+
when:
37+
- .kubeovn_version | empty | not
38+
- .cni.type | eq "kubeovn"
39+
command: |
40+
artifact_name={{ .download.artifact_url.kubeovn | splitList "/" | last }}
41+
artifact_path={{ .binary_dir }}/cni/kubeovn
42+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/kubeovn
43+
mkdir -p $target_path
44+
cp $artifact_path/$artifact_name $target_path/
45+
46+
- name: Helm | Ensure the Hybridnet binary is available
47+
when:
48+
- .cni.hybridnet_version | empty | not
49+
- .cni.type | eq "hybridnet"
50+
command: |
51+
artifact_name={{ .download.artifact_url.hybridnet | splitList "/" | last }}
52+
artifact_path={{ .binary_dir }}/cni/hybridnet
53+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/cni/hybridnet
54+
mkdir -p $target_path
55+
cp $artifact_path/$artifact_name $target_path/
56+
57+
- name: Helm | Ensure the NFS Provisioner binary is available
58+
when:
59+
- .storage_class.nfs_provisioner_version | empty | not
60+
- .storage_class.nfs.enabled
61+
command: |
62+
artifact_name={{ .download.artifact_url.nfs_provisioner | splitList "/" | last }}
63+
artifact_path={{ .binary_dir }}/sc
64+
target_path={{ .artifact_file_dir }}/kubekey/kubekey/sc
65+
mkdir -p $target_path
66+
cp $artifact_path/$artifact_name $target_path/
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- name: Image | Ensure container images is available
2+
image:
3+
copy:
4+
from:
5+
path: >-
6+
{{ .binary_dir }}/images/
7+
manifests: "{{ .image_manifests | toJson }}"
8+
to:
9+
path: >-
10+
{{ .artifact_file_dir }}/kubekey/kubekey/images/
11+
when:
12+
- .image_manifests | default list | empty | not
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
- name: ISO | Ensure ISO files is available
3+
when: .download.iso_url.urls | empty | not
4+
loop: "{{ .download.iso_url.urls | toJson }}"
5+
command: |
6+
iso_path={{ .binary_dir }}/repository/{{ .item | splitList "/" | last }}
7+
if [ ! -f {{ .artifact_file_dir }}/kubekey/kubekey/repository/ ];then
8+
mkdir -p {{ .artifact_file_dir }}/kubekey/kubekey/repository/
9+
fi
10+
cp $iso_path {{ .artifact_file_dir }}/kubekey/kubekey/repository/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
- name: Copy | Set artifact file dir
3+
when:
4+
- .artifact_file | empty | not
5+
set_fact:
6+
artifact_file_dir: >-
7+
{{ .artifact_file | dir }}/artifact
8+
9+
- name: Copy | Create artifact file dir
10+
command: >-
11+
mkdir -p {{ .artifact_file_dir }}/kubekey/kubekey/
12+
13+
- name: Artifact | Copy required binaries and images
14+
when: .artifact_file_dir | empty | not
15+
block:
16+
# Download core binaries
17+
- include_tasks: binary.yaml
18+
# Download Helm and CNI binaries
19+
- include_tasks: helm.yaml
20+
tags: ["kubernetes"]
21+
# Download remote images to the local images directory
22+
- include_tasks: images.yaml
23+
tags: ["kubernetes", "image_registry"]
24+
- include_tasks: iso.yaml
25+
26+
- name: Export artifact
27+
command: |
28+
cd {{ .artifact_file_dir }} && tar -czvf {{ .artifact_file }} *

hack/downloadKubekey.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ if [ $? -ne 0 ]; then
159159
fi
160160
161161
echo "Preparing offline package directory..."
162-
mkdir -p offline/kubekey/kubekey
162+
mkdir -p offline/
163163
164164
echo "Extracting artifact.tgz to offline/ ..."
165-
tar -xzf artifact.tgz -C offline/kubekey/kubekey --no-same-owner
165+
tar -xzf artifact.tgz -C offline/ --no-same-owner
166166
167167
echo "Extracting web-installer.tgz to offline/ ..."
168168
tar -xzf web-installer.tgz -C offline/ --no-same-owner

0 commit comments

Comments
 (0)