1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 08:19:15 +08:00

feat: PHP 镜像 build 增加超时时间 (#6744)

This commit is contained in:
zhengkunwang 2024-10-17 12:13:30 +08:00 committed by GitHub
parent 8749dc649a
commit b99061777a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2,6 +2,7 @@ package service
import ( import (
"bytes" "bytes"
"context"
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
@ -218,7 +219,10 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, rebuild bool) {
_ = logFile.Close() _ = 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) multiWriterStdout := io.MultiWriter(os.Stdout, logFile)
cmd.Stdout = multiWriterStdout cmd.Stdout = multiWriterStdout
var stderrBuf bytes.Buffer var stderrBuf bytes.Buffer
@ -228,7 +232,11 @@ func buildRuntime(runtime *model.Runtime, oldImageID string, rebuild bool) {
err = cmd.Run() err = cmd.Run()
if err != nil { if err != nil {
runtime.Status = constant.RuntimeError 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 { } else {
runtime.Status = constant.RuntimeNormal runtime.Status = constant.RuntimeNormal
runtime.Message = "" runtime.Message = ""