Add environment variables to set inactivity timeout values
Fixes-###
What
When I use mint (slim) to optimize my docker image (original size is 13 GB), I always get this error
level=error msg="dockerutil.CopyFromContainer: dclient.DownloadFromContainer() error = inactivity time exceeded timeout"
And slim optimization failed finally with error
cmd=slim info=build.error status='optimized.image.build.error' error='no layers'
Why
The reason is the inactivity timeout is hardcoded to 20secs for export image and download from container
options := dockerapi.ExportImageOptions{
Name: imageRef,
OutputStream: dfile,
InactivityTimeout: 20 * time.Second,
}
downloadOptions := dockerapi.DownloadFromContainerOptions{
Path: remote,
OutputStream: dfile,
InactivityTimeout: 20 * time.Second,
InactivityTimeout: downloadTimeoutValue * time.Second,
}
For large docker image, we might need longer time to finish these operation.
In order to fix that, we add two environment variables SLIM_EXPORT_IMAGE_INACTIVITY_TIMEOUT and SLIM_DOWNLOAD_INACTIVITY_TIMEOUT to set the inactivity timeout values respectively.
How Tested
Now we can run mint slim with the customized timeout value like
SLIM_DOWNLOAD_INACTIVITY_TIMEOUT=180 mint slim ...
Thanks for the enhancement @tsujie ! Definitely makes sense to have an option like that. Normally it's done in a slightly different way using flags, which also have environment variables, so there's no need to manually extract environment variables. I can accept this PR as-is though I'll need to refactor it to use flags.
@kcq , yes, using flags is a better way. But I'm not quite familiar with the flags implementation and passing mechanism in slim. Maybe need your refactoring.