summaryrefslogtreecommitdiff
path: root/cmd/podmanV2/registry
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podmanV2/registry')
-rw-r--r--cmd/podmanV2/registry/config.go67
-rw-r--r--cmd/podmanV2/registry/registry.go56
2 files changed, 72 insertions, 51 deletions
diff --git a/cmd/podmanV2/registry/config.go b/cmd/podmanV2/registry/config.go
index e68009a50..358f9172e 100644
--- a/cmd/podmanV2/registry/config.go
+++ b/cmd/podmanV2/registry/config.go
@@ -1,18 +1,21 @@
package registry
import (
+ "fmt"
"os"
+ "path/filepath"
"runtime"
"strings"
"github.com/containers/common/pkg/config"
- "github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/domain/entities"
- "github.com/sirupsen/logrus"
+ "github.com/containers/libpod/pkg/rootless"
+ "github.com/containers/libpod/pkg/util"
+ "github.com/pkg/errors"
)
const (
- RootRequired = "RootRequired"
+ ParentNSRequired = "ParentNSRequired"
)
var (
@@ -21,8 +24,8 @@ var (
// NewPodmanConfig creates a PodmanConfig from the environment
func NewPodmanConfig() entities.PodmanConfig {
- if err := libpod.SetXdgDirs(); err != nil {
- logrus.Errorf(err.Error())
+ if err := setXdgDirs(); err != nil {
+ fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
@@ -35,7 +38,7 @@ func NewPodmanConfig() entities.PodmanConfig {
case "linux":
mode = entities.ABIMode
default:
- logrus.Errorf("%s is not a supported OS", runtime.GOOS)
+ fmt.Fprintf(os.Stderr, "%s is not a supported OS", runtime.GOOS)
os.Exit(1)
}
@@ -43,17 +46,61 @@ func NewPodmanConfig() entities.PodmanConfig {
for _, v := range os.Args {
// Prefix checking works because of how default EngineMode's
// have been defined.
- if strings.HasPrefix(v, "--remote=") {
+ if strings.HasPrefix(v, "--remote") {
mode = entities.TunnelMode
}
}
- // FIXME: for rootless, where to get the path
- // TODO:
+ // FIXME: for rootless, add flag to get the path to override configuration
cfg, err := config.NewConfig("")
if err != nil {
- logrus.Error("Failed to obtain podman configuration")
+ fmt.Fprint(os.Stderr, "Failed to obtain podman configuration: "+err.Error())
os.Exit(1)
}
+
+ cfg.Network.NetworkConfigDir = cfg.Network.CNIPluginDirs[0]
+ if rootless.IsRootless() {
+ cfg.Network.NetworkConfigDir = ""
+ }
+
return entities.PodmanConfig{Config: cfg, EngineMode: mode}
}
+
+// SetXdgDirs ensures the XDG_RUNTIME_DIR env and XDG_CONFIG_HOME variables are set.
+// containers/image uses XDG_RUNTIME_DIR to locate the auth file, XDG_CONFIG_HOME is
+// use for the libpod.conf configuration file.
+func setXdgDirs() error {
+ if !rootless.IsRootless() {
+ return nil
+ }
+
+ // Setup XDG_RUNTIME_DIR
+ if _, found := os.LookupEnv("XDG_RUNTIME_DIR"); !found {
+ dir, err := util.GetRuntimeDir()
+ if err != nil {
+ return err
+ }
+ if err := os.Setenv("XDG_RUNTIME_DIR", dir); err != nil {
+ return errors.Wrapf(err, "cannot set XDG_RUNTIME_DIR="+dir)
+ }
+ }
+
+ if _, found := os.LookupEnv("DBUS_SESSION_BUS_ADDRESS"); !found {
+ sessionAddr := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "bus")
+ if _, err := os.Stat(sessionAddr); err == nil {
+ os.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path="+sessionAddr)
+ }
+ }
+
+ // Setup XDG_CONFIG_HOME
+ if _, found := os.LookupEnv("XDG_CONFIG_HOME"); !found {
+ cfgHomeDir, err := util.GetRootlessConfigHomeDir()
+ if err != nil {
+ return err
+ }
+ if err := os.Setenv("XDG_CONFIG_HOME", cfgHomeDir); err != nil {
+ return errors.Wrapf(err, "cannot set XDG_CONFIG_HOME="+cfgHomeDir)
+ }
+ }
+ return nil
+}
diff --git a/cmd/podmanV2/registry/registry.go b/cmd/podmanV2/registry/registry.go
index 5ef6a10d8..1c5e5d21b 100644
--- a/cmd/podmanV2/registry/registry.go
+++ b/cmd/podmanV2/registry/registry.go
@@ -42,41 +42,6 @@ func GetExitCode() int {
return exitCode
}
-// HelpTemplate returns the help template for podman commands
-// This uses the short and long options.
-// command should not use this.
-func HelpTemplate() string {
- return `{{.Short}}
-
-Description:
- {{.Long}}
-
-{{if or .Runnable .HasSubCommands}}{{.UsageString}}{{end}}`
-}
-
-// UsageTemplate returns the usage template for podman commands
-// This blocks the displaying of the global options. The main podman
-// command should not use this.
-func UsageTemplate() string {
- return `Usage(v2):{{if (and .Runnable (not .HasAvailableSubCommands))}}
- {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
- {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
-
-Aliases:
- {{.NameAndAliases}}{{end}}{{if .HasExample}}
-
-Examples:
- {{.Example}}{{end}}{{if .HasAvailableSubCommands}}
-
-Available Commands:{{range .Commands}}{{if (or .IsAvailableCommand (eq .Name "help"))}}
- {{rpad .Name .NamePadding }} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableLocalFlags}}
-
-Flags:
-{{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}}
-{{end}}
-`
-}
-
func ImageEngine() entities.ImageEngine {
return imageEngine
}
@@ -126,17 +91,26 @@ func IdOrLatestArgs(cmd *cobra.Command, args []string) error {
return nil
}
-func GetContext() context.Context {
+type PodmanOptionsKey struct{}
+
+func Context() context.Context {
if cliCtx == nil {
- cliCtx = context.Background()
+ cliCtx = ContextWithOptions(context.Background())
}
return cliCtx
}
-type ContextOptionsKey string
-
-const PodmanOptionsKey ContextOptionsKey = "PodmanOptions"
+func ContextWithOptions(ctx context.Context) context.Context {
+ cliCtx = context.WithValue(ctx, PodmanOptionsKey{}, PodmanOptions)
+ return cliCtx
+}
+// GetContextWithOptions deprecated, use NewContextWithOptions()
func GetContextWithOptions() context.Context {
- return context.WithValue(GetContext(), PodmanOptionsKey, PodmanOptions)
+ return ContextWithOptions(context.Background())
+}
+
+// GetContext deprecated, use Context()
+func GetContext() context.Context {
+ return Context()
}