Merge pull request #811 from GLYASAI/V5.2

image build error
This commit is contained in:
黄润豪 2020-07-28 19:11:07 +08:00 committed by GitHub
commit 819f5040ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 8 deletions

View File

@ -141,7 +141,7 @@ func (a *AppStruct) ImportID(w http.ResponseWriter, r *http.Request) {
cmd.Stdout = &out
err := cmd.Run()
logrus.Infof("cmd return is : %s", out.String())
if err != nil {
if err != nil && err.Error() != "exit status 1" {
logrus.Errorf("rm -rf %s failed: %s", dirName, err.Error())
httputil.ReturnError(r, w, 501, "Failed to delete directory by id: "+eventID)
return

View File

@ -73,7 +73,8 @@ func NewImageBuildItem(in []byte) *ImageBuildItem {
//Run Run
func (i *ImageBuildItem) Run(timeout time.Duration) error {
_, err := sources.ImagePull(i.DockerClient, i.Image, i.HubUser, i.HubPassword, i.Logger, 30)
user, pass := builder.GetImageUserInfoV2(i.Image, i.HubUser, i.HubPassword)
_, err := sources.ImagePull(i.DockerClient, i.Image, user, pass, i.Logger, 30)
if err != nil {
logrus.Errorf("pull image %s error: %s", i.Image, err.Error())
i.Logger.Error(fmt.Sprintf("获取指定镜像: %s失败", i.Image), map[string]string{"step": "builder-exector", "status": "failure"})

View File

@ -275,10 +275,10 @@ func (i *ImportApp) importPlugins() error {
return err
}
oldPlugins, err := meta.Get("plugins").Array()
if err != nil {
logrus.Errorf("Failed to get plugins from meta for load app %s: %v", i.SourceDir, err)
return nil
var oldPlugins []interface{}
if plugins, err := meta.Get("plugins").Array(); err != nil {
logrus.Warningf("Failed to get plugins from meta for load app %s: %v", i.SourceDir, err)
oldPlugins = plugins
}
for index := range oldPlugins {
@ -370,7 +370,8 @@ func (i *ImportApp) loadApps() error {
return err
}
for _, app := range apps {
for idx := range apps {
app := apps[idx]
serviceName := app.Get("service_cname").String()
serviceName = unicode2zh(serviceName)
serviceDir := fmt.Sprintf("%s/%s", i.SourceDir, serviceName)
@ -393,6 +394,7 @@ func (i *ImportApp) loadApps() error {
saveImageName := sources.GenSaveImageName(oldImage)
// 上传之前先要根据新的仓库地址修改镜像名
image := app.Get("share_image").String()
logrus.Debugf("[loadApps] target image: %s", image)
if err := sources.ImageTag(i.DockerClient, saveImageName, image, i.Logger, 15); err != nil {
if strings.Contains(err.Error(), "No such image") {
err = sources.ImageTag(i.DockerClient, "goodrain.me/"+saveImageName, image, i.Logger, 2)

View File

@ -21,6 +21,7 @@ package builder
import (
"os"
"path"
"strings"
"github.com/goodrain/rainbond/util/constants"
)
@ -48,7 +49,7 @@ func init() {
BUILDERIMAGENAME = path.Join(REGISTRYDOMAIN, BUILDERIMAGENAME)
}
// GetImageUserInfo -
// GetImageUserInfo - deprecated
func GetImageUserInfo(user, pass string) (string, string) {
if user != "" && pass != "" {
return user, pass
@ -56,6 +57,17 @@ func GetImageUserInfo(user, pass string) (string, string) {
return REGISTRYUSER, REGISTRYPASS
}
// GetImageUserInfoV2 -
func GetImageUserInfoV2(domain, user, pass string) (string, string) {
if user != "" && pass != "" {
return user, pass
}
if strings.HasPrefix(domain, REGISTRYDOMAIN) {
return REGISTRYUSER, REGISTRYPASS
}
return "", ""
}
//REGISTRYDOMAIN REGISTRY_DOMAIN
var REGISTRYDOMAIN = constants.DefImageRepository