From d8fd430856562fe85cb359b915a2d464985d4bf5 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:01:05 +0800 Subject: [PATCH] fix: Fix Issue with Podman Unable to Create PHP Runtime Website (#7253) --- backend/app/service/container.go | 19 +++++++++++++++++++ backend/app/service/website.go | 7 +------ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/backend/app/service/container.go b/backend/app/service/container.go index b7a3ab96b..b38da965d 100644 --- a/backend/app/service/container.go +++ b/backend/app/service/container.go @@ -983,6 +983,25 @@ func checkImageExist(client *client.Client, imageItem string) bool { return false } +func checkImageLike(imageName string) bool { + cli, err := docker.NewDockerClient() + if err != nil { + return false + } + images, err := cli.ImageList(context.Background(), image.ListOptions{}) + if err != nil { + return false + } + for _, img := range images { + for _, tag := range img.RepoTags { + if strings.Contains(tag, imageName) { + return true + } + } + } + return false +} + func pullImages(ctx context.Context, client *client.Client, imageName string) error { options := image.PullOptions{} repos, _ := imageRepoRepo.List() diff --git a/backend/app/service/website.go b/backend/app/service/website.go index 648914cb2..2ee218215 100644 --- a/backend/app/service/website.go +++ b/backend/app/service/website.go @@ -313,12 +313,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error) switch runtime.Type { case constant.RuntimePHP: if runtime.Resource == constant.ResourceAppstore { - client, err := docker.NewDockerClient() - if err != nil { - return err - } - defer client.Close() - if !checkImageExist(client, runtime.Image) { + if !checkImageLike(runtime.Image) { return buserr.WithName("ErrImageNotExist", runtime.Name) } var (