mirror of
https://github.com/containers/podman.git
synced 2025-06-10 17:48:29 +08:00
Change standard config path and add override config
The standard config has moved to /usr/share/containers/ per discussion. An override configuration file is allowed at the previous /etc/containers/ location. This override will be used in place of the normal config if both are present, and exists to override distro packaged configs without modifying the standard config. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #430 Approved by: rhatdan
This commit is contained in:
4
Makefile
4
Makefile
@ -10,9 +10,9 @@ PREFIX ?= ${DESTDIR}/usr/local
|
|||||||
BINDIR ?= ${PREFIX}/bin
|
BINDIR ?= ${PREFIX}/bin
|
||||||
LIBEXECDIR ?= ${PREFIX}/libexec
|
LIBEXECDIR ?= ${PREFIX}/libexec
|
||||||
MANDIR ?= ${PREFIX}/share/man
|
MANDIR ?= ${PREFIX}/share/man
|
||||||
|
SHAREDIR_CONTAINERS ?= ${PREFIX}/share/containers
|
||||||
ETCDIR ?= ${DESTDIR}/etc
|
ETCDIR ?= ${DESTDIR}/etc
|
||||||
ETCDIR_LIBPOD ?= ${ETCDIR}/crio
|
ETCDIR_LIBPOD ?= ${ETCDIR}/crio
|
||||||
ETCDIR_CONTAINERS ?= ${ETCDIR}/containers
|
|
||||||
BUILDTAGS ?= seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh) $(shell hack/btrfs_installed_tag.sh) $(shell hack/ostree_tag.sh) $(shell hack/selinux_tag.sh)
|
BUILDTAGS ?= seccomp $(shell hack/btrfs_tag.sh) $(shell hack/libdm_tag.sh) $(shell hack/btrfs_installed_tag.sh) $(shell hack/ostree_tag.sh) $(shell hack/selinux_tag.sh)
|
||||||
|
|
||||||
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
|
BASHINSTALLDIR=${PREFIX}/share/bash-completion/completions
|
||||||
@ -152,7 +152,7 @@ install.man: docs
|
|||||||
install ${SELINUXOPT} -m 644 $(filter %.1,$(MANPAGES)) -t $(MANDIR)/man1
|
install ${SELINUXOPT} -m 644 $(filter %.1,$(MANPAGES)) -t $(MANDIR)/man1
|
||||||
|
|
||||||
install.config:
|
install.config:
|
||||||
install ${SELINUXOPT} -D -m 644 libpod.conf ${ETCDIR_CONTAINERS}/libpod.conf
|
install ${SELINUXOPT} -D -m 644 libpod.conf ${SHAREDIR_CONTAINERS}/libpod.conf
|
||||||
install ${SELINUXOPT} -D -m 644 seccomp.json $(ETCDIR_LIBPOD)/seccomp.json
|
install ${SELINUXOPT} -D -m 644 seccomp.json $(ETCDIR_LIBPOD)/seccomp.json
|
||||||
install ${SELINUXOPT} -D -m 644 crio-umount.conf $(OCIUMOUNTINSTALLDIR)/crio-umount.conf
|
install ${SELINUXOPT} -D -m 644 crio-umount.conf $(OCIUMOUNTINSTALLDIR)/crio-umount.conf
|
||||||
|
|
||||||
|
@ -44,7 +44,11 @@ const (
|
|||||||
// If it is not present, the builtin default config is used instead
|
// If it is not present, the builtin default config is used instead
|
||||||
// This path can be overridden when the runtime is created by using
|
// This path can be overridden when the runtime is created by using
|
||||||
// NewRuntimeFromConfig() instead of NewRuntime()
|
// NewRuntimeFromConfig() instead of NewRuntime()
|
||||||
ConfigPath = "/etc/containers/libpod.conf"
|
ConfigPath = "/usr/share/containers/libpod.conf"
|
||||||
|
// OverrideConfigPath is the path to an override for the default libpod
|
||||||
|
// configuration file. If OverrideConfigPath exists, it will be used in
|
||||||
|
// place of the configuration file pointed to by ConfigPath.
|
||||||
|
OverrideConfigPath = "/etc/containers/libpod.conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A RuntimeOption is a functional option which alters the Runtime created by
|
// A RuntimeOption is a functional option which alters the Runtime created by
|
||||||
@ -163,20 +167,24 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) {
|
|||||||
// Copy the default configuration
|
// Copy the default configuration
|
||||||
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
|
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
|
||||||
|
|
||||||
// Now overwrite it with the given configuration file, if it exists
|
configPath := ConfigPath
|
||||||
// Do not fail on error, instead just use the builtin defaults
|
foundConfig := true
|
||||||
if _, err := os.Stat(ConfigPath); err == nil {
|
if _, err := os.Stat(OverrideConfigPath); err == nil {
|
||||||
// Read the contents of the config file
|
// Use the override configuration path
|
||||||
contents, err := ioutil.ReadFile(ConfigPath)
|
configPath = OverrideConfigPath
|
||||||
if err == nil {
|
} else if _, err := os.Stat(ConfigPath); err != nil {
|
||||||
// Only proceed if we successfully read the file
|
// Both stat checks failed, no config found
|
||||||
_, err := toml.Decode(string(contents), runtime.config)
|
foundConfig = false
|
||||||
if err != nil {
|
}
|
||||||
// We may have just ruined our RuntimeConfig
|
|
||||||
// Make a new one to be safe
|
// If we have a valid configuration file, load it in
|
||||||
runtime.config = new(RuntimeConfig)
|
if foundConfig {
|
||||||
deepcopier.Copy(defaultRuntimeConfig).To(runtime.config)
|
contents, err := ioutil.ReadFile(configPath)
|
||||||
}
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error reading configuration file %s", configPath)
|
||||||
|
}
|
||||||
|
if _, err := toml.Decode(string(contents), runtime.config); err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error decoding configuration file %s", configPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user