Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: make DOCKER_CONFIG usage consistent with Docker CLI #654

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading