Skip to content

Commit

Permalink
Add two environment variables SLIM_EXPORT_IMAGE_INACTIVITY_TIMEOUT
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
tsujie and jiexuim authored Oct 13, 2024
1 parent 98299a7 commit 90f6024
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions pkg/crt/docker/dockerutil/dockerutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"path/filepath"
"strings"
"time"
"strconv"

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

const (
EnvExportImageInactivityTimeout = "SLIM_EXPORT_IMAGE_INACTIVITY_TIMEOUT"
EnvExportDownloadInactivityTimeout = "SLIM_DOWNLOAD_INACTIVITY_TIMEOUT"
)

type BasicImageProps struct {
ID string
Size int64
Expand Down Expand Up @@ -360,10 +366,19 @@ func SaveImage(dclient *dockerapi.Client, imageRef, local string, extract, remov
return err
}


// Default export image inactivity timeout value in seconds
var exportTimeoutValue time.Duration = time.Duration(20)
if value, exists := os.LookupEnv(EnvExportImageInactivityTimeout); exists {
if timeout, err := strconv.Atoi(value); err == nil && timeout > 0 {
exportTimeoutValue = time.Duration(timeout)
}
}

options := dockerapi.ExportImageOptions{
Name: imageRef,
OutputStream: dfile,
InactivityTimeout: 20 * time.Second,
InactivityTimeout: exportTimeoutValue * time.Second,
}

err = dclient.ExportImage(options)
Expand Down Expand Up @@ -800,10 +815,18 @@ func CopyFromContainer(dclient *dockerapi.Client, containerID, remote, local str
return err
}

// Default download from container inactivity timeout value in seconds
var downloadTimeoutValue time.Duration = time.Duration(20)
if value, exists := os.LookupEnv(EnvExportDownloadInactivityTimeout); exists {
if timeout, err := strconv.Atoi(value); err == nil && timeout > 0 {
downloadTimeoutValue = time.Duration(timeout)
}
}

downloadOptions := dockerapi.DownloadFromContainerOptions{
Path: remote,
OutputStream: dfile,
InactivityTimeout: 20 * time.Second,
InactivityTimeout: downloadTimeoutValue * time.Second,
}

err = dclient.DownloadFromContainer(containerID, downloadOptions)
Expand Down

0 comments on commit 90f6024

Please sign in to comment.