mirror of
https://github.com/containers/podman.git
synced 2025-06-20 09:03:43 +08:00
Merge pull request #21095 from liuming50/support-config-option
cmd: support --config option
This commit is contained in:
@ -400,7 +400,10 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
func configHook() {
|
func configHook() {
|
||||||
if dockerConfig != "" {
|
if dockerConfig != "" {
|
||||||
logrus.Warn("The --config flag is ignored by Podman. Exists for Docker compatibility")
|
if err := os.Setenv("DOCKER_CONFIG", dockerConfig); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "cannot set DOCKER_CONFIG=%s: %s", dockerConfig, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,8 +479,10 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
|
|||||||
lFlags.StringVarP(&podmanConfig.URI, "host", "H", podmanConfig.URI, "Used for Docker compatibility")
|
lFlags.StringVarP(&podmanConfig.URI, "host", "H", podmanConfig.URI, "Used for Docker compatibility")
|
||||||
_ = lFlags.MarkHidden("host")
|
_ = lFlags.MarkHidden("host")
|
||||||
|
|
||||||
lFlags.StringVar(&dockerConfig, "config", "", "Ignored for Docker compatibility")
|
configFlagName := "config"
|
||||||
_ = lFlags.MarkHidden("config")
|
lFlags.StringVar(&dockerConfig, "config", "", "Location of authentication config file")
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc(configFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
// Context option added just for compatibility with DockerCLI.
|
// Context option added just for compatibility with DockerCLI.
|
||||||
lFlags.String("context", "default", "Name of the context to use to connect to the daemon (This flag is a NOOP and provided solely for scripting compatibility.)")
|
lFlags.String("context", "default", "Name of the context to use to connect to the daemon (This flag is a NOOP and provided solely for scripting compatibility.)")
|
||||||
_ = lFlags.MarkHidden("context")
|
_ = lFlags.MarkHidden("context")
|
||||||
|
@ -32,6 +32,9 @@ The CGroup manager to use for container cgroups. Supported values are __cgroupfs
|
|||||||
Note: Setting this flag can cause certain commands to break when called on containers previously created by the other CGroup manager type.
|
Note: Setting this flag can cause certain commands to break when called on containers previously created by the other CGroup manager type.
|
||||||
Note: CGroup manager is not supported in rootless mode when using CGroups Version V1.
|
Note: CGroup manager is not supported in rootless mode when using CGroups Version V1.
|
||||||
|
|
||||||
|
#### **--config**
|
||||||
|
Location of config file. Mainly for docker compatibility, only the authentication parts of the config are supported.
|
||||||
|
|
||||||
#### **--conmon**
|
#### **--conmon**
|
||||||
Path of the conmon binary (Default path is configured in `containers.conf`)
|
Path of the conmon binary (Default path is configured in `containers.conf`)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ type PodmanConfig struct {
|
|||||||
ContainersConf *config.Config
|
ContainersConf *config.Config
|
||||||
ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf.
|
ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf.
|
||||||
DBBackend string // Hidden: change the database backend
|
DBBackend string // Hidden: change the database backend
|
||||||
DockerConfig string // Used for Docker compatibility
|
DockerConfig string // Location of authentication config file
|
||||||
CgroupUsage string // rootless code determines Usage message
|
CgroupUsage string // rootless code determines Usage message
|
||||||
ConmonPath string // --conmon flag will set Engine.ConmonPath
|
ConmonPath string // --conmon flag will set Engine.ConmonPath
|
||||||
CPUProfile string // Hidden: Should CPU profile be taken
|
CPUProfile string // Hidden: Should CPU profile be taken
|
||||||
|
@ -35,9 +35,6 @@ function setup() {
|
|||||||
|
|
||||||
run_podman -v
|
run_podman -v
|
||||||
is "$output" "podman.*version \+" "'Version line' in output"
|
is "$output" "podman.*version \+" "'Version line' in output"
|
||||||
|
|
||||||
run_podman 0+w --config foobar version
|
|
||||||
require_warning "The --config flag is ignored by Podman. Exists for Docker compatibility"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# bats test_tags=distro-integration
|
# bats test_tags=distro-integration
|
||||||
|
@ -91,6 +91,38 @@ function setup() {
|
|||||||
assert "$output" =~ "Error: options for paths to the credential file and to the Docker-compatible credential file can not be set simultaneously"
|
assert "$output" =~ "Error: options for paths to the credential file and to the Docker-compatible credential file can not be set simultaneously"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "podman login - check with --config global option" {
|
||||||
|
dockerconfig=${PODMAN_LOGIN_WORKDIR}/docker
|
||||||
|
rm -rf $dockerconfig
|
||||||
|
|
||||||
|
registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT}
|
||||||
|
|
||||||
|
run_podman --config $dockerconfig login \
|
||||||
|
--tls-verify=false \
|
||||||
|
--username ${PODMAN_LOGIN_USER} \
|
||||||
|
--password ${PODMAN_LOGIN_PASS} \
|
||||||
|
$registry
|
||||||
|
|
||||||
|
# Confirm that config file now exists
|
||||||
|
test -e $dockerconfig/config.json || \
|
||||||
|
die "podman login did not create config $dockerconfig/config.json"
|
||||||
|
|
||||||
|
# Special bracket form needed because of colon in host:port
|
||||||
|
run jq -r ".[\"auths\"][\"$registry\"][\"auth\"]" <$dockerconfig/config.json
|
||||||
|
is "$status" "0" "jq from $dockerconfig/config.json"
|
||||||
|
|
||||||
|
expect_userpass="${PODMAN_LOGIN_USER}:${PODMAN_LOGIN_PASS}"
|
||||||
|
actual_userpass=$(base64 -d <<<"$output")
|
||||||
|
is "$actual_userpass" "$expect_userpass" "credentials stored in $dockerconfig/config.json"
|
||||||
|
|
||||||
|
# Now log out and make sure credentials are removed
|
||||||
|
run_podman --config $dockerconfig logout $registry
|
||||||
|
|
||||||
|
run jq -r '.auths' <$dockerconfig/config.json
|
||||||
|
is "$status" "0" "jq from $dockerconfig/config.json"
|
||||||
|
is "$output" "{}" "credentials removed from $dockerconfig/config.json"
|
||||||
|
}
|
||||||
|
|
||||||
# Some push tests
|
# Some push tests
|
||||||
@test "podman push fail" {
|
@test "podman push fail" {
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user