1
0

feat: implement global docker timeout

This commit is contained in:
dump_stack() 2023-05-22 14:41:00 +00:00
parent 2fe3103603
commit fa5d0adb39
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
6 changed files with 13 additions and 17 deletions

View File

@ -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")

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

3
pew.go
View File

@ -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")