Skip to content

Commit d957990

Browse files
authored
fix: Fix incomplete log printing for compose save errors (#11357)
1 parent 682d786 commit d957990

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

agent/app/dto/container.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,11 @@ type ComposeInfo struct {
264264
Env []string `json:"env"`
265265
}
266266
type ComposeContainer struct {
267-
ContainerID string `json:"containerID"`
268-
Name string `json:"name"`
269-
CreateTime string `json:"createTime"`
270-
State string `json:"state"`
267+
ContainerID string `json:"containerID"`
268+
Name string `json:"name"`
269+
CreateTime string `json:"createTime"`
270+
State string `json:"state"`
271+
Ports []string `json:"ports"`
271272
}
272273
type ComposeCreate struct {
273274
TaskID string `json:"taskID"`

agent/app/service/container_compose.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (u *ContainerService) PageCompose(req dto.SearchWithPage) (int64, interface
7474
Name: container.Names[0][1:],
7575
State: container.State,
7676
CreateTime: time.Unix(container.Created, 0).Format(constant.DateTimeLayout),
77+
Ports: transPortToStr(container.Ports),
7778
}
7879
if compose, has := composeMap[name]; has {
7980
compose.ContainerCount++
@@ -180,7 +181,7 @@ func (u *ContainerService) TestCompose(req dto.ComposeCreate) (bool, error) {
180181
cmd := getComposeCmd(req.Path, "config")
181182
stdout, err := cmd.CombinedOutput()
182183
if err != nil {
183-
return false, errors.New(string(stdout))
184+
return false, fmt.Errorf("docker-compose config failed, std: %s, err: %v", string(stdout), err)
184185
}
185186
return true, nil
186187
}
@@ -242,14 +243,13 @@ func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error {
242243
}
243244
if req.Operation == "up" {
244245
if stdout, err := compose.Up(req.Path); err != nil {
245-
return errors.New(string(stdout))
246+
return fmt.Errorf("docker-compose up failed, std: %s, err: %v", stdout, err)
246247
}
247248
} else {
248249
if stdout, err := compose.Operate(req.Path, req.Operation); err != nil {
249-
return errors.New(string(stdout))
250+
return fmt.Errorf("docker-compose %s failed, std: %s, err: %v", req.Operation, stdout, err)
250251
}
251252
}
252-
global.LOG.Infof("docker-compose %s %s successful", req.Operation, req.Name)
253253
return nil
254254
}
255255

@@ -276,10 +276,11 @@ func (u *ContainerService) ComposeUpdate(req dto.ComposeUpdate) error {
276276
}
277277

278278
if stdout, err := compose.Up(req.Path); err != nil {
279+
global.LOG.Errorf("update failed when handle compose up, std: %s, err: %s, now try to recreate the old compose file", stdout, err)
279280
if err := recreateCompose(string(oldFile), req.Path); err != nil {
280-
return fmt.Errorf("update failed when handle compose up, err: %s, recreate failed: %v", string(stdout), err)
281+
return fmt.Errorf("update failed and recreate old compose file also failed, err: %v", err)
281282
}
282-
return fmt.Errorf("update failed when handle compose up, err: %s", string(stdout))
283+
return fmt.Errorf("update failed when handle compose up, std: %v, err: %s", stdout, err)
283284
}
284285

285286
return nil
@@ -438,6 +439,5 @@ func newComposeEnv(pathItem string, env []string) error {
438439
return err
439440
}
440441
}
441-
global.LOG.Infof(".env file successfully created or updated with env variables in %s", envFilePath)
442442
return nil
443443
}

0 commit comments

Comments
 (0)