[agent-go] - image sync entity
This commit is contained in:
@@ -16,17 +16,21 @@ const PublicDeployHarborHost = "42.192.52.227"
|
||||
const DirectPushDeployHarborHost = "36.134.71.138"
|
||||
|
||||
type ImageSyncEntity struct {
|
||||
ProjectName string // 优先级3
|
||||
ProjectFromDemoNameNotNull bool
|
||||
ProjectVersion string // 优先级2
|
||||
CmiiNameTagList []string // 优先级1 appName:tag的形式
|
||||
FullNameImageList []string // 优先级1
|
||||
DownloadImage bool // 下载镜像
|
||||
DownloadFromOss bool // 下载镜像
|
||||
CompressImageToGzip bool // 压缩镜像
|
||||
UploadToDemoMinio bool // 上传镜像
|
||||
ShouldDirectPushToHarbor bool // 直接推送到对方的主机 || 离线部署机 使用此部门
|
||||
DirectHarborHost string // 目标Harbor仓库的Host,全名称带端口 不带http前缀
|
||||
ProjectName string // 优先级3 优先级最低 从DEMO拉取镜像
|
||||
ProjectVersion string // 优先级2 高于ProjectName 优先拉取特定版本的镜像
|
||||
|
||||
CmiiNameTagList []string // 优先级1 appName:tag 会被转换为FullNameImageList
|
||||
FullNameImageList []string // 优先级1 优先下载此类型
|
||||
|
||||
ShouldDownloadImage bool // 下载镜像 DCU中的D
|
||||
ShouldCompressImageToGzip bool // 压缩镜像 DCU中的C
|
||||
ShouldUploadToDemoMinio bool // 上传镜像 DCU中的U
|
||||
|
||||
ShouldDownloadFromOss bool // 下载镜像 DLTU中的D
|
||||
ShouldUpdateImageTag bool // 更新镜像 DLTU中的U
|
||||
|
||||
ShouldDirectPushToHarbor bool // 直接推送到对方的主机 || 离线部署机
|
||||
DirectHarborHost string // IP:Port or 域名:PORT 不带http前缀
|
||||
}
|
||||
|
||||
type ImageSyncResult struct {
|
||||
@@ -57,15 +61,14 @@ func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResul
|
||||
if sync.ProjectVersion != "" {
|
||||
|
||||
// 获取特定版本的镜像
|
||||
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList, allGzipFileNameList = DownloadCompressUploadFromVersion(sync.ProjectVersion, sync.CompressImageToGzip, sync.UploadToDemoMinio)
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList, allGzipFileNameList = C_DownloadCompressUploadFromVersion(sync.ProjectVersion, sync.ShouldCompressImageToGzip, sync.ShouldUploadToDemoMinio)
|
||||
|
||||
gzipFolderFullPath = image.OfflineImageGzipFolderPrefix + sync.ProjectVersion
|
||||
|
||||
} else {
|
||||
// 获取DEMO的镜像
|
||||
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList, allGzipFileNameList = DownloadCompressUploadFromDemo(sync.ProjectName, sync.CompressImageToGzip, sync.UploadToDemoMinio)
|
||||
// 获取DEMO的镜像
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList, allGzipFileNameList = C_DownloadCompressUploadFromDemo(sync.ProjectName, sync.ShouldCompressImageToGzip, sync.ShouldUploadToDemoMinio)
|
||||
gzipFolderFullPath = image.OfflineImageGzipFolderPrefix + sync.ProjectName
|
||||
|
||||
}
|
||||
@@ -77,7 +80,7 @@ func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResul
|
||||
allCmiiImageNameList = concatAndUniformCmiiImage(sync.FullNameImageList, sync.CmiiNameTagList)
|
||||
|
||||
// DCU
|
||||
errorPullImageList, errorGzipImageList, realCmiiImageList, allGzipFileNameList = DownloadCompressUpload(true, allCmiiImageNameList, sync.CompressImageToGzip, gzipFolderFullPath, sync.UploadToDemoMinio)
|
||||
errorPullImageList, errorGzipImageList, realCmiiImageList, allGzipFileNameList = A_DownloadCompressUpload(true, allCmiiImageNameList, sync.ShouldCompressImageToGzip, gzipFolderFullPath, sync.ShouldUploadToDemoMinio)
|
||||
}
|
||||
|
||||
// 直接传输到目标Harbor仓库
|
||||
@@ -119,8 +122,8 @@ func concatAndUniformCmiiImage(fullImageList []string, cmiiImageList []string) [
|
||||
return fullImageList
|
||||
}
|
||||
|
||||
// DownloadCompressUpload DCU 镜像同步的前半部分,通常在35.71 LapPro执行,无需Bastion Mode
|
||||
func DownloadCompressUpload(downloadImage bool, fullNameList []string, shouldGzip bool, gzipFolderFullPath string, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileFullNameList []string) {
|
||||
// A_DownloadCompressUpload DCU 镜像同步的前半部分,通常在35.71 LapPro执行,无需Bastion Mode
|
||||
func A_DownloadCompressUpload(downloadImage bool, fullNameList []string, shouldGzip bool, gzipFolderFullPath string, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileFullNameList []string) {
|
||||
|
||||
// write to file
|
||||
localGzipFileListTxt := gzipFolderFullPath + "all-gzip-image-file-name.txt"
|
||||
@@ -235,13 +238,13 @@ func DownloadCompressUpload(downloadImage bool, fullNameList []string, shouldGzi
|
||||
return errorPullImageList, errorGzipImageList, fullNameList, allGzipFileFullNameList
|
||||
}
|
||||
|
||||
// DownloadLoadTagUpload DLTU procedure ImageSync的另外一般流程,需要支持 堡垒机(纯离线)的模式
|
||||
// A_DownloadLoadTagUpload DLTU procedure ImageSync的另外一般流程,需要支持 堡垒机(纯离线)的模式
|
||||
// 2. Gzip文件目录,RKE MIDDLE CMII三个文件目录 - 约定目录
|
||||
// 约定目录 /root/wdd/image/rke/ /root/wdd/image/middle/ /root/wdd/image/cmii/
|
||||
// 3. 读取本机的IP地址 - 参数传递
|
||||
// 4. OSS地址 - ossUrlPrefix传空 则使用默认值
|
||||
// 5. ossFileName - 如果结尾为txt,则为文件的形式,如果为tar.gz,则为gzip文件夹的形式
|
||||
func DownloadLoadTagUpload(downloadFromOss bool, ossUrlPrefix, ossFileNameOrGzipFileListTxt, localGzipFolderOrGzipFile string, targetHarborFullName string) (targetImageFullNameList []string) {
|
||||
func A_DownloadLoadTagUpload(downloadFromOss bool, ossUrlPrefix, ossFileNameOrGzipFileListTxt, localGzipFolderOrGzipFile string, targetHarborFullName string) (targetImageFullNameList []string) {
|
||||
|
||||
// 支持单文件的形式
|
||||
if !utils.IsDirOrFile(localGzipFolderOrGzipFile) {
|
||||
@@ -340,8 +343,8 @@ func parseAndDownloadFromOss(ossUrlPrefix, ossFileName, localGzipFolder string)
|
||||
return true
|
||||
}
|
||||
|
||||
// DownloadCompressUploadFromDemo 获取DEMO环境的全部镜像
|
||||
func DownloadCompressUploadFromDemo(projectName string, shouldGzip, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
// C_DownloadCompressUploadFromDemo 获取DEMO环境的全部镜像
|
||||
func C_DownloadCompressUploadFromDemo(projectName string, shouldGzip, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
|
||||
// generate a project folder
|
||||
err := os.MkdirAll(image.OfflineImageGzipFolderPrefix+projectName, os.ModeDir)
|
||||
@@ -357,7 +360,7 @@ func DownloadCompressUploadFromDemo(projectName string, shouldGzip, shouldOss bo
|
||||
|
||||
// do work
|
||||
// DCU
|
||||
return DownloadCompressUpload(true, allCmiiImageNameListFromDemo, shouldGzip, image.OfflineImageGzipFolderPrefix+projectName, shouldOss)
|
||||
return A_DownloadCompressUpload(true, allCmiiImageNameListFromDemo, shouldGzip, image.OfflineImageGzipFolderPrefix+projectName, shouldOss)
|
||||
}
|
||||
|
||||
func buildAllCmiiImageNameListFromDemo(projectName string) []string {
|
||||
@@ -396,8 +399,8 @@ func buildAllCmiiImageNameListFromDemo(projectName string) []string {
|
||||
return realCmiiImageName
|
||||
}
|
||||
|
||||
// DownloadCompressUploadFromVersion 根据版本下载全部的CMII镜像
|
||||
func DownloadCompressUploadFromVersion(cmiiVersion string, shouldGzip bool, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
// C_DownloadCompressUploadFromVersion 根据版本下载全部的CMII镜像
|
||||
func C_DownloadCompressUploadFromVersion(cmiiVersion string, shouldGzip bool, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
|
||||
// generate a project folder
|
||||
err := os.MkdirAll(image.OfflineImageGzipFolderPrefix+cmiiVersion, os.ModeDir)
|
||||
@@ -413,7 +416,7 @@ func DownloadCompressUploadFromVersion(cmiiVersion string, shouldGzip bool, shou
|
||||
|
||||
// do work
|
||||
// DCU procedure
|
||||
return DownloadCompressUpload(true, realCmiiImageName, shouldGzip, image.OfflineImageGzipFolderPrefix+cmiiVersion, shouldOss)
|
||||
return A_DownloadCompressUpload(true, realCmiiImageName, shouldGzip, image.OfflineImageGzipFolderPrefix+cmiiVersion, shouldOss)
|
||||
|
||||
}
|
||||
|
||||
@@ -454,7 +457,8 @@ func buildAllCmiiImageNameListFromVersion(cmiiVersion string) []string {
|
||||
return realCmiiImageName
|
||||
}
|
||||
|
||||
func DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool, shouldDownload bool, isRKE bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
// C_DownloadCompressUploadDependency DCU所有的依赖镜像
|
||||
func C_DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool, shouldDownload bool, isRKE bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
|
||||
log.Info("DCU for middle and rke!")
|
||||
err := os.MkdirAll(image.OfflineImageGzipFolderPrefix, os.ModeDir)
|
||||
@@ -478,7 +482,7 @@ func DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool, shouldDow
|
||||
gzipFolderPrefix = image.OfflineImageGzipFolderPrefix + "middle/"
|
||||
}
|
||||
|
||||
return DownloadCompressUpload(shouldDownload, fulleImageNameList, shouldGzip, gzipFolderPrefix, shouldOss)
|
||||
return A_DownloadCompressUpload(shouldDownload, fulleImageNameList, shouldGzip, gzipFolderPrefix, shouldOss)
|
||||
}
|
||||
|
||||
func LoadSplitCmiiGzipImageToTargetHarbor(projectName, targetHarborHost string) (errorLoadImageNameList, errorPushImageNameList []string) {
|
||||
|
||||
Reference in New Issue
Block a user