From 710577145a3668e0b1f387bd45f8f8f58a5f645e Mon Sep 17 00:00:00 2001 From: Roman Timushev Date: Wed, 12 Jun 2024 16:47:26 +0200 Subject: [PATCH] Make DOCKER_CONFIG usage consistent with Docker CLI --- docs/features/configuration.md | 3 +-- testcontainers/src/core/env/config.rs | 8 +++++--- testcontainers/src/lib.rs | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/features/configuration.md b/docs/features/configuration.md index 765f8b80..4eaa37bb 100644 --- a/docs/features/configuration.md +++ b/docs/features/configuration.md @@ -29,6 +29,5 @@ For that reason, Testcontainers for Rust gives you the ability to read the Docke Configuration is fetched in the following order: 1. `DOCKER_AUTH_CONFIG` environment variable, unmarshalling the string value from its JSON representation and using it as the Docker config. -2. `DOCKER_CONFIG` environment variable, as an alternative path to the Docker config file. +2. `DOCKER_CONFIG` environment variable, as an alternative path to the directory containing Docker `config.json` file. 3. else it will load the default Docker config file, which lives in the user's home, e.g. `~/.docker/config.json`. - diff --git a/testcontainers/src/core/env/config.rs b/testcontainers/src/core/env/config.rs index 2ac0314b..1c569e49 100644 --- a/testcontainers/src/core/env/config.rs +++ b/testcontainers/src/core/env/config.rs @@ -19,7 +19,8 @@ pub enum ConfigurationError { } /// The default path to the Docker configuration file. -const DEFAULT_DOCKER_CONFIG_PATH: &str = ".docker/config.json"; +const DEFAULT_DOCKER_CONFIG_PATH: &str = ".docker"; +const DOCKER_CONFIG_FILE: &str = "config.json"; #[cfg(feature = "properties-config")] const TESTCONTAINERS_PROPERTIES: &str = ".testcontainers.properties"; @@ -161,7 +162,7 @@ impl Config { /// Read the Docker authentication configuration in the following order: /// /// 1. `DOCKER_AUTH_CONFIG` environment variable, unmarshalling the string value from its JSON representation and using it as the Docker config. -/// 2. `DOCKER_CONFIG` environment variable, as an alternative path to the Docker config file. +/// 2. `DOCKER_CONFIG` environment variable, as an alternative path to the directory containing Docker `config.json` file. /// 3. else it will load the default Docker config file, which lives in the user's home, e.g. `~/.docker/config.json`. async fn read_docker_auth_config() -> Option where @@ -170,13 +171,14 @@ where match E::get_env_value("DOCKER_AUTH_CONFIG") { Some(cfg) => Some(cfg), None => { - let path_to_config = match E::get_env_value("DOCKER_CONFIG").map(PathBuf::from) { + let mut path_to_config = match E::get_env_value("DOCKER_CONFIG").map(PathBuf::from) { Some(path_to_config) => path_to_config, None => { let home_dir = dirs::home_dir()?; home_dir.join(DEFAULT_DOCKER_CONFIG_PATH) } }; + path_to_config.push(DOCKER_CONFIG_FILE); tokio::fs::read_to_string(path_to_config).await.ok() } } diff --git a/testcontainers/src/lib.rs b/testcontainers/src/lib.rs index cafe3de3..7fa64617 100644 --- a/testcontainers/src/lib.rs +++ b/testcontainers/src/lib.rs @@ -48,7 +48,7 @@ //! Configuration is fetched in the following order: //! //! 1. `DOCKER_AUTH_CONFIG` environment variable, unmarshalling the string value from its JSON representation and using it as the Docker config. -//! 2. `DOCKER_CONFIG` environment variable, as an alternative path to the Docker config file. +//! 2. `DOCKER_CONFIG` environment variable, as an alternative path to the directory containing Docker `config.json` file. //! 3. else it will load the default Docker config file, which lives in the user's home, e.g. `~/.docker/config.json`. //! //! # Ecosystem