Skip to content

Commit 2e01041

Browse files
committed
Pass the platform config when pulling a image
1 parent cb014a0 commit 2e01041

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

testcontainers/src/core/client.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,19 @@ impl Client {
445445
Ok(())
446446
}
447447

448-
pub(crate) async fn pull_image(&self, descriptor: &str) -> Result<(), ClientError> {
448+
pub(crate) async fn pull_image(
449+
&self,
450+
descriptor: &str,
451+
platform: Option<String>,
452+
) -> Result<(), ClientError> {
449453
let pull_options = CreateImageOptionsBuilder::new()
450454
.from_image(descriptor)
451-
.platform(self.config.platform().unwrap_or_default())
455+
.platform(
456+
platform
457+
.as_ref()
458+
.map(|s| s.as_str())
459+
.unwrap_or_else(|| self.config.platform().unwrap_or_default()),
460+
)
452461
.build();
453462

454463
let credentials = self.credentials_for_image(descriptor).await;
@@ -462,7 +471,7 @@ impl Client {
462471
Err(BollardError::DockerResponseServerError {
463472
status_code: _,
464473
message: _,
465-
}) => {
474+
}) if !matches!(platform.as_ref().map(|s| s.as_str()), Some("linux/amd64")) => {
466475
self.pull_image_linux_amd64(descriptor).await?;
467476
}
468477
_ => {
@@ -708,7 +717,7 @@ mod tests {
708717
let config = env::Config::load::<OsEnvWithPlatformLinuxAmd64>().await?;
709718
let mut client = Client::new().await?;
710719
client.config = config;
711-
client.pull_image("hello-world:latest").await?;
720+
client.pull_image("hello-world:latest", None).await?;
712721

713722
let image = client.bollard.inspect_image("hello-world:latest").await?;
714723

@@ -718,7 +727,7 @@ mod tests {
718727
let config = env::Config::load::<OsEnvWithPlatformLinux386>().await?;
719728
let mut client = Client::new().await?;
720729
client.config = config;
721-
client.pull_image("hello-world:latest").await?;
730+
client.pull_image("hello-world:latest", None).await?;
722731

723732
let image = client.bollard.inspect_image("hello-world:latest").await?;
724733

testcontainers/src/core/image/image_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub trait ImageExt<I: Image> {
7070

7171
/// Sets the platform the container will be run on.
7272
///
73-
/// Platform in the format os[/arch[/variant]] used for image lookup.
73+
/// Platform in the format `os[/arch[/variant]]` used for image lookup.
7474
///
7575
/// # Examples
7676
///

testcontainers/src/runners/async_runner.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,12 @@ where
315315
status_code: 404, ..
316316
},
317317
)) => {
318-
client.pull_image(&container_req.descriptor()).await?;
318+
client
319+
.pull_image(
320+
&container_req.descriptor(),
321+
container_req.platform().clone(),
322+
)
323+
.await?;
319324
client.create_container(create_options, config).await
320325
}
321326
res => res,
@@ -358,7 +363,12 @@ where
358363
async fn pull_image(self) -> Result<ContainerRequest<I>> {
359364
let container_req = self.into();
360365
let client = Client::lazy_client().await?;
361-
client.pull_image(&container_req.descriptor()).await?;
366+
client
367+
.pull_image(
368+
&container_req.descriptor(),
369+
container_req.platform().clone(),
370+
)
371+
.await?;
362372

363373
Ok(container_req)
364374
}

0 commit comments

Comments
 (0)