gopkg.in/docker/docker.v23@v23.0.11/pkg/plugins/discovery_unix.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package plugins // import "github.com/docker/docker/pkg/plugins"
     5  import (
     6  	"path/filepath"
     7  
     8  	"github.com/docker/docker/pkg/homedir"
     9  	"github.com/docker/docker/pkg/rootless"
    10  )
    11  
    12  const globalConfigPluginsPath = "/etc/docker/plugins"
    13  const globalLibPluginsPath = "/usr/lib/docker/plugins"
    14  
    15  var globalSpecsPaths = []string{globalConfigPluginsPath, globalLibPluginsPath}
    16  
    17  func rootlessConfigPluginsPath() string {
    18  	configHome, err := homedir.GetConfigHome()
    19  	if err == nil {
    20  		return filepath.Join(configHome, "docker/plugins")
    21  	}
    22  
    23  	return globalConfigPluginsPath
    24  }
    25  
    26  func rootlessLibPluginsPath() string {
    27  	libHome, err := homedir.GetLibHome()
    28  	if err == nil {
    29  		return filepath.Join(libHome, "docker/plugins")
    30  	}
    31  
    32  	return globalLibPluginsPath
    33  }
    34  
    35  // SpecsPaths returns
    36  // { "%programdata%\docker\plugins" } on Windows,
    37  // { "/etc/docker/plugins", "/usr/lib/docker/plugins" } on Unix in non-rootless mode,
    38  // { "$XDG_CONFIG_HOME/docker/plugins", "$HOME/.local/lib/docker/plugins" } on Unix in rootless mode
    39  // with fallback to the corresponding path in non-rootless mode if $XDG_CONFIG_HOME or $HOME is not set.
    40  func SpecsPaths() []string {
    41  	if rootless.RunningWithRootlessKit() {
    42  		return []string{rootlessConfigPluginsPath(), rootlessLibPluginsPath()}
    43  	}
    44  
    45  	return globalSpecsPaths
    46  }