[Agent][Deploy] - 修改ImageSync模块 大量修改
This commit is contained in:
@@ -330,13 +330,13 @@ func PullFromFullNameList(fullImageNameList []string) (errorPullImageList []stri
|
||||
}
|
||||
scanner := bufio.NewScanner(pullResult)
|
||||
for scanner.Scan() {
|
||||
//line := scanner.Text()
|
||||
line := scanner.Text()
|
||||
//if strings.Contains(line, "\"status\":\"Pulling from") {
|
||||
// fmt.Println(line)
|
||||
//}
|
||||
//if strings.Contains(line, "Status: Image is up to date for") {
|
||||
// fmt.Println(line)
|
||||
//}
|
||||
if strings.Contains(line, "Status: Image is up to date for") {
|
||||
fmt.Println(line)
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
@@ -453,7 +453,7 @@ func SaveToGzipFile(imageFullName, folderPathPrefix string) (gzipOK bool, gzipIm
|
||||
}
|
||||
|
||||
// 生成gzip压缩文件的全路径名称
|
||||
gzipImageFileFullPath = folderPathPrefix + gzipImageFileFullPath
|
||||
gzipImageFileFullPath = filepath.Join(folderPathPrefix, gzipImageFileFullPath)
|
||||
|
||||
log.InfoF("[ImageSaveToTarGZ] - start to save [%s] to [%s]", realImageTag, gzipImageFileFullPath)
|
||||
|
||||
@@ -491,71 +491,68 @@ func SaveToGzipFile(imageFullName, folderPathPrefix string) (gzipOK bool, gzipIm
|
||||
// SaveImageListToGzipFile 将一个列表内的镜像全部压缩为一个tar.gz文件
|
||||
func SaveImageListToGzipFile(imageFullNames []string, folderPathPrefix string, outputFileName string) (gzipOK bool, gzipFileFullPath string, errorGzipImageList []string) {
|
||||
|
||||
if len(imageFullNames) == 0 {
|
||||
log.Error("[SaveImagesToGzipFile] - no images provided")
|
||||
return false, "", errorGzipImageList
|
||||
}
|
||||
|
||||
// 确保输出文件路径
|
||||
if err := os.MkdirAll(filepath.Dir(folderPathPrefix), os.ModePerm); err != nil {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - failed to create directory: %s", err)
|
||||
return false, "", errorGzipImageList
|
||||
}
|
||||
|
||||
gzipFileFullPath = filepath.Join(folderPathPrefix, outputFileName)
|
||||
log.InfoF("[SaveImagesToGzipFile] - start saving images to [%s]", gzipFileFullPath)
|
||||
|
||||
// 删除旧的Gzip文件
|
||||
if err := os.Remove(gzipFileFullPath); err != nil && !os.IsNotExist(err) {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - failed to remove old gzip file: %s", err)
|
||||
return false, "", errorGzipImageList
|
||||
}
|
||||
|
||||
tarFile, err := os.Create(gzipFileFullPath)
|
||||
if err != nil {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - error creating gzip file: %s", err)
|
||||
return false, "", errorGzipImageList
|
||||
}
|
||||
defer tarFile.Close()
|
||||
|
||||
gw, err := pgzip.NewWriterLevel(tarFile, pgzip.DefaultCompression)
|
||||
if err != nil {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - pgzip writer creation error: %s", err)
|
||||
return false, "", errorGzipImageList
|
||||
}
|
||||
defer gw.Close()
|
||||
|
||||
errorGzipImageList = []string{}
|
||||
|
||||
for _, imageFullName := range imageFullNames {
|
||||
imageGetByName := GetByName(imageFullName)
|
||||
if imageGetByName == nil {
|
||||
log.WarnF("[SaveImagesToGzipFile] - %s not exists, skipping", imageFullName)
|
||||
errorGzipImageList = append(errorGzipImageList, imageFullName)
|
||||
continue
|
||||
}
|
||||
|
||||
imageSaveTarStream, err := apiClient.ImageSave(context.TODO(), imageGetByName.RepoTags)
|
||||
if err != nil {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - image save error for %s: %s", imageFullName, err)
|
||||
errorGzipImageList = append(errorGzipImageList, imageFullName)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := io.Copy(gw, imageSaveTarStream); err != nil {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - failed to copy tar archive for %s to gzip writer: %s", imageFullName, err)
|
||||
errorGzipImageList = append(errorGzipImageList, imageFullName)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if err := gw.Close(); err != nil {
|
||||
log.ErrorF("[SaveImagesToGzipFile] - error closing gzip writer: %s", err)
|
||||
return false, "", errorGzipImageList
|
||||
}
|
||||
|
||||
log.InfoF("[SaveImagesToGzipFile] - successfully saved images to [%s]", gzipFileFullPath)
|
||||
//if len(imageFullNames) == 0 {
|
||||
// log.Error("[SaveImagesToGzipFile] - no images provided")
|
||||
// return false, "", errorGzipImageList
|
||||
//}
|
||||
//
|
||||
//// 确保输出文件路径
|
||||
//gzipFileFullPath = folderPathPrefix + outputFileName
|
||||
//if err := os.MkdirAll(filepath.Dir(gzipFileFullPath), os.ModePerm); err != nil {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - failed to create directory: %s", err)
|
||||
// return false, "", errorGzipImageList
|
||||
//}
|
||||
//
|
||||
//log.InfoF("[SaveImagesToGzipFile] - start saving images to [%s]", gzipFileFullPath)
|
||||
//
|
||||
//// 删除旧的Gzip文件
|
||||
//if err := os.Remove(gzipFileFullPath); err != nil && !os.IsNotExist(err) {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - failed to remove old gzip file: %s", err)
|
||||
// return false, "", errorGzipImageList
|
||||
//}
|
||||
//
|
||||
//tarFile, err := os.Create(gzipFileFullPath)
|
||||
//if err != nil {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - error creating gzip file: %s", err)
|
||||
// return false, "", errorGzipImageList
|
||||
//}
|
||||
//defer tarFile.Close()
|
||||
//
|
||||
//gw, err := pgzip.NewWriterLevel(tarFile, pgzip.DefaultCompression)
|
||||
//if err != nil {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - pgzip writer creation error: %s", err)
|
||||
// return false, "", errorGzipImageList
|
||||
//}
|
||||
//defer gw.Close()
|
||||
//
|
||||
//for _, imageFullName := range imageFullNames {
|
||||
// imageGetByName := GetByName(imageFullName)
|
||||
// if imageGetByName == nil {
|
||||
// log.WarnF("[SaveImagesToGzipFile] - %s not exists, skipping", imageFullName)
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// imageSaveTarStream, err := apiClient.ImageSave(context.TODO(), imageGetByName.RepoTags)
|
||||
// if err != nil {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - image save error for %s: %s", imageFullName, err)
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// if _, err := io.Copy(gw, imageSaveTarStream); err != nil {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - failed to copy tar archive for %s to gzip writer: %s", imageFullName, err)
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
||||
//if err := gw.Close(); err != nil {
|
||||
// log.ErrorF("[SaveImagesToGzipFile] - error closing gzip writer: %s", err)
|
||||
// return false, "", errorGzipImageList
|
||||
//}
|
||||
//
|
||||
//log.InfoF("[SaveImagesToGzipFile] - successfully saved images to [%s]", gzipFileFullPath)
|
||||
return true, gzipFileFullPath, errorGzipImageList
|
||||
|
||||
}
|
||||
|
||||
func CmiiImageMapToFullNameList(cmiiImageVersionMap map[string]string) (fullImageNameList []string) {
|
||||
|
||||
Reference in New Issue
Block a user