Skip to content

Commit

Permalink
Make DOCKER_CONFIG usage consistent with Docker CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimush committed Jun 12, 2024
1 parent 31ce952 commit 7105771
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 1 addition & 2 deletions docs/features/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

8 changes: 5 additions & 3 deletions testcontainers/src/core/env/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<E>() -> Option<String>
where
Expand All @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion testcontainers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7105771

Please sign in to comment.