From 5e7429cd510b15de38e6dab673b6820a87952e5a Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 16 Aug 2023 23:34:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=AE=B9=E5=99=A8?= =?UTF-8?q?=E7=BC=96=E6=8E=92=E5=88=9B=E5=BB=BA=E6=97=A5=E5=BF=97=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=85=A2=E7=9A=84=E9=97=AE=E9=A2=98=20(#1973)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #1950 --- backend/app/service/container.go | 4 ++-- backend/app/service/container_compose.go | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index 1a3857c4f..085bd19dc 100644 --- a/backend/app/service/container.go +++ b/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 "" diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index 007575fb6..4e6b9bf9a 100644 --- a/backend/app/service/container_compose.go +++ b/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 {