From fa5d0adb3969ab52ab460f9b450c14ba57b0cfde Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Mon, 22 May 2023 14:41:00 +0000 Subject: [PATCH] feat: implement global docker timeout --- container/container.go | 12 +++++------- distro/centos/centos.go | 3 +-- distro/oraclelinux/oraclelinux.go | 3 +-- distro/ubuntu/ubuntu.go | 3 +-- kernel/kernel.go | 6 +++--- pew.go | 3 ++- 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/container/container.go b/container/container.go index 35cc8df..1d981c8 100644 --- a/container/container.go +++ b/container/container.go @@ -25,6 +25,8 @@ import ( var Runtime = "docker" +var Timeout = time.Hour + type Image struct { Name string Distro distro.Distro @@ -78,8 +80,6 @@ type Volume struct { type Container struct { name string - timeout time.Duration - Volumes []Volume // Additional arguments @@ -88,13 +88,12 @@ type Container struct { Log zerolog.Logger } -func New(name string, timeout time.Duration) (c Container, err error) { +func New(name string) (c Container, err error) { c.Log = log.With(). Str("container", name). Logger() c.name = name - c.timeout = timeout c.Volumes = append(c.Volumes, Volume{ Src: config.Dir("volumes", name, "lib", "modules"), @@ -114,11 +113,10 @@ func New(name string, timeout time.Duration) (c Container, err error) { return } -func NewFromKernelInfo(ki config.KernelInfo, timeout time.Duration) ( +func NewFromKernelInfo(ki config.KernelInfo) ( c Container, err error) { c.name = ki.ContainerName - c.timeout = timeout c.Log = log.With(). Str("container", c.name). @@ -211,7 +209,7 @@ func (c Container) Run(workdir string, command string) (output string, err error } cmd.Stderr = cmd.Stdout - timer := time.AfterFunc(c.timeout, func() { + timer := time.AfterFunc(Timeout, func() { flog.Info().Msg("killing container by timeout") flog.Debug().Msg("SIGINT") diff --git a/distro/centos/centos.go b/distro/centos/centos.go index 851192d..a98f556 100644 --- a/distro/centos/centos.go +++ b/distro/centos/centos.go @@ -3,7 +3,6 @@ package centos import ( "fmt" "strings" - "time" "github.com/rs/zerolog/log" @@ -43,7 +42,7 @@ func (centos CentOS) Equal(d distro.Distro) bool { } func (centos CentOS) Packages() (pkgs []string, err error) { - c, err := container.New(centos.container, time.Hour) + c, err := container.New(centos.container) if err != nil { return } diff --git a/distro/oraclelinux/oraclelinux.go b/distro/oraclelinux/oraclelinux.go index 25588b9..6e8e38c 100644 --- a/distro/oraclelinux/oraclelinux.go +++ b/distro/oraclelinux/oraclelinux.go @@ -3,7 +3,6 @@ package oraclelinux import ( "fmt" "strings" - "time" "github.com/rs/zerolog/log" @@ -43,7 +42,7 @@ func (ol OracleLinux) Equal(d distro.Distro) bool { } func (ol OracleLinux) Packages() (pkgs []string, err error) { - c, err := container.New(ol.container, time.Hour) + c, err := container.New(ol.container) if err != nil { return } diff --git a/distro/ubuntu/ubuntu.go b/distro/ubuntu/ubuntu.go index 9f55789..9eb62ca 100644 --- a/distro/ubuntu/ubuntu.go +++ b/distro/ubuntu/ubuntu.go @@ -3,7 +3,6 @@ package ubuntu import ( "fmt" "strings" - "time" "code.dumpstack.io/tools/out-of-tree/config" "code.dumpstack.io/tools/out-of-tree/container" @@ -49,7 +48,7 @@ func (u Ubuntu) Equal(d distro.Distro) bool { } func (u Ubuntu) Packages() (pkgs []string, err error) { - c, err := container.New(u.container, time.Hour) + c, err := container.New(u.container) if err != nil { return } diff --git a/kernel/kernel.go b/kernel/kernel.go index 2e742a1..78a5f00 100644 --- a/kernel/kernel.go +++ b/kernel/kernel.go @@ -163,7 +163,7 @@ func GenerateBaseDockerImage(registry string, commands []config.DockerCommand, return } - c, err := container.New(sk.DockerName(), time.Hour) + c, err := container.New(sk.DockerName()) if err != nil { return } @@ -189,7 +189,7 @@ func installKernel(sk config.Target, pkgname string, force, headers bool) (err e Str("pkg", pkgname). Logger() - c, err := container.New(sk.DockerName(), time.Hour) // TODO conf + c, err := container.New(sk.DockerName()) // TODO conf if err != nil { return } @@ -407,7 +407,7 @@ func listContainersKernels(dii container.Image, newkcfg *config.KernelConfig, return } - c, err := container.New(dii.Name, time.Hour) + c, err := container.New(dii.Name) if err != nil { return } diff --git a/pew.go b/pew.go index 26a9430..506084e 100644 --- a/pew.go +++ b/pew.go @@ -289,7 +289,8 @@ func build(flog zerolog.Logger, tmp string, ka config.Artifact, if ki.ContainerName != "" { var c container.Container - c, err = container.NewFromKernelInfo(ki, dockerTimeout) + container.Timeout = dockerTimeout + c, err = container.NewFromKernelInfo(ki) c.Log = flog if err != nil { log.Fatal().Err(err).Msg("container creation failure")