Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions agent/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -847,6 +820,29 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
install.Version = detail.Version
install.AppDetailId = req.DetailID

if req.PullImage {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pull images before mutating app files

When req.PullImage is true and the registry pull fails here, this block now runs after copyAppDetailMissing and the scripts/build replacements above, but before compose.Down. If the user upgraded without a backup, rollBackApp is a no-op, so the task is marked failed while the install directory has already been partially advanced to the target version, leaving the still-running old app with new support files/scripts and making a retry or rollback depend on manual cleanup. Keep the pull after computing the new compose, but before any filesystem mutations.

Useful? React with 👍 / 👎.

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)
Expand Down
21 changes: 17 additions & 4 deletions agent/utils/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
if msg, ok := progress["errorDetail"]; ok {
return fmt.Errorf("image pull failed, err: %v", msg)
}
if msg, ok := progress["error"]; ok {
return fmt.Errorf("image pull failed, err: %v", msg)
}
if task == nil {
continue
}
status, _ := progress["status"].(string)
if status == "Downloading" || status == "Extracting" {
switch status {
case "Downloading", "Extracting":
logProcess(progress, task)
}
if status == "Pull complete" || status == "Download complete" {
case "Pull complete", "Download complete", "Already exists", "Verifying Checksum":
id, _ := progress["id"].(string)
progressStr := fmt.Sprintf("%s %s", status, id)
_ = setLog(id, progressStr, task)
Expand Down
Loading