From 927def4472b9ea57399dd8562d6c5a12866f61e0 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 17 Mar 2023 19:11:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=20compose=20=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E9=94=99=E8=AF=AF=E6=9C=AA=E5=AD=98=E5=BA=93=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/container_compose.go | 12 +++++++++--- backend/utils/compose/compose.go | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/backend/app/service/container_compose.go b/backend/app/service/container_compose.go index d0a384385..6371aa726 100644 --- a/backend/app/service/container_compose.go +++ b/backend/app/service/container_compose.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "path" "sort" "strings" "time" @@ -152,11 +153,16 @@ func (u *ContainerService) CreateCompose(req dto.ComposeCreate) error { req.Path = path } global.LOG.Infof("docker-compose.yml %s create successful, start to docker-compose up", req.Name) - if stdout, err := compose.Up(req.Path); err != nil { - return errors.New(string(stdout)) - } + if req.From == "path" { + req.Name = path.Base(strings.ReplaceAll(req.Path, "/docker-compose.yml", "")) + } + if stdout, err := compose.Up(req.Path); err != nil { + _, _ = compose.Down(req.Path) + return errors.New(stdout) + } _ = composeRepo.CreateRecord(&model.Compose{Name: req.Name}) + return nil } diff --git a/backend/utils/compose/compose.go b/backend/utils/compose/compose.go index b990275f0..44a2c3520 100644 --- a/backend/utils/compose/compose.go +++ b/backend/utils/compose/compose.go @@ -7,7 +7,7 @@ import ( ) func Up(filePath string) (string, error) { - stdout, err := cmd.Execf("docker-compose -f %s up -d", filePath) + stdout, err := cmd.Execf("docker-compose -f %s up -d --quiet-pull", filePath) return stdout, err }