mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-22 00:00:50 +00:00
feat: update app upgrade logic (#13032)
This commit is contained in:
@@ -765,33 +765,6 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
|
||||
install.Env = string(paramByte)
|
||||
content = setVllmImageInEnvContent(content, image)
|
||||
}
|
||||
if req.PullImage {
|
||||
composeContent := []byte(detail.DockerCompose)
|
||||
if install.App.Key == vllmAppKeyForUpgrade {
|
||||
composeContent = []byte(install.DockerCompose)
|
||||
}
|
||||
if req.DockerCompose != "" {
|
||||
composeContent = []byte(req.DockerCompose)
|
||||
}
|
||||
images, err := docker.GetImagesFromDockerCompose(content, composeContent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dockerCLi, err := docker.NewClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dockerCLi.Close()
|
||||
for _, image := range images {
|
||||
t.Log(i18n.GetWithName("PullImageStart", image))
|
||||
if err = dockerCLi.PullImageWithProcess(t, image); err != nil {
|
||||
err = buserr.WithNameAndErr("ErrDockerPullImage", "", err)
|
||||
return err
|
||||
}
|
||||
t.LogSuccess(i18n.GetMsgByKey("PullImage"))
|
||||
}
|
||||
}
|
||||
|
||||
_ = copyAppDetailMissing(fileOp, detailDir, install.GetPath())
|
||||
if install.App.Key == constant.AppOpenresty {
|
||||
installBuildDir := path.Join(install.GetPath(), "build")
|
||||
@@ -847,6 +820,29 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
|
||||
install.Version = detail.Version
|
||||
install.AppDetailId = req.DetailID
|
||||
|
||||
if req.PullImage {
|
||||
images, err := docker.GetImagesFromDockerCompose(content, []byte(install.DockerCompose))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dockerCLi, err := docker.NewClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer dockerCLi.Close()
|
||||
for _, image := range images {
|
||||
t.Log(i18n.GetWithName("PullImageStart", image))
|
||||
if err = dockerCLi.PullImageWithProcess(t, image); err != nil {
|
||||
return buserr.WithNameAndErr("ErrDockerPullImage", "", err)
|
||||
}
|
||||
exist, err := dockerCLi.ImageExists(image)
|
||||
if err != nil || !exist {
|
||||
return buserr.WithNameAndErr("ErrDockerPullImage", "", fmt.Errorf("image %s does not exist after pull: %v", image, err))
|
||||
}
|
||||
t.LogSuccess(i18n.GetMsgByKey("PullImage"))
|
||||
}
|
||||
}
|
||||
|
||||
if out, err := compose.Down(install.GetComposePath()); err != nil {
|
||||
if out != "" {
|
||||
upErr = errors.New(out)
|
||||
|
||||
@@ -199,20 +199,33 @@ func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
return handlePullImageProcess(out, task)
|
||||
}
|
||||
|
||||
func handlePullImageProcess(out io.Reader, task *task.Task) error {
|
||||
decoder := json.NewDecoder(out)
|
||||
for {
|
||||
var progress map[string]interface{}
|
||||
if err = decoder.Decode(&progress); err != nil {
|
||||
if err := decoder.Decode(&progress); err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
return err
|
||||
}
|
||||
status, _ := progress["status"].(string)
|
||||
if status == "Downloading" || status == "Extracting" {
|
||||
logProcess(progress, task)
|
||||
if msg, ok := progress["errorDetail"]; ok {
|
||||
return fmt.Errorf("image pull failed, err: %v", msg)
|
||||
}
|
||||
if status == "Pull complete" || status == "Download complete" {
|
||||
if msg, ok := progress["error"]; ok {
|
||||
return fmt.Errorf("image pull failed, err: %v", msg)
|
||||
}
|
||||
if task == nil {
|
||||
continue
|
||||
}
|
||||
status, _ := progress["status"].(string)
|
||||
switch status {
|
||||
case "Downloading", "Extracting":
|
||||
logProcess(progress, task)
|
||||
case "Pull complete", "Download complete", "Already exists", "Verifying Checksum":
|
||||
id, _ := progress["id"].(string)
|
||||
progressStr := fmt.Sprintf("%s %s", status, id)
|
||||
_ = setLog(id, progressStr, task)
|
||||
|
||||
Reference in New Issue
Block a user