registry: deprecate SetCertsDir

This function had to be called both in the daemon startup, as well as
the CLI startup. Which, in case of the cli, meant that the registry
package became a required dependency for all CLI-plugins.

Make the package itself aware of situations where it's running with
rootlessKit enabled. Altogether we should get rid of this package-level
variable, and instead store this in our configuration, and pass through
where it's used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-03-09 18:29:33 +01:00
parent a1c1340196
commit b633c4cc33
3 changed files with 37 additions and 23 deletions

View File

@@ -4,13 +4,9 @@ package main
import (
"net"
"path/filepath"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/homedir"
"github.com/docker/docker/pkg/rootless"
"github.com/docker/docker/registry"
"github.com/spf13/pflag"
)
@@ -59,14 +55,3 @@ func installConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
flags.BoolVar(&conf.Rootless, "rootless", conf.Rootless, "Enable rootless mode; typically used with RootlessKit")
flags.StringVar(&conf.CgroupNamespaceMode, "default-cgroupns-mode", conf.CgroupNamespaceMode, `Default mode for containers cgroup namespace ("host" | "private")`)
}
// configureCertsDir configures registry.CertsDir() depending on if the daemon
// is running in rootless mode or not.
func configureCertsDir() {
if rootless.RunningWithRootlessKit() {
configHome, err := homedir.GetConfigHome()
if err == nil {
registry.SetCertsDir(filepath.Join(configHome, "docker/certs.d"))
}
}
}

View File

@@ -79,7 +79,6 @@ func newDaemonCommand() (*cobra.Command, error) {
flags := cmd.Flags()
flags.BoolP("version", "v", false, "Print version information and quit")
flags.StringVar(&opts.configFile, "config-file", opts.configFile, "Daemon configuration file")
configureCertsDir()
opts.installFlags(flags)
installConfigFlags(opts.daemonConfig, flags)
installServiceFlags(flags)