2017-07-12 05:08:53 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package appdefaults
|
|
|
|
|
2018-05-30 02:49:43 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2017-07-12 05:08:53 +00:00
|
|
|
const (
|
2018-08-29 21:00:25 +00:00
|
|
|
Address = "unix:///run/buildkit/buildkitd.sock"
|
|
|
|
Root = "/var/lib/buildkit"
|
|
|
|
ConfigDir = "/etc/buildkit"
|
2017-07-12 05:08:53 +00:00
|
|
|
)
|
2018-05-30 02:49:43 +00:00
|
|
|
|
|
|
|
// UserAddress typically returns /run/user/$UID/buildkit/buildkitd.sock
|
|
|
|
func UserAddress() string {
|
|
|
|
// pam_systemd sets XDG_RUNTIME_DIR but not other dirs.
|
|
|
|
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
|
|
|
if xdgRuntimeDir != "" {
|
|
|
|
dirs := strings.Split(xdgRuntimeDir, ":")
|
|
|
|
return "unix://" + filepath.Join(dirs[0], "buildkit", "buildkitd.sock")
|
|
|
|
}
|
|
|
|
return Address
|
|
|
|
}
|
|
|
|
|
|
|
|
// EnsureUserAddressDir sets sticky bit on XDG_RUNTIME_DIR if XDG_RUNTIME_DIR is set.
|
|
|
|
// See https://github.com/opencontainers/runc/issues/1694
|
|
|
|
func EnsureUserAddressDir() error {
|
|
|
|
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
|
|
|
|
if xdgRuntimeDir != "" {
|
|
|
|
dirs := strings.Split(xdgRuntimeDir, ":")
|
|
|
|
dir := filepath.Join(dirs[0], "buildkit")
|
|
|
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return os.Chmod(dir, 0700|os.ModeSticky)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserRoot typically returns /home/$USER/.local/share/buildkit
|
|
|
|
func UserRoot() string {
|
|
|
|
// pam_systemd sets XDG_RUNTIME_DIR but not other dirs.
|
|
|
|
xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
|
|
|
if xdgDataHome != "" {
|
|
|
|
dirs := strings.Split(xdgDataHome, ":")
|
|
|
|
return filepath.Join(dirs[0], "buildkit")
|
|
|
|
}
|
|
|
|
home := os.Getenv("HOME")
|
|
|
|
if home != "" {
|
|
|
|
return filepath.Join(home, ".local", "share", "buildkit")
|
|
|
|
}
|
|
|
|
return Root
|
|
|
|
}
|
2018-08-29 21:00:25 +00:00
|
|
|
|
|
|
|
// UserConfigDir returns dir for storing config. /home/$USER/.config/buildkit/
|
|
|
|
func UserConfigDir() string {
|
|
|
|
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
|
|
|
|
if xdgConfigHome != "" {
|
|
|
|
return filepath.Join(xdgConfigHome, "buildkit")
|
|
|
|
}
|
|
|
|
home := os.Getenv("HOME")
|
|
|
|
if home != "" {
|
|
|
|
return filepath.Join(home, ".config", "buildkit")
|
|
|
|
}
|
|
|
|
return ConfigDir
|
|
|
|
}
|