kubekey/builtin/roles/install/image-registry/tasks/load_images.yaml
liujian 3e56b095de
fix: test kk push image to harbor. (#2457)
Co-authored-by: joyceliu <joyceliu@yunify.com>
2024-11-19 14:23:29 +08:00

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 }}