Merge pull request #21095 from liuming50/support-config-option

cmd: support --config option
This commit is contained in:
openshift-merge-bot[bot]
2024-01-10 11:04:45 +00:00
committed by GitHub
5 changed files with 44 additions and 7 deletions

View File

@ -400,7 +400,10 @@ func persistentPostRunE(cmd *cobra.Command, args []string) error {
func configHook() {
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.MarkHidden("host")
lFlags.StringVar(&dockerConfig, "config", "", "Ignored for Docker compatibility")
_ = lFlags.MarkHidden("config")
configFlagName := "config"
lFlags.StringVar(&dockerConfig, "config", "", "Location of authentication config file")
_ = cmd.RegisterFlagCompletionFunc(configFlagName, completion.AutocompleteDefault)
// 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.MarkHidden("context")

View File

@ -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: 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**
Path of the conmon binary (Default path is configured in `containers.conf`)

View File

@ -35,7 +35,7 @@ type PodmanConfig struct {
ContainersConf *config.Config
ContainersConfDefaultsRO *config.Config // The read-only! defaults from containers.conf.
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
ConmonPath string // --conmon flag will set Engine.ConmonPath
CPUProfile string // Hidden: Should CPU profile be taken

View File

@ -35,9 +35,6 @@ function setup() {
run_podman -v
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

View File

@ -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"
}
@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
@test "podman push fail" {