[ Cmii ] [ Octopus ] - image sync refresh
This commit is contained in:
@@ -2,7 +2,9 @@ package cmii_operator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"wdd.io/agent-go/executor"
|
||||
"wdd.io/agent-go/utils"
|
||||
@@ -12,16 +14,128 @@ import (
|
||||
const OfflineImageGzipFolderPrefix = "/root/octopus_image/"
|
||||
const OfflineDeployHarborHost = "harbor.wdd.io"
|
||||
const PublicDeployHarborHost = "42.192.52.227"
|
||||
const DirectPushDeployHarborHost = "36.134.28.60"
|
||||
const DirectPushDeployHarborHost = "36.134.71.138"
|
||||
|
||||
func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, errorGzipImageList []string) {
|
||||
type ImageSyncEntity struct {
|
||||
ProjectName string
|
||||
ProjectVersion string
|
||||
DirectHarborHost string
|
||||
PushToDemoMinio bool
|
||||
}
|
||||
|
||||
type ImageSyncResult struct {
|
||||
ErrorPullImageList []string
|
||||
ErrorGzipImageList []string
|
||||
ErrorPushImageNameList []string
|
||||
RealImageNameList []string
|
||||
RealGzipFileNameList []string
|
||||
AllCmiiImageNameList []string
|
||||
}
|
||||
|
||||
func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResult ImageSyncResult) {
|
||||
|
||||
var realCmiiImageList []string
|
||||
var errorPullImageList []string
|
||||
var errorGzipImageList []string
|
||||
var allCmiiImageNameList []string
|
||||
var allGzipFileNameList []string
|
||||
var errorPushImageNameList []string
|
||||
var gzipFolderFullPath string
|
||||
// get all image name by Name or Version
|
||||
// pull images
|
||||
// compress
|
||||
if sync.ProjectVersion == "" {
|
||||
// get version
|
||||
if sync.DirectHarborHost == "" {
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchVersionImages(sync.ProjectVersion, true)
|
||||
gzipFolderFullPath = OfflineImageGzipFolderPrefix + sync.ProjectVersion
|
||||
} else {
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchVersionImages(sync.ProjectVersion, false)
|
||||
}
|
||||
} else {
|
||||
// get demo images
|
||||
if sync.DirectHarborHost == "" {
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchDemoImages(sync.ProjectName, true)
|
||||
gzipFolderFullPath = OfflineImageGzipFolderPrefix + sync.ProjectName
|
||||
} else {
|
||||
errorPullImageList, errorGzipImageList, allCmiiImageNameList = FetchDemoImages(sync.ProjectName, false)
|
||||
}
|
||||
}
|
||||
|
||||
realCmiiImageList = append(realCmiiImageList, remove(allCmiiImageNameList, errorPullImageList)...)
|
||||
realCmiiImageList = append(realCmiiImageList, remove(allCmiiImageNameList, errorGzipImageList)...)
|
||||
|
||||
// direct push if can
|
||||
if sync.DirectHarborHost != "" {
|
||||
// push to
|
||||
errorPushImageNameList = image.TagFromListAndPushToCHarbor(realCmiiImageList, sync.DirectHarborHost)
|
||||
|
||||
// build
|
||||
imageSyncResult.AllCmiiImageNameList = allCmiiImageNameList
|
||||
imageSyncResult.ErrorPullImageList = errorPullImageList
|
||||
imageSyncResult.ErrorGzipImageList = errorGzipImageList
|
||||
imageSyncResult.ErrorPushImageNameList = errorPushImageNameList
|
||||
|
||||
// no gzip file
|
||||
|
||||
return imageSyncResult
|
||||
}
|
||||
|
||||
// get gzip file name list
|
||||
err := filepath.WalkDir(gzipFolderFullPath, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
log.ErrorF("error getting gzip file name list 1! %s", err.Error())
|
||||
}
|
||||
if !d.IsDir() {
|
||||
allGzipFileNameList = append(allGzipFileNameList, d.Name())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.ErrorF("error getting gzip file name list 2! %s", err.Error())
|
||||
}
|
||||
|
||||
// push to demo minio
|
||||
if sync.PushToDemoMinio {
|
||||
log.InfoF("pretend to push to minio !")
|
||||
// create path
|
||||
// push
|
||||
}
|
||||
|
||||
// build
|
||||
imageSyncResult.AllCmiiImageNameList = allCmiiImageNameList
|
||||
imageSyncResult.ErrorPullImageList = errorPullImageList
|
||||
imageSyncResult.ErrorGzipImageList = errorGzipImageList
|
||||
imageSyncResult.ErrorPushImageNameList = errorPushImageNameList
|
||||
imageSyncResult.RealGzipFileNameList = allGzipFileNameList
|
||||
|
||||
// no gzip file
|
||||
|
||||
return imageSyncResult
|
||||
}
|
||||
|
||||
func remove(s1, s2 []string) []string {
|
||||
m := make(map[string]struct{}, len(s2))
|
||||
for _, v := range s2 {
|
||||
m[v] = struct{}{}
|
||||
}
|
||||
res := make([]string, 0, len(s1))
|
||||
for _, v := range s1 {
|
||||
if _, ok := m[v]; !ok {
|
||||
res = append(res, v)
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, errorGzipImageList, allCmiiImageName []string) {
|
||||
|
||||
// generate a project folder
|
||||
err := os.MkdirAll(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 errorPullImageList, errorGzipImageList
|
||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,9 +168,13 @@ func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, er
|
||||
)
|
||||
|
||||
// download image
|
||||
backendPull := image.ImagePullFromCmiiHarborByMap(backendMap, true)
|
||||
frontendPull := image.ImagePullFromCmiiHarborByMap(frontendMap, true)
|
||||
srsPull := image.ImagePullFromCmiiHarborByMap(srsMap, true)
|
||||
backendFullNameList, backendPull := image.PullFromCmiiHarborByMap(backendMap, true)
|
||||
frontendFullNameList, frontendPull := image.PullFromCmiiHarborByMap(frontendMap, true)
|
||||
srsFullNameList, srsPull := image.PullFromCmiiHarborByMap(srsMap, true)
|
||||
|
||||
allCmiiImageName = append(allCmiiImageName, backendFullNameList...)
|
||||
allCmiiImageName = append(allCmiiImageName, frontendFullNameList...)
|
||||
allCmiiImageName = append(allCmiiImageName, srsFullNameList...)
|
||||
|
||||
// compress image
|
||||
if gzipSplit {
|
||||
@@ -84,32 +202,30 @@ func FetchDemoImages(projectName string, gzipSplit bool) (errorPullImageList, er
|
||||
errorPullImageList = append(errorPullImageList, frontendPull...)
|
||||
errorPullImageList = append(errorPullImageList, srsPull...)
|
||||
|
||||
return errorPullImageList, errorGzipImageList
|
||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
||||
}
|
||||
|
||||
func FetchVersionImages(cmiiVersion string, gzipSplit bool) (errorPullImageList, errorGzipImageList []string) {
|
||||
func FetchVersionImages(cmiiVersion string, shouldGzip bool) (errorPullImageList, errorGzipImageList, allCmiiImageName []string) {
|
||||
|
||||
// generate a project folder
|
||||
err := os.MkdirAll(OfflineImageGzipFolderPrefix+cmiiVersion, os.ModeDir)
|
||||
if err != nil {
|
||||
if !errors.Is(err, os.ErrExist) {
|
||||
log.ErrorF("[FetchDemoImages] - create folder of %s error %s", OfflineImageGzipFolderPrefix+cmiiVersion, err.Error())
|
||||
return errorPullImageList, errorGzipImageList
|
||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
||||
}
|
||||
}
|
||||
|
||||
backendMap := CmiiBackendAppMap
|
||||
frontendMap := CmiiFrontendAppMap
|
||||
|
||||
for app, _ := range backendMap {
|
||||
for app := range backendMap {
|
||||
backendMap[app] = cmiiVersion
|
||||
}
|
||||
for app, _ := range frontendMap {
|
||||
for app := range frontendMap {
|
||||
frontendMap[app] = cmiiVersion
|
||||
}
|
||||
|
||||
var allCmiiImageName []string
|
||||
|
||||
allCmiiImageName = append(allCmiiImageName, image.ConvertCMiiImageMapToList(backendMap)...)
|
||||
allCmiiImageName = append(allCmiiImageName, image.ConvertCMiiImageMapToList(frontendMap)...)
|
||||
|
||||
@@ -130,12 +246,16 @@ func FetchVersionImages(cmiiVersion string, gzipSplit bool) (errorPullImageList,
|
||||
}
|
||||
}
|
||||
|
||||
utils.BeautifulPrint(allCmiiImageName)
|
||||
utils.BeautifulPrintListWithTitle(allCmiiImageName, "Cmii Version Image => "+cmiiVersion)
|
||||
|
||||
// do work
|
||||
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(allCmiiImageName, OfflineImageGzipFolderPrefix+cmiiVersion)
|
||||
if shouldGzip {
|
||||
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(allCmiiImageName, OfflineImageGzipFolderPrefix+cmiiVersion)
|
||||
} else {
|
||||
errorPullImageList = image.PullFromFullNameList(allCmiiImageName)
|
||||
}
|
||||
|
||||
return errorPullImageList, errorGzipImageList
|
||||
return errorPullImageList, errorGzipImageList, allCmiiImageName
|
||||
}
|
||||
|
||||
func FetchDependencyRepos(gzipSplit bool) (errorPullImageList, errorGzipImageList []string) {
|
||||
@@ -151,14 +271,13 @@ func FetchDependencyRepos(gzipSplit bool) (errorPullImageList, errorGzipImageLis
|
||||
pull, gzipImageList := image.PullFromListAndCompressSplit(image.Rancher1204Amd64, OfflineImageGzipFolderPrefix+"rke/")
|
||||
|
||||
return append(errorPullImageList, pull...), append(errorGzipImageList, gzipImageList...)
|
||||
|
||||
}
|
||||
|
||||
func LoadSplitGzipImageToTargetHarbor(projectName, targetHarborHost string) (errorLoadImageNameList, errorPushImageNameList []string) {
|
||||
func LoadSplitCmiiGzipImageToTargetHarbor(projectName, targetHarborHost string) (errorLoadImageNameList, errorPushImageNameList []string) {
|
||||
|
||||
// list folder
|
||||
projectGzipFolder := OfflineImageGzipFolderPrefix + projectName
|
||||
errorLoadImageNameList = append(errorLoadImageNameList, image.ImageLoadFromFolderPath(projectGzipFolder)...)
|
||||
errorLoadImageNameList = append(errorLoadImageNameList, image.LoadFromFolderPath(projectGzipFolder)...)
|
||||
// read from json
|
||||
errorPushImageNameList = append(errorPushImageNameList, image.TagFromListAndPushToCHarbor(image.Cmii520DemoImageList, targetHarborHost)...)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user