mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
58 lines
2.2 KiB
YAML
58 lines
2.2 KiB
YAML
---
|
|
- name: Sync images to remote
|
|
tags: ["only_image"]
|
|
copy:
|
|
src: |
|
|
{{ .work_dir }}/kubekey/images/
|
|
dest: |
|
|
{{ .image_registry.images_dir }}
|
|
|
|
- name: Create harbor project for each image
|
|
tags: ["only_image"]
|
|
command: |
|
|
{{- if .image_registry.namespace_override | eq "" }}
|
|
for dir in {{ .image_registry.images_dir }}*; do
|
|
if [ ! -d "$dir" ]; then
|
|
# only deal with directories
|
|
continue
|
|
fi
|
|
|
|
project=${dir##*/}
|
|
|
|
if [[ "$project" == "blobs" ]]; then
|
|
# skip blobs dir
|
|
continue
|
|
fi
|
|
|
|
# if project is not exist, create it
|
|
resp=$(curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X GET "https://{{ .image_registry.auth.registry }}/api/v2.0/projects/${project}")
|
|
if echo "$resp" | grep -q '"code":"NOT_FOUND"'; then
|
|
# create project
|
|
curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X POST -H "Content-Type: application/json" "https://{{ .image_registry.auth.registry }}/api/v2.0/projects" -d "{ \"project_name\": \"${project}\", \"public\": true}"
|
|
fi
|
|
done
|
|
{{- else }}
|
|
# if project is not exist, create it
|
|
resp=$(curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X GET "https://{{ .image_registry.auth.registry }}/api/v2.0/projects/{{ .image_registry.namespace_override }}")
|
|
if echo "$resp" | grep -q '"code":"NOT_FOUND"'; then
|
|
# create project
|
|
curl -u "{{ .image_registry.auth.username }}:{{ .image_registry.auth.password }}" -k -X POST -H "Content-Type: application/json" "https://{{ .image_registry.auth.registry }}/api/v2.0/projects" -d "{ \"project_name\": \"{{ .image_registry.namespace_override }}\", \"public\": true}"
|
|
fi
|
|
{{- end }}
|
|
when: .image_registry.type | eq "harbor"
|
|
|
|
- name: Sync images package to harbor
|
|
tags: ["only_image"]
|
|
image:
|
|
push:
|
|
images_dir: |
|
|
{{ .image_registry.images_dir }}
|
|
registry: |
|
|
{{ .image_registry.auth.registry }}
|
|
namespace_override: |
|
|
{{ .image_registry.namespace_override }}
|
|
username: |
|
|
{{ .image_registry.auth.username }}
|
|
password: |
|
|
{{ .image_registry.auth.password }}
|