Skip to content

Commit

Permalink
cmd: support --config option
Browse files Browse the repository at this point in the history
Let's support --config option by setting environment variable
DOCKER_CONFIG instead of ignoring it for docker compatibility.

Also add a test case for this change, remove the deprecated one.

This is a rework to fix:
containers#14767

Signed-off-by: Ming Liu <liu.ming50@gmail.com>
  • Loading branch information
liuming50 committed Dec 28, 2023
1 parent 7dc7cbf commit 7989a62
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
8 changes: 5 additions & 3 deletions cmd/podman/root.go
Expand Up @@ -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: %w", dockerConfig, err)
os.Exit(1)
}
}
}

Expand Down Expand Up @@ -476,8 +479,7 @@ 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")
lFlags.StringVar(&dockerConfig, "config", "", "Location of config files")
// 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")
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/entities/engine.go
Expand Up @@ -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 config files
CgroupUsage string // rootless code determines Usage message
ConmonPath string // --conmon flag will set Engine.ConmonPath
CPUProfile string // Hidden: Should CPU profile be taken
Expand Down
3 changes: 0 additions & 3 deletions test/system/001-basic.bats
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions test/system/150-login.bats
Expand Up @@ -91,6 +91,37 @@ 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 option" {
dockerconfig=${PODMAN_LOGIN_WORKDIR}/docker
rm -rf $dockerconfig

registry=localhost:${PODMAN_LOGIN_REGISTRY_PORT}

run_podman login --config $dockerconfig \
--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 logout --config $dockerconfig $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" {

Expand Down

0 comments on commit 7989a62

Please sign in to comment.