testcontainers_build/
request.rs1use crate::{BuildContextProvider, BuildOptions, BuiltImage, ImageBuilder, Result};
2use std::time::Duration;
3
4#[must_use]
7pub struct ImageBuildRequest<S> {
8 builder: ImageBuilder,
9 source: S,
10 options: BuildOptions,
11}
12
13impl<S: BuildContextProvider> ImageBuildRequest<S> {
14 pub(crate) fn new(builder: ImageBuilder, source: S) -> Self {
15 Self {
16 builder,
17 source,
18 options: BuildOptions::default(),
19 }
20 }
21
22 pub fn with_options(mut self, options: BuildOptions) -> Self {
25 self.options = options;
26 self
27 }
28
29 pub fn with_dockerfile(mut self, path: impl Into<String>) -> Self {
32 self.options.dockerfile = path.into();
33 self
34 }
35
36 pub fn with_build_argument(
39 mut self,
40 name: impl Into<String>,
41 value: impl Into<String>,
42 ) -> Self {
43 self.options
44 .build_arguments
45 .insert(name.into(), value.into());
46 self
47 }
48
49 pub fn with_target(mut self, target: impl Into<String>) -> Self {
52 self.options.target = Some(target.into());
53 self
54 }
55
56 pub fn with_platform(mut self, platform: impl Into<String>) -> Self {
59 self.options.platform = Some(platform.into());
60 self
61 }
62
63 pub fn with_no_cache(mut self, no_cache: bool) -> Self {
66 self.options.no_cache = no_cache;
67 self
68 }
69
70 pub fn with_timeout(mut self, timeout: Duration) -> Self {
73 self.options.timeout = timeout;
74 self
75 }
76
77 pub async fn build(self) -> Result<BuiltImage> {
80 self.builder.build(&self.source, &self.options).await
81 }
82}