From 418863543c73759fed8674a09e6e214b71516525 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Tue, 12 Sep 2023 17:52:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=81=9C=E6=AD=A2=E4=B9=8B=E5=90=8E=E4=B8=8D=E8=83=BD=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98=20(#2267)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/app_install.go | 16 ++++++++-------- backend/utils/docker/docker.go | 12 ++++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/backend/app/service/app_install.go b/backend/app/service/app_install.go index 05f2f6fa5..fe956a970 100644 --- a/backend/app/service/app_install.go +++ b/backend/app/service/app_install.go @@ -151,7 +151,7 @@ func (a *AppInstallService) CheckExist(req request.AppInstalledInfo) (*response. if reflect.DeepEqual(appInstall, model.AppInstall{}) { return res, nil } - if err = syncById(appInstall.ID); err != nil { + if err = syncByID(appInstall.ID); err != nil { return nil, err } @@ -239,26 +239,26 @@ func (a *AppInstallService) Operate(req request.AppInstalledOperate) error { if err != nil { return handleErr(install, err, out) } - return syncById(install.ID) + return syncByID(install.ID) case constant.Stop: out, err := compose.Stop(dockerComposePath) if err != nil { return handleErr(install, err, out) } - return syncById(install.ID) + return syncByID(install.ID) case constant.Restart: out, err := compose.Restart(dockerComposePath) if err != nil { return handleErr(install, err, out) } - return syncById(install.ID) + return syncByID(install.ID) case constant.Delete: if err := deleteAppInstall(install, req.DeleteBackup, req.ForceDelete, req.DeleteDB); err != nil && !req.ForceDelete { return err } return nil case constant.Sync: - return syncById(install.ID) + return syncByID(install.ID) case constant.Upgrade: return upgradeInstall(install.ID, req.DetailId, req.Backup) default: @@ -417,7 +417,7 @@ func (a *AppInstallService) SyncAll(systemInit bool) error { continue } if !systemInit { - if err := syncById(i.ID); err != nil { + if err := syncByID(i.ID); err != nil { global.LOG.Errorf("sync install app[%s] error,mgs: %s", i.Name, err.Error()) } } @@ -675,8 +675,8 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) { return &res, nil } -func syncById(installId uint) error { - appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installId)) +func syncByID(installID uint) error { + appInstall, err := appInstallRepo.GetFirst(commonRepo.WithByID(installID)) if err != nil { return err } diff --git a/backend/utils/docker/docker.go b/backend/utils/docker/docker.go index 1d881a3da..a2dfad9b9 100644 --- a/backend/utils/docker/docker.go +++ b/backend/utils/docker/docker.go @@ -42,7 +42,10 @@ func (c Client) ListAllContainers() ([]types.Container, error) { } func (c Client) ListContainersByName(names []string) ([]types.Container, error) { - var options types.ContainerListOptions + var ( + options types.ContainerListOptions + res []types.Container + ) options.All = true if len(names) > 0 { var array []filters.KeyValuePair @@ -55,7 +58,12 @@ func (c Client) ListContainersByName(names []string) ([]types.Container, error) if err != nil { return nil, err } - return containers, nil + for _, container := range containers { + if container.Names[0] == "/"+names[0] { + res = append(res, container) + } + } + return res, nil } func (c Client) CreateNetwork(name string) error {