fix: Fix incomplete log printing for compose save errors (#11357)

This commit is contained in:
ssongliu 2025-12-16 16:41:58 +08:00 committed by GitHub
parent 682d78698f
commit d9579901fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 11 deletions

View file

@ -264,10 +264,11 @@ type ComposeInfo struct {
Env []string `json:"env"` Env []string `json:"env"`
} }
type ComposeContainer struct { type ComposeContainer struct {
ContainerID string `json:"containerID"` ContainerID string `json:"containerID"`
Name string `json:"name"` Name string `json:"name"`
CreateTime string `json:"createTime"` CreateTime string `json:"createTime"`
State string `json:"state"` State string `json:"state"`
Ports []string `json:"ports"`
} }
type ComposeCreate struct { type ComposeCreate struct {
TaskID string `json:"taskID"` TaskID string `json:"taskID"`

View file

@ -74,6 +74,7 @@ func (u *ContainerService) PageCompose(req dto.SearchWithPage) (int64, interface
Name: container.Names[0][1:], Name: container.Names[0][1:],
State: container.State, State: container.State,
CreateTime: time.Unix(container.Created, 0).Format(constant.DateTimeLayout), CreateTime: time.Unix(container.Created, 0).Format(constant.DateTimeLayout),
Ports: transPortToStr(container.Ports),
} }
if compose, has := composeMap[name]; has { if compose, has := composeMap[name]; has {
compose.ContainerCount++ compose.ContainerCount++
@ -180,7 +181,7 @@ func (u *ContainerService) TestCompose(req dto.ComposeCreate) (bool, error) {
cmd := getComposeCmd(req.Path, "config") cmd := getComposeCmd(req.Path, "config")
stdout, err := cmd.CombinedOutput() stdout, err := cmd.CombinedOutput()
if err != nil { if err != nil {
return false, errors.New(string(stdout)) return false, fmt.Errorf("docker-compose config failed, std: %s, err: %v", string(stdout), err)
} }
return true, nil return true, nil
} }
@ -242,14 +243,13 @@ func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error {
} }
if req.Operation == "up" { if req.Operation == "up" {
if stdout, err := compose.Up(req.Path); err != nil { if stdout, err := compose.Up(req.Path); err != nil {
return errors.New(string(stdout)) return fmt.Errorf("docker-compose up failed, std: %s, err: %v", stdout, err)
} }
} else { } else {
if stdout, err := compose.Operate(req.Path, req.Operation); err != nil { if stdout, err := compose.Operate(req.Path, req.Operation); err != nil {
return errors.New(string(stdout)) return fmt.Errorf("docker-compose %s failed, std: %s, err: %v", req.Operation, stdout, err)
} }
} }
global.LOG.Infof("docker-compose %s %s successful", req.Operation, req.Name)
return nil return nil
} }
@ -276,10 +276,11 @@ func (u *ContainerService) ComposeUpdate(req dto.ComposeUpdate) error {
} }
if stdout, err := compose.Up(req.Path); err != nil { if stdout, err := compose.Up(req.Path); err != nil {
global.LOG.Errorf("update failed when handle compose up, std: %s, err: %s, now try to recreate the old compose file", stdout, err)
if err := recreateCompose(string(oldFile), req.Path); err != nil { if err := recreateCompose(string(oldFile), req.Path); err != nil {
return fmt.Errorf("update failed when handle compose up, err: %s, recreate failed: %v", string(stdout), err) return fmt.Errorf("update failed and recreate old compose file also failed, err: %v", err)
} }
return fmt.Errorf("update failed when handle compose up, err: %s", string(stdout)) return fmt.Errorf("update failed when handle compose up, std: %v, err: %s", stdout, err)
} }
return nil return nil
@ -438,6 +439,5 @@ func newComposeEnv(pathItem string, env []string) error {
return err return err
} }
} }
global.LOG.Infof(".env file successfully created or updated with env variables in %s", envFilePath)
return nil return nil
} }