Skip to content

Commit 90f6024

Browse files
tsujiejiexuim
andauthored
Add two environment variables SLIM_EXPORT_IMAGE_INACTIVITY_TIMEOUT and SLIM_DOWNLOAD_INACTIVITY_TIMEOUT to set the inactivity timeout values (#65)
Signed-off-by: Jie Xu <jie.xu@image-metrics.com> Co-authored-by: Jie Xu <jie.xu@image-metrics.com>
1 parent 98299a7 commit 90f6024

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pkg/crt/docker/dockerutil/dockerutil.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"strings"
1313
"time"
14+
"strconv"
1415

1516
"github.com/docker/docker/pkg/archive"
1617
dockerapi "github.com/fsouza/go-dockerclient"
@@ -32,6 +33,11 @@ const (
3233
emptyImageDockerfile = "FROM scratch\nCMD\n"
3334
)
3435

36+
const (
37+
EnvExportImageInactivityTimeout = "SLIM_EXPORT_IMAGE_INACTIVITY_TIMEOUT"
38+
EnvExportDownloadInactivityTimeout = "SLIM_DOWNLOAD_INACTIVITY_TIMEOUT"
39+
)
40+
3541
type BasicImageProps struct {
3642
ID string
3743
Size int64
@@ -360,10 +366,19 @@ func SaveImage(dclient *dockerapi.Client, imageRef, local string, extract, remov
360366
return err
361367
}
362368

369+
370+
// Default export image inactivity timeout value in seconds
371+
var exportTimeoutValue time.Duration = time.Duration(20)
372+
if value, exists := os.LookupEnv(EnvExportImageInactivityTimeout); exists {
373+
if timeout, err := strconv.Atoi(value); err == nil && timeout > 0 {
374+
exportTimeoutValue = time.Duration(timeout)
375+
}
376+
}
377+
363378
options := dockerapi.ExportImageOptions{
364379
Name: imageRef,
365380
OutputStream: dfile,
366-
InactivityTimeout: 20 * time.Second,
381+
InactivityTimeout: exportTimeoutValue * time.Second,
367382
}
368383

369384
err = dclient.ExportImage(options)
@@ -800,10 +815,18 @@ func CopyFromContainer(dclient *dockerapi.Client, containerID, remote, local str
800815
return err
801816
}
802817

818+
// Default download from container inactivity timeout value in seconds
819+
var downloadTimeoutValue time.Duration = time.Duration(20)
820+
if value, exists := os.LookupEnv(EnvExportDownloadInactivityTimeout); exists {
821+
if timeout, err := strconv.Atoi(value); err == nil && timeout > 0 {
822+
downloadTimeoutValue = time.Duration(timeout)
823+
}
824+
}
825+
803826
downloadOptions := dockerapi.DownloadFromContainerOptions{
804827
Path: remote,
805828
OutputStream: dfile,
806-
InactivityTimeout: 20 * time.Second,
829+
InactivityTimeout: downloadTimeoutValue * time.Second,
807830
}
808831

809832
err = dclient.DownloadFromContainer(containerID, downloadOptions)

0 commit comments

Comments
 (0)