Skip to content

Commit

Permalink
Add support for TMP override on toml
Browse files Browse the repository at this point in the history
When running containerd as a service it may be hard to
override the TMP location of the process. This is especially
true on Windows when running containerd in SCM. This change
allows you to set the 'temp' location in the config.toml when
the service starts up that overrides its TEMP/TMP/TMPDIR usage.

This is helpful on Linux as well but it primarily solves the
performance issue on Windows when running containerd across
volumes. IE: If you configure your data/root paths on a volume
other than the SystemDrive the snapshotter does a temporary unpack
on the SystemDrive and then has to copy contents of that data
to the snapshot folder on the destination volume. By alinging the
tmp with the destination it is a simple move operation instead of
a copy operation.

Signed-off-by: Justin Terry <jlterry@amazon.com>
  • Loading branch information
jterry75 committed Nov 16, 2021
1 parent aa1b073 commit 63895de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions services/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type Config struct {
Root string `toml:"root"`
// State is the path to a directory where containerd will store transient data
State string `toml:"state"`
// TempDir is the path to a directory where to place containerd temporary files
TempDir string `toml:"temp"`
// PluginDir is the directory for dynamic plugins to be stored
PluginDir string `toml:"plugin_dir"`
// GRPC configuration settings
Expand Down
24 changes: 23 additions & 1 deletion services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net/http/pprof"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -75,7 +76,28 @@ func CreateTopLevelDirectories(config *srvconfig.Config) error {
return err
}

return sys.MkdirAllWithACL(config.State, 0711)
if err := sys.MkdirAllWithACL(config.State, 0711); err != nil {
return err
}

if config.TempDir != "" {
if err := sys.MkdirAllWithACL(config.TempDir, 0711); err != nil {
return err
}
if runtime.GOOS == "windows" {
// On Windows, the Host Compute Service (vmcompute) will read the
// TEMP/TMP setting from the calling process when creating the
// tempdir to extract an image layer to. This allows the
// administrator to align the tempdir location with the same volume
// as the snapshot dir to avoid a copy operation when moving the
// extracted layer to the snapshot dir location.
os.Setenv("TEMP", config.TempDir)
os.Setenv("TMP", config.TempDir)
} else {
os.Setenv("TMPDIR", config.TempDir)
}
}
return nil
}

// New creates and initializes a new containerd server
Expand Down

0 comments on commit 63895de

Please sign in to comment.