feat: 添加了 imager 工具 package
refactor: 将 images 的获取分散到各个组件里面
This commit is contained in:
73
internal/controller/maker/registry.go
Normal file
73
internal/controller/maker/registry.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package maker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.loveuer.com/yizhisec/pkg3/logger"
|
||||
"yizhisec.com/hsv2/forge/pkg/resource"
|
||||
)
|
||||
|
||||
func (m *maker) Registry(ctx context.Context, storage string) error {
|
||||
const (
|
||||
_registryToml = `
|
||||
[plugins."io.containerd.grpc.v1.cri".registry]
|
||||
config_path = ""
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."10.96.123.45:80"]
|
||||
endpoint = ["http://10.96.123.45:80"]
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.configs]
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.configs."10.96.123.45:80".tls]
|
||||
insecure_skip_verify = true
|
||||
[plugins."io.containerd.grpc.v1.cri".registry.configs."10.96.123.45:80".auth]`
|
||||
)
|
||||
|
||||
var (
|
||||
err error
|
||||
location = filepath.Join(m.workdir, "dependency", "registry")
|
||||
imgName = "docker.io/library/registry:2.8.3"
|
||||
uiImgName = "docker.io/quiq/registry-ui:0.11.0"
|
||||
imgFallback = "docker-mirror.yizhisec.com/library/registry:2.8.3"
|
||||
uiImgFallback = "docker-mirror.yizhisec.com/quiq/registry-ui:0.11.0"
|
||||
)
|
||||
|
||||
logger.Info("☑️ 开始创建依赖: registry...")
|
||||
|
||||
logger.Debug("☑️ 创建 dir: %s ...", location)
|
||||
if err = os.MkdirAll(location, 0755); err != nil {
|
||||
logger.Debug("❌ 创建 dir %s 失败: %v", location, err)
|
||||
return err
|
||||
}
|
||||
|
||||
yamlFile := filepath.Join(location, "registry.yaml")
|
||||
content := fmt.Sprintf(resource.YAMLRegistry, storage)
|
||||
logger.Debug("写入 yaml 文件: %s ...", yamlFile)
|
||||
if os.WriteFile(yamlFile, []byte(content), 0644); err != nil {
|
||||
logger.Debug("❌ 写入 yaml 文件 %s 失败: %v", yamlFile, err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Debug("开始准备镜像...")
|
||||
imgFile := filepath.Join(location, "registry.tar")
|
||||
if err = m.Image(ctx, imgName, WithImageFallback(imgFallback), WithImageSave(imgFile)); err != nil {
|
||||
logger.Debug("❌ 准备镜像 %s 失败: %v", imgName, err)
|
||||
return err
|
||||
}
|
||||
imgFile = filepath.Join(location, "registry-ui.tar")
|
||||
if err = m.Image(ctx, uiImgName, WithImageFallback(uiImgFallback), WithImageSave(imgFile)); err != nil {
|
||||
logger.Debug("❌ 准备镜像 %s 失败: %v", uiImgName, err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Debug("写入 registry.toml 文件: %s ...", filepath.Join(location, "registry.toml"))
|
||||
if os.WriteFile(filepath.Join(location, "registry.toml"), []byte(_registryToml), 0644); err != nil {
|
||||
logger.Debug("❌ 写入 registry.toml 文件 %s 失败: %v", filepath.Join(location, "registry.toml"), err)
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("✅ 创建依赖成功: registry!!!")
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user