From 2900dc19267bc9f9de4081a2c84ef0c3f78f7fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E7=BE=8A=E7=BE=8A?= Date: Wed, 15 Apr 2020 18:24:20 +0800 Subject: [PATCH 1/2] use password push image --- builder/exector/import_app.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/builder/exector/import_app.go b/builder/exector/import_app.go index f8f51f40a..8c35d983f 100644 --- a/builder/exector/import_app.go +++ b/builder/exector/import_app.go @@ -384,8 +384,18 @@ func (i *ImportApp) importPlugins() error { return err } // 上传到仓库 - user := plugin.Get("plugin_image.hub_user").String() - pass := plugin.Get("plugin_image.hub_password").String() + user := builder.REGISTRYUSER + hubUser := plugin.Get("plugin_image.hub_user").String() + if hubUser != "" { + logrus.Debugf("plugin image hub user is : %s", hubUser) + user = hubUser + } + pass := builder.REGISTRYPASS + hubPass := plugin.Get("plugin_image.hub_password").String() + if hubPass != "" { + logrus.Debugf("plugin image hub password is : %s", hubUser) + pass = hubPass + } // 上传之前先要根据新的仓库地址修改镜像名 image := i.oldPluginPath[plugin.Get("plugin_id").String()] imageName := sources.ImageNameWithNamespaceHandle(image) @@ -437,8 +447,18 @@ func (i *ImportApp) loadApps() error { // 上传到仓库 oldImage := i.oldAPPPath[app.Get("service_key").String()] oldImageName := sources.ImageNameWithNamespaceHandle(oldImage) - user := app.Get("service_image.hub_user").String() - pass := app.Get("service_image.hub_password").String() + user := builder.REGISTRYUSER + hubUser := app.Get("service_image.hub_user").String() + if hubUser != "" { + logrus.Debugf("app service image hub user is : %s", hubUser) + user = hubUser + } + pass := builder.REGISTRYPASS + hubPass := app.Get("service_image.hub_password").String() + if hubPass != "" { + logrus.Debugf("app service image hub password is : %s", hubPass) + pass = hubPass + } // 上传之前先要根据新的仓库地址修改镜像名 image := app.Get("share_image").String() if err := sources.ImageTag(i.DockerClient, fmt.Sprintf("%s/%s:%s", builder.REGISTRYDOMAIN, oldImageName.Name, oldImageName.Tag), image, i.Logger, 15); err != nil { From 07003a43650c5fb7b9b916b653205f913591e948 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=87=A1=E7=BE=8A=E7=BE=8A?= Date: Wed, 15 Apr 2020 18:41:09 +0800 Subject: [PATCH 2/2] update code --- builder/exector/import_app.go | 28 ++++------------------------ builder/repostory.go | 8 ++++++++ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/builder/exector/import_app.go b/builder/exector/import_app.go index 8c35d983f..4bbfdea5a 100644 --- a/builder/exector/import_app.go +++ b/builder/exector/import_app.go @@ -384,18 +384,8 @@ func (i *ImportApp) importPlugins() error { return err } // 上传到仓库 - user := builder.REGISTRYUSER - hubUser := plugin.Get("plugin_image.hub_user").String() - if hubUser != "" { - logrus.Debugf("plugin image hub user is : %s", hubUser) - user = hubUser - } - pass := builder.REGISTRYPASS - hubPass := plugin.Get("plugin_image.hub_password").String() - if hubPass != "" { - logrus.Debugf("plugin image hub password is : %s", hubUser) - pass = hubPass - } + // get docker account user and pass + user, pass := builder.GetImageUserInfo(plugin.Get("plugin_image.hub_user").String(), plugin.Get("plugin_image.hub_password").String()) // 上传之前先要根据新的仓库地址修改镜像名 image := i.oldPluginPath[plugin.Get("plugin_id").String()] imageName := sources.ImageNameWithNamespaceHandle(image) @@ -447,18 +437,8 @@ func (i *ImportApp) loadApps() error { // 上传到仓库 oldImage := i.oldAPPPath[app.Get("service_key").String()] oldImageName := sources.ImageNameWithNamespaceHandle(oldImage) - user := builder.REGISTRYUSER - hubUser := app.Get("service_image.hub_user").String() - if hubUser != "" { - logrus.Debugf("app service image hub user is : %s", hubUser) - user = hubUser - } - pass := builder.REGISTRYPASS - hubPass := app.Get("service_image.hub_password").String() - if hubPass != "" { - logrus.Debugf("app service image hub password is : %s", hubPass) - pass = hubPass - } + // get docker account user and pass + user, pass := builder.GetImageUserInfo(app.Get("service_image.hub_user").String(), app.Get("service_image.hub_password").String()) // 上传之前先要根据新的仓库地址修改镜像名 image := app.Get("share_image").String() if err := sources.ImageTag(i.DockerClient, fmt.Sprintf("%s/%s:%s", builder.REGISTRYDOMAIN, oldImageName.Name, oldImageName.Tag), image, i.Logger, 15); err != nil { diff --git a/builder/repostory.go b/builder/repostory.go index 0e52edfd4..91f790729 100644 --- a/builder/repostory.go +++ b/builder/repostory.go @@ -48,6 +48,14 @@ func init() { BUILDERIMAGENAME = path.Join(REGISTRYDOMAIN, BUILDERIMAGENAME) } +// GetImageUserInfo - +func GetImageUserInfo(user, pass string) (string, string) { + if user != "" && pass != "" { + return user, pass + } + return REGISTRYUSER, REGISTRYPASS +} + //REGISTRYDOMAIN REGISTRY_DOMAIN var REGISTRYDOMAIN = constants.DefImageRepository