Closed STARRY-S closed 5 months ago
- Remove the saved-image-cache cache folder of the Save/Load command and instead read/write the compressed package in real time to avoid unnecessary waste of storage space.
The format of the compressed archive needs to be changed from the non-index archive tar (tar.gz
) format to index archive zip format to support this feature, however, Golang's zip standard library does not support appending new files to the existing zip archive (hangar sync
command needs this) (https://github.com/golang/go/issues/15626).
Therefore, Hangar needs to modify and add some new functions based on the Go zip standard library to allow it to append new files to the zip archive without decompressing the entire zip file.
Update:
Created a new repository github.com/STARRY-S/zip and added the Updater
functions based on Go archive/zip
standard library.
Since containers/images
API (skopeo
) does not support the containerd
transport protocol (see https://github.com/containers/image/issues/1572), and both K3s and RKE2 are using containerd
as container-runtime, only the old RKE1 is using Docker Daemon as runtime.
So Hangar won't support docker-daemon
and docker-archive
protocol currently, and Hangar will consider adding containerd
protocol support when the containers/images
API supports it.
Available to test on version v1.7.0-beta.4
.
Documents of v1.7: https://hangar.cnrancher.com/docs/next/
版本:v1.7.0-beta.4
验证通过。测试内容如下:
validate
子命令,用于验证已拷贝的容器镜像hangar archive ls
命令查看压缩包中存储的镜像信息hangar inspect
命令可获取镜像仓库中镜像的 Manifesthangar convert-list
命令将镜像列表从 Default 格式转换为 Mirror 格式hangar generate-list
命令用于生成 Rancher 镜像列表save
/load
命令过程中敲Ctrl-C 强行中止:检查 ~/.cache/hangar_cache
目录里的所有缓存文件夹,缓存文件夹会清理load
命令时监测 ~/.cache/hangar_cache
目录中存储的文件体积:文件体积不会持续增加
# 另起一个终端执行:
watch du -d 1 -h ~/.cache/hangar_cache
save
/load
命令,完成后检查缓存文件夹:save、load结束缓存文件夹会删除环境:所有环境配置相同:aws 东京,4c8g 100G存储,docker 23.0 版本:
- hangar:v1.6.0,v1.7.0-beta.4
- Harbor:v2.8.4 (http hangar从内网推送镜像)
命令:hangar v1.6和v1.7使用相同的命令,并发数相同
测试结果:
Hangar版本 | Mirror时间 | save时间 | save占用存储 | save失败数 | load时间 | load失败数 |
---|---|---|---|---|---|---|
v1.6 | 9分17秒 | 18分30秒 | 44G saved-image-cache 44G saved-images.tar.gz | 失败0 | 19分钟 | 失败0 |
v1.7 | 9分15秒 | 14分钟 | 44G save_images.zip 4.0K /root/.cache/hangar_cache | 失败1 | 10分钟 | 失败6 |
备注:
结果分析:
Version: v1.7.0-beta.4
Verification passed. The test content is as follows:
validate
subcommand, used to verify the copied container imagehangar archive ls
command to view the image information stored in the compressed packagehangar inspect
command can obtain the manifest of the image in the image warehousehangar convert-list
command converts the mirror list from Default format to Mirror formathangar generate-list
command is used to generate a Rancher image listCtrl-C
during the execution of the save/load
command to force abort: check all cache folders in the ~/.cache/hangar_cache
directory, the cache folders will be cleared~/.cache/hangar_cache
directory when executing the load command: the file size will not continue to increase
# Start a new terminal and execute:
watch du -d 1 -h ~/.cache/hangar_cache
Environment: All environment configurations are the same: aws, 4c8g 100G storage, docker 23.0 Version:
- hangar: v1.6.0, v1.7.0-beta.4
- Harbor: v2.8.4
Command: hangar v1.6 and v1.7 use the same command, and the number of concurrency is the same
Test Results:
Hangar | Mirror time | Save time | Save storage | Save failures | Load time | load failures |
---|---|---|---|---|---|---|
v1.6 | 9m17s | 18m30s | 44G saved-image-cache 44G saved-images.tar.gz | failed 0 | 19m | failed 0 |
v1.7 | 9m15s | 14m | 44G save_images.zip 4.0K /root/.cache/hangar_cache | Failed 1 | 10m | Failed 6 |
Remark:
Result analysis:
考虑在后续移除
skopeo
二进制依赖,改用 containers/image API。 提高 Hangar 的镜像拷贝速度,使该工具更易用,便于开发维护。移除
skopeo
二进制依赖的附加改动:TLS handshake timeout
错误。login/logout
子命令,功能同skopeo login/logout
。saved-image-cache
缓存文件夹,改为实时读取/写入压缩包,避免不必要的存储空间浪费。考虑增加docker-daemon
和docker-archive
协议支持。zstd
压缩格式效果不明显,考虑移除。tar.gz
格式改为zip
格式,新增hangar archive
子命令,用于对压缩包执行一些操作。 此改动会使 Hangar v1.7 版本与旧版本存在不兼容。mirror-validate
等 Validate 命令改为mirror validate
(Mirror 的子命令形式); 同时移除了--repo-type=harbor
,--harbor-https
等选项,改为自动识别 Registry 类型。除此之外
load
和load validate
命令将支持指定镜像列表文件,如果指定了镜像列表,将只 Load (Validate)列表中的部分镜像。SIGINT/SIGTERM
信号处理,在执行Ctrl-C
时会释放资源再退出程序。hangar inspect
命令,功能与skopeo inspect
类似,用于查看 Registry Server 中的镜像 Manifest。compress/decompress
子命令已被移除。hangar completion
子命令,用于生成 Shell 补全脚本。containers/signature
API 使用了 libgpgme 等 C 库,因此新版本的 Hangar 需要启用 CGO,编译生成的二进制文件存在动态库依赖,因此后续的 Release 将不再包含 Hangar 二进制文件。 考虑后续在 OBS 中为 openSUSE 等 Linux 发行版构建 Hangar 安装包。mirror
命令除了支持 “Mirror” 格式的镜像列表外,还将支持save
命令使用的镜像列表格式。Consider removing the
skopeo
binary dependency and using containers/image API to refactor the major codes of this project to make it much easier to use and develop.Additional changes to remove the
skopeo
binary dependency:TLS handshake timeout
errors.login
andlogout
subcommands, the function is the same asskopeo login/logout
.saved-image-cache
cache folder of theSave/Load
command and instead read/write the compressed package in real time to avoid unnecessary waste of storage space.Adddocker-daemon
anddocker-archive
protocol support.zstd
compression format is not obvious, consider removing it.zip
fromtar.gz
, and addinghangar archive
subcommand for operations to the archive file. This change will make Hangar v1.7 incompatible with older versions.mirror-validate
were changed tomirror validate
(subcommand ofmirror
command); Some options like--repo-type=harbor
and--harbor-https
will be removed and the Registry type will be automatically detected.the
load
andload validate
commands will support specifying an image list file. If an image list is specified, only some of the images in the list will be loaded (and validated).SIGINT/SIGTERM
signal and exit program gracefully.hangar inspect
command, (similar toskopeo inspect
), for inspecting the manifest of images on registry server.compress/decompress
subcommands were removed since thesaved-image-cache
directory logic was removed.hangar completion
subcommand for generating Shell completion scripts.containers/signature
API useslibgpgme
and other C libraries, so CGO was enabled to build Hangar. The built binary file has dynamic library dependencies, so the GitHub Releases will no longer contain Hangar binary files. Will consider adding Hangar to OBS for building packages of openSUSE and other Linux distributions.mirror
command will support both "Mirror" format and default format image list (used bysave
command).