[ Cmii ] [ Operator ] - optimize Image pull

This commit is contained in:
zeaslity
2024-01-25 12:07:17 +08:00
parent 5069372348
commit 84455a8849
5 changed files with 71 additions and 51 deletions

View File

@@ -9,14 +9,14 @@ import (
const OfflineImageGzipFolderPrefix = "/root/octopus_image/"
func FetchDemoImages(projectName string, gzipSplit bool) bool {
func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, errorGzipImageList []string) {
// generate a project folder
err := os.Mkdir(OfflineImageGzipFolderPrefix+projectName, os.ModeDir)
if err != nil {
if !errors.Is(err, os.ErrExist) {
log.ErrorF("[FetchDemoImages] - create folder of %s error %s", OfflineImageGzipFolderPrefix+projectName, err.Error())
return false
return errorPullImageList, errorGzipImageList
}
}
@@ -42,26 +42,33 @@ func FetchDemoImages(projectName string, gzipSplit bool) bool {
)
// download image
ImagePullFromCmiiHarborByMap(backendMap, true)
ImagePullFromCmiiHarborByMap(frontendMap, true)
backendPull := ImagePullFromCmiiHarborByMap(backendMap, true)
frontendPull := ImagePullFromCmiiHarborByMap(frontendMap, true)
// compress image
if gzipSplit {
for image, tag := range backendMap {
ImageSaveToTarGZ(image+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/")
if !ImageSaveToTarGZ(image+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
errorGzipImageList = append(errorGzipImageList, CmiiHarborPrefix+image+":"+tag)
}
}
for image, tag := range frontendMap {
ImageSaveToTarGZ(image+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/")
if !ImageSaveToTarGZ(image+":"+tag, OfflineImageGzipFolderPrefix+projectName+"/app/") {
errorGzipImageList = append(errorGzipImageList, CmiiHarborPrefix+image+":"+tag)
}
}
}
// upload to harbor
// clean up images
return false
errorPullImageList = append(errorPullImageList, backendPull...)
errorPullImageList = append(errorPullImageList, frontendPull...)
return errorPullImageList, errorGzipImageList
}
func FetchDependencyRepos(gzipSplit bool) {
func FetchDependencyRepos(gzipSplit bool) (errorPullImageList, errorGzipImageList []string) {
err := os.Mkdir(OfflineImageGzipFolderPrefix, os.ModeDir)
if err != nil {
if !errors.Is(err, os.ErrExist) {
@@ -69,8 +76,10 @@ func FetchDependencyRepos(gzipSplit bool) {
}
}
ImagePullFromListAndCompressSplit(MiddlewareAmd64, OfflineImageGzipFolderPrefix+"middle/")
errorPullImageList, errorGzipImageList = ImagePullFromListAndCompressSplit(MiddlewareAmd64, OfflineImageGzipFolderPrefix+"middle/")
ImagePullFromListAndCompressSplit(Rancher1204Amd64, OfflineImageGzipFolderPrefix+"rke/")
pull, gzipImageList := ImagePullFromListAndCompressSplit(Rancher1204Amd64, OfflineImageGzipFolderPrefix+"rke/")
return append(errorPullImageList, pull...), append(errorGzipImageList, gzipImageList...)
}