From b99061777a49aad4938c886eee4b3fa237f49264 Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Thu, 17 Oct 2024 12:13:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20PHP=20=E9=95=9C=E5=83=8F=20build=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=20(#6744?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/runtime_utils.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/app/service/runtime_utils.go b/backend/app/service/runtime_utils.go index afb1c8563..ecb43abbf 100644 --- a/backend/app/service/runtime_utils.go +++ b/backend/app/service/runtime_utils.go @@ -2,6 +2,7 @@ package service import ( "bytes" + "context" "fmt" "io" "net/http" @@ -218,7 +219,10 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, rebuild bool) { _ = logFile.Close() }() - cmd := exec.Command("docker-compose", "-f", composePath, "build") + ctx, cancel := context.WithTimeout(context.Background(), 1*time.Hour) + defer cancel() + + cmd := exec.CommandContext(ctx, "docker-compose", "-f", composePath, "build") multiWriterStdout := io.MultiWriter(os.Stdout, logFile) cmd.Stdout = multiWriterStdout var stderrBuf bytes.Buffer @@ -228,7 +232,11 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, rebuild bool) { err = cmd.Run() if err != nil { runtime.Status = constant.RuntimeError - runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + stderrBuf.String() + if errors.Is(ctx.Err(), context.DeadlineExceeded) { + runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + buserr.New("ErrCmdTimeout").Error() + } else { + runtime.Message = buserr.New(constant.ErrImageBuildErr).Error() + ":" + stderrBuf.String() + } } else { runtime.Status = constant.RuntimeNormal runtime.Message = ""