[agent-operator] - image bastion mode
This commit is contained in:
@@ -86,6 +86,7 @@ var CmiiGISAppMap = map[string]string{
|
||||
"cmii-uav-grid-engine": "5.4.0",
|
||||
"cmii-uav-grid-manage": "5.4.0",
|
||||
}
|
||||
|
||||
var CmiiDevK8sConfig = `apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
|
||||
@@ -36,6 +36,7 @@ const (
|
||||
DefaultAccessKeyID = "cmii"
|
||||
DefaultSecretAccessKey = "B#923fC7mk"
|
||||
DefaultOctopusBucketName = "octopus"
|
||||
DefaultOssUrlPrefix = "https://oss.demo.uavcmlc.com/cmlc-installation/tmp/"
|
||||
)
|
||||
|
||||
func (op *CmiiMinioOperator) buildCmiiMinioOperator() {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -18,15 +20,16 @@ const PublicDeployHarborHost = "42.192.52.227"
|
||||
const DirectPushDeployHarborHost = "36.134.71.138"
|
||||
|
||||
type ImageSyncEntity struct {
|
||||
ProjectName string // 优先级3
|
||||
ProjectVersion string // 优先级2
|
||||
CmiiNameTagList []string // 优先级1 appName:tag的形式
|
||||
FullNameImageList []string // 优先级1
|
||||
DownloadImage bool // 下载镜像
|
||||
CompressImageToGzip bool // 压缩镜像
|
||||
UploadToDemoMinio bool // 上传镜像
|
||||
ShouldDirectPushToHarbor bool // 直接推送到对方的主机 || 离线部署机 使用此部门
|
||||
DirectHarborHost string // 目标Harbor仓库的Host,全名称带端口 不带http前缀
|
||||
ProjectName string // 优先级3
|
||||
ProjectFromDemoNameNotNull bool
|
||||
ProjectVersion string // 优先级2
|
||||
CmiiNameTagList []string // 优先级1 appName:tag的形式
|
||||
FullNameImageList []string // 优先级1
|
||||
DownloadFromOss bool // 下载镜像
|
||||
CompressImageToGzip bool // 压缩镜像
|
||||
UploadToDemoMinio bool // 上传镜像
|
||||
ShouldDirectPushToHarbor bool // 直接推送到对方的主机 || 离线部署机 使用此部门
|
||||
DirectHarborHost string // 目标Harbor仓库的Host,全名称带端口 不带http前缀
|
||||
}
|
||||
|
||||
type ImageSyncResult struct {
|
||||
@@ -76,7 +79,7 @@ func (sync ImageSyncEntity) PullFromEntityAndSyncConditionally() (imageSyncResul
|
||||
allCmiiImageNameList = concatAndUniformCmiiImage(sync.FullNameImageList, sync.CmiiNameTagList)
|
||||
|
||||
// DCU
|
||||
errorPullImageList, errorGzipImageList, realCmiiImageList, allGzipFileNameList = DownloadCompressUploadFromFullNameList(allCmiiImageNameList, sync.CompressImageToGzip, gzipFolderFullPath, sync.UploadToDemoMinio)
|
||||
errorPullImageList, errorGzipImageList, realCmiiImageList, allGzipFileNameList = DownloadCompressUpload(allCmiiImageNameList, sync.CompressImageToGzip, gzipFolderFullPath, sync.UploadToDemoMinio)
|
||||
}
|
||||
|
||||
// 直接传输到目标Harbor仓库
|
||||
@@ -118,7 +121,8 @@ func concatAndUniformCmiiImage(fullImageList []string, cmiiImageList []string) [
|
||||
return fullImageList
|
||||
}
|
||||
|
||||
func DownloadCompressUploadFromFullNameList(fullNameList []string, shouldGzip bool, gzipFolderFullPath string, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
// DownloadCompressUpload DCU 镜像同步的前半部分,通常在35.71 LapPro执行,无需Bastion Mode
|
||||
func DownloadCompressUpload(fullNameList []string, shouldGzip bool, gzipFolderFullPath string, shouldOss bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
|
||||
// Download
|
||||
log.Info("DOWNLOAD START !")
|
||||
@@ -190,8 +194,62 @@ func DownloadCompressUploadFromFullNameList(fullNameList []string, shouldGzip bo
|
||||
return errorPullImageList, errorGzipImageList, fullNameList, allGzipFileNameList
|
||||
}
|
||||
|
||||
func uploadGzipFileToDemoMinio() {
|
||||
// DownloadLoadTagPush DLTU procedure ImageSync的另外一般流程,需要支持 堡垒机(纯离线)的模式
|
||||
// 1. 文件模式,从文件中读取全部的镜像全名称-写死到文件中
|
||||
// 2. Gzip文件目录,RKE MIDDLE CMII三个文件目录 - 是否需要约定目录
|
||||
// 约定目录 /root/wdd/image/rke/ /root/wdd/image/middle/ /root/wdd/image/cmii/
|
||||
// 3. 读取本机的IP地址 - 或者进行参数传递
|
||||
// 4. OSS地址 - 参数传递gizpFileName
|
||||
func DownloadLoadTagPush(downloadFromOss bool, ossUrlPrefix, localGzipFolder string, targetHarborFullName string) []string {
|
||||
|
||||
// download
|
||||
if downloadFromOss {
|
||||
parseAndDownloadFromOssUrlPrefix(ossUrlPrefix, localGzipFolder)
|
||||
}
|
||||
// load
|
||||
loadAllGzipImageFromLocalFolder(localGzipFolder)
|
||||
image.LoadFromFolderPath(localGzipFolder)
|
||||
|
||||
// tag
|
||||
// push
|
||||
allFileInFolder, err := utils.ListAllFileInFolder(localGzipFolder)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
for _, gzipFileName := range allFileInFolder {
|
||||
log.DebugF("gzip file name is %s", gzipFileName)
|
||||
imageFullName := image2.GzipFileNameToImageFullName(gzipFileName)
|
||||
if imageFullName == "" {
|
||||
log.ErrorF("gzip file %s to image full name error !", gzipFileName)
|
||||
continue
|
||||
}
|
||||
targetImageFullName := image2.ImageNameToTargetImageFullName(imageFullName, targetHarborFullName)
|
||||
|
||||
// tag
|
||||
image.TagFromSourceToTarget(imageFullName, targetImageFullName)
|
||||
//push
|
||||
pushResult := image.PushToOctopusKindHarbor(targetImageFullName)
|
||||
defer pushResult.Close()
|
||||
|
||||
scanner := bufio.NewScanner(pushResult)
|
||||
for scanner.Scan() {
|
||||
}
|
||||
fmt.Println()
|
||||
fmt.Printf("%s to %s push success !", gzipFileName, targetImageFullName)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadAllGzipImageFromLocalFolder(localGzipFolder string) {
|
||||
|
||||
}
|
||||
|
||||
// todo
|
||||
func parseAndDownloadFromOssUrlPrefix(ossUrlPrefix string, localGzipFolder string) {
|
||||
|
||||
// 解析
|
||||
}
|
||||
|
||||
// DownloadCompressUploadFromDemo 获取DEMO环境的全部镜像
|
||||
@@ -211,7 +269,7 @@ func DownloadCompressUploadFromDemo(projectName string, shouldGzip bool, shouldO
|
||||
|
||||
// do work
|
||||
// DCU
|
||||
return DownloadCompressUploadFromFullNameList(allCmiiImageNameListFromDemo, shouldGzip, OfflineImageGzipFolderPrefix+projectName, shouldOss)
|
||||
return DownloadCompressUpload(allCmiiImageNameListFromDemo, shouldGzip, OfflineImageGzipFolderPrefix+projectName, shouldOss)
|
||||
}
|
||||
|
||||
func buildAllCmiiImageNameListFromDemo(projectName string) []string {
|
||||
@@ -267,7 +325,7 @@ func DownloadCompressUploadFromVersion(cmiiVersion string, shouldGzip bool, shou
|
||||
|
||||
// do work
|
||||
// DCU procedure
|
||||
return DownloadCompressUploadFromFullNameList(realCmiiImageName, shouldGzip, OfflineImageGzipFolderPrefix+cmiiVersion, shouldOss)
|
||||
return DownloadCompressUpload(realCmiiImageName, shouldGzip, OfflineImageGzipFolderPrefix+cmiiVersion, shouldOss)
|
||||
|
||||
}
|
||||
|
||||
@@ -308,7 +366,7 @@ func buildAllCmiiImageNameListFromVersion(cmiiVersion string) []string {
|
||||
return realCmiiImageName
|
||||
}
|
||||
|
||||
func DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool) (errorPullImageList, errorGzipImageList []string) {
|
||||
func DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool, downloadMiddle bool, downloadRke bool) (errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList []string) {
|
||||
err := os.MkdirAll(OfflineImageGzipFolderPrefix, os.ModeDir)
|
||||
if err != nil {
|
||||
if !errors.Is(err, os.ErrExist) {
|
||||
@@ -316,14 +374,22 @@ func DownloadCompressUploadDependency(shouldGzip bool, shouldOss bool) (errorPul
|
||||
}
|
||||
}
|
||||
|
||||
// pull middleware images
|
||||
errorPullImageList, errorGzipImageList = image.PullFromListAndCompressSplit(image.MiddlewareAmd64, OfflineImageGzipFolderPrefix+"middle/")
|
||||
if downloadMiddle {
|
||||
|
||||
// pull rke images
|
||||
pull, gzipImageList := image.PullFromListAndCompressSplit(image.Rancher1204Amd64, OfflineImageGzipFolderPrefix+"rke/")
|
||||
gzipFolderPrefix := OfflineImageGzipFolderPrefix + "middle/"
|
||||
|
||||
// result
|
||||
return append(errorPullImageList, pull...), append(errorGzipImageList, gzipImageList...)
|
||||
// remove folder first
|
||||
utils.RemoveFolderComplete(gzipFolderPrefix)
|
||||
|
||||
return DownloadCompressUpload(image.MiddlewareAmd64, shouldGzip, gzipFolderPrefix, shouldOss)
|
||||
}
|
||||
|
||||
if downloadRke {
|
||||
gzipFolderPrefix := OfflineImageGzipFolderPrefix + "rke/"
|
||||
return DownloadCompressUpload(image.MiddlewareAmd64, shouldGzip, gzipFolderPrefix, shouldOss)
|
||||
}
|
||||
|
||||
return errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList
|
||||
}
|
||||
|
||||
func LoadSplitCmiiGzipImageToTargetHarbor(projectName, targetHarborHost string) (errorLoadImageNameList, errorPushImageNameList []string) {
|
||||
|
||||
@@ -9,29 +9,15 @@ import (
|
||||
/* 拉取
|
||||
*/
|
||||
|
||||
func TestFetchDemoImages(t *testing.T) {
|
||||
|
||||
//errorPullImageList, errorGzipImageList, allCmiiImageName := DownloadCompressUploadFromDemo("shls", true)
|
||||
//
|
||||
//utils.BeautifulPrintListWithTitle(errorPullImageList, "cmii errorPullImageList")
|
||||
//utils.BeautifulPrintListWithTitle(errorGzipImageList, "cmii errorGzipImageList")
|
||||
//utils.BeautifulPrintListWithTitle(allCmiiImageName, "cmii allCmiiImageName")
|
||||
}
|
||||
|
||||
func TestFetchVersionImages(t *testing.T) {
|
||||
//errorPullImageList, errorGzipImageList, allCmiiImageName := DownloadCompressUploadFromVersion("5.4.0", true)
|
||||
//
|
||||
//utils.BeautifulPrintListWithTitle(errorPullImageList, "cmii errorPullImageList")
|
||||
//utils.BeautifulPrintListWithTitle(errorGzipImageList, "cmii errorGzipImageList")
|
||||
//utils.BeautifulPrintListWithTitle(allCmiiImageName, "cmii allCmiiImageName")
|
||||
}
|
||||
|
||||
func TestFetchDependencyRepos(t *testing.T) {
|
||||
|
||||
//errorPullImageList, errorGzipImageList := FetchDependencyRepos(true)
|
||||
//
|
||||
//utils.BeautifulPrintListWithTitle(errorPullImageList, "dep errorPullImageList")
|
||||
//utils.BeautifulPrintListWithTitle(errorGzipImageList, "dep errorGzipImageList")
|
||||
errorPullImageList, errorGzipImageList, realCmiiImageName, allGzipFileNameList := DownloadCompressUploadDependency(true, false, true, false)
|
||||
|
||||
utils.BeautifulPrintListWithTitle(errorPullImageList, "errorPullImageList")
|
||||
utils.BeautifulPrintListWithTitle(errorGzipImageList, "errorGzipImageList")
|
||||
utils.BeautifulPrintListWithTitle(realCmiiImageName, "realCmiiImageName")
|
||||
utils.BeautifulPrintListWithTitle(allGzipFileNameList, "allGzipFileNameList")
|
||||
|
||||
}
|
||||
|
||||
func TestLoadSplitGzipImageToTargetHarbor(t *testing.T) {
|
||||
|
||||
@@ -71,12 +71,12 @@ require (
|
||||
go.opentelemetry.io/otel/trace v1.14.0 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
go.uber.org/zap v1.27.0 // indirect
|
||||
golang.org/x/crypto v0.16.0 // indirect
|
||||
golang.org/x/crypto v0.22.0 // indirect
|
||||
golang.org/x/mod v0.14.0 // indirect
|
||||
golang.org/x/net v0.19.0 // indirect
|
||||
golang.org/x/net v0.24.0 // indirect
|
||||
golang.org/x/oauth2 v0.10.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
golang.org/x/term v0.15.0 // indirect
|
||||
golang.org/x/sys v0.19.0 // indirect
|
||||
golang.org/x/term v0.19.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/time v0.3.0 // indirect
|
||||
golang.org/x/tools v0.16.1 // indirect
|
||||
|
||||
@@ -269,8 +269,8 @@ golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPh
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
|
||||
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
|
||||
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@@ -286,8 +286,8 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
|
||||
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
|
||||
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
|
||||
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||
golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=
|
||||
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@@ -315,12 +315,12 @@ golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
|
||||
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
|
||||
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
|
||||
@@ -168,6 +168,7 @@ func TagFromSourceToTarget(sourceImageName, targetImageName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
sourceImageName = getByName.RepoTags[0]
|
||||
err := apiClient.ImageTag(context.TODO(), sourceImageName, targetImageName)
|
||||
if err != nil {
|
||||
log.ErrorF("[ImageTagFromSourceToTarget] - from %s to %s error %s", sourceImageName, targetImageName, err.Error())
|
||||
@@ -208,41 +209,47 @@ func TagFromListAndPushToCHarbor(referenceImageList []string, targetHarborHost s
|
||||
cmiiImageFullName := imageName
|
||||
|
||||
if strings.HasPrefix(imageName, "cmii") {
|
||||
// cmii-uav-gateway:v1.0.0 短名称的形式
|
||||
cmiiImageFullName = image2.CmiiHarborPrefix + imageName
|
||||
}
|
||||
|
||||
targetProject := "cmii"
|
||||
if strings.HasPrefix(imageName, "rancher") {
|
||||
// rancher/rancher:v2.5.7 rancher名称的形式
|
||||
targetProject = "rancher"
|
||||
}
|
||||
|
||||
// referenceImageList 存储的是全名称的形式
|
||||
if strings.HasPrefix(imageName, image2.CmiiHarborPrefix) {
|
||||
//
|
||||
// harbor.cdcyy.cn/cmii/cmii-uav-gateway:v1.0.0 全名称的形式 需要拿到短名称
|
||||
imageName = strings.TrimPrefix(imageName, image2.CmiiHarborPrefix)
|
||||
} else {
|
||||
// todo
|
||||
if strings.Contains(imageName, "/") {
|
||||
imageName = strings.Split(imageName, "/")[1]
|
||||
// 10.250.0.10:8033/cmii/cmii-uav-gateway:v1.0.0
|
||||
|
||||
if strings.Contains(imageName, ":8033") {
|
||||
imageName = strings.TrimLeft(imageName, ":8033")
|
||||
}
|
||||
}
|
||||
|
||||
targetImageName := targetHarborHost + ":8033/" + targetProject + "/" + imageName
|
||||
fmt.Println(cmiiImageFullName)
|
||||
fmt.Println(targetImageName)
|
||||
|
||||
if TagFromSourceToTarget(cmiiImageFullName, targetImageName) {
|
||||
pushResult := PushToOctopusKindHarbor(targetImageName)
|
||||
if pushResult == nil {
|
||||
errorPushImageNameList = append(errorPushImageNameList, cmiiImageFullName)
|
||||
log.InfoF("[ImageTagFromListAndPushToCHarbor] - push of %s error error !", targetImageName)
|
||||
break
|
||||
}
|
||||
scanner := bufio.NewScanner(pushResult)
|
||||
for scanner.Scan() {
|
||||
|
||||
}
|
||||
log.InfoF("[ImageTagFromListAndPushToCHarbor] - push of %s success!", targetImageName)
|
||||
} else {
|
||||
errorPushImageNameList = append(errorPushImageNameList, cmiiImageFullName)
|
||||
}
|
||||
//if TagFromSourceToTarget(cmiiImageFullName, targetImageName) {
|
||||
// pushResult := PushToOctopusKindHarbor(targetImageName)
|
||||
// if pushResult == nil {
|
||||
// errorPushImageNameList = append(errorPushImageNameList, cmiiImageFullName)
|
||||
// log.InfoF("[ImageTagFromListAndPushToCHarbor] - push of %s error error !", targetImageName)
|
||||
// break
|
||||
// }
|
||||
// scanner := bufio.NewScanner(pushResult)
|
||||
// for scanner.Scan() {
|
||||
//
|
||||
// }
|
||||
// log.InfoF("[ImageTagFromListAndPushToCHarbor] - push of %s success!", targetImageName)
|
||||
//} else {
|
||||
// errorPushImageNameList = append(errorPushImageNameList, cmiiImageFullName)
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
@@ -361,6 +368,7 @@ func PullFromListAndCompressSplit(fullImageNameList []string, gzipFolder string)
|
||||
return errorPullImageList, errorGzipImageList
|
||||
}
|
||||
|
||||
// LoadFromGzipFilePath 根据Gzip文件的全名称进行Load操作
|
||||
func LoadFromGzipFilePath(gzipFullPath string) bool {
|
||||
openFile, err := os.OpenFile(gzipFullPath, 0, fs.ModePerm)
|
||||
if err != nil {
|
||||
@@ -386,6 +394,7 @@ func LoadFromGzipFilePath(gzipFullPath string) bool {
|
||||
}
|
||||
|
||||
func LoadFromFolderPath(folderPath string) (errorLoadImageNameList []string) {
|
||||
|
||||
if !strings.HasSuffix(folderPath, "/") {
|
||||
folderPath += "/"
|
||||
}
|
||||
|
||||
@@ -99,7 +99,8 @@ func TestImagePushToOctopusKindHarbor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestImageLoadFromFile(t *testing.T) {
|
||||
loadFromFile := LoadFromGzipFilePath("/root/octopus_image/cqga/cqga/cmlc=cmii=cmii-uav-user=5.2.0.tar.gz")
|
||||
|
||||
loadFromFile := LoadFromGzipFilePath("/root/cmlc=cmii=srs=v5.0.195.tar.gz")
|
||||
|
||||
assert.Equal(t, loadFromFile, true, "image load error !")
|
||||
}
|
||||
@@ -126,9 +127,11 @@ func TestImageFullNameToGzipFileName(t *testing.T) {
|
||||
"busybox",
|
||||
}
|
||||
|
||||
test = append(test, MiddlewareAmd64...)
|
||||
|
||||
for _, s := range test {
|
||||
gzipFileName := image.ImageFullNameToGzipFileName(s)
|
||||
fmt.Printf(" %s to %s \n", s, gzipFileName)
|
||||
fmt.Println(gzipFileName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"wdd.io/agent-common/utils"
|
||||
"wdd.io/agent-operator/real_project/bgtg"
|
||||
)
|
||||
@@ -71,7 +75,64 @@ func CmiiRunner() {
|
||||
|
||||
}
|
||||
|
||||
var DLTUHelp = `
|
||||
DLTUHelp
|
||||
dltu [ossUrl] [localGzipFolder] [harborHostFullName]
|
||||
`
|
||||
|
||||
func main() {
|
||||
|
||||
RealProjectRunner()
|
||||
//RealProjectRunner()
|
||||
|
||||
// 解析命令行参数
|
||||
var mode string
|
||||
flag.StringVar(&mode, "mode", "mode", "agent run mode")
|
||||
flag.Parse()
|
||||
|
||||
if mode == "image" {
|
||||
// 堡垒机模式 的 镜像美容
|
||||
// 初始化堡垒机模式
|
||||
for {
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
fmt.Printf(DLTUHelp)
|
||||
fmt.Print("enter ==> ")
|
||||
|
||||
text, _ := reader.ReadString('\n')
|
||||
split := strings.Split(text, " ")
|
||||
var result []string
|
||||
for _, s := range split {
|
||||
text = strings.TrimSpace(s)
|
||||
if text == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
result = append(result, text)
|
||||
}
|
||||
|
||||
if len(result) != 4 {
|
||||
fmt.Println("input error!")
|
||||
fmt.Printf(DLTUHelp)
|
||||
return
|
||||
}
|
||||
|
||||
ossUrl := result[1]
|
||||
localGzipFolder := result[2]
|
||||
harborHostFullName := result[3]
|
||||
|
||||
fmt.Println("ossUrl: ", ossUrl)
|
||||
fmt.Println("localGzipFolder: ", localGzipFolder)
|
||||
fmt.Println("harborHostFullName: ", harborHostFullName)
|
||||
fmt.Println()
|
||||
|
||||
DownloadLoadTagPush(false, ossUrl, localGzipFolder, harborHostFullName)
|
||||
|
||||
// 下载
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user