Browse Source

fix: 解决容器编排创建日志加载慢的问题 (#1973)

Refs #1950
release-1.5
ssongliu 1 year ago committed by wanghe-fit2cloud
parent
commit
5e7429cd51
  1. 4
      backend/app/service/container.go
  2. 8
      backend/app/service/container_compose.go

4
backend/app/service/container.go

@ -631,9 +631,9 @@ func (u *ContainerService) ContainerStats(id string) (*dto.ContainerStats, error
func (u *ContainerService) LoadContainerLogs(req dto.OperationWithNameAndType) string {
filePath := ""
switch req.Type {
case "image-pull", "image-push", "image-build":
case "image-pull", "image-push", "image-build", "compose-create":
filePath = path.Join(global.CONF.System.TmpDir, fmt.Sprintf("docker_logs/%s", req.Name))
case "compose-detail", "compose-create":
case "compose-detail":
client, err := docker.NewDockerClient()
if err != nil {
return ""

8
backend/app/service/container_compose.go

@ -159,8 +159,10 @@ func (u *ContainerService) CreateCompose(req dto.ComposeCreate) (string, error)
if req.From == "path" {
req.Name = path.Base(path.Dir(req.Path))
}
logName := path.Dir(req.Path) + "/compose.log"
file, err := os.OpenFile(logName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
dockerLogDir := path.Join(global.CONF.System.TmpDir, "docker_logs")
logItem := fmt.Sprintf("%s/compose_create_%s_%s.log", dockerLogDir, req.Name, time.Now().Format("20060102150405"))
file, err := os.OpenFile(logItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
return "", err
}
@ -181,7 +183,7 @@ func (u *ContainerService) CreateCompose(req dto.ComposeCreate) (string, error)
_, _ = file.WriteString("docker-compose up successful!")
}()
return req.Name, nil
return path.Base(logItem), nil
}
func (u *ContainerService) ComposeOperation(req dto.ComposeOperation) error {

Loading…
Cancel
Save