use crate::{BuildContextProvider, BuildOptions, BuiltImage, ImageBuilder, Result};
use std::time::Duration;
#[must_use]
pub struct ImageBuildRequest<S> {
builder: ImageBuilder,
source: S,
options: BuildOptions,
}
impl<S: BuildContextProvider> ImageBuildRequest<S> {
pub(crate) fn new(builder: ImageBuilder, source: S) -> Self {
Self {
builder,
source,
options: BuildOptions::default(),
}
}
pub fn with_options(mut self, options: BuildOptions) -> Self {
self.options = options;
self
}
pub fn with_dockerfile(mut self, path: impl Into<String>) -> Self {
self.options.dockerfile = path.into();
self
}
pub fn with_build_argument(
mut self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self {
self.options
.build_arguments
.insert(name.into(), value.into());
self
}
pub fn with_target(mut self, target: impl Into<String>) -> Self {
self.options.target = Some(target.into());
self
}
pub fn with_platform(mut self, platform: impl Into<String>) -> Self {
self.options.platform = Some(platform.into());
self
}
pub fn with_no_cache(mut self, no_cache: bool) -> Self {
self.options.no_cache = no_cache;
self
}
pub fn with_timeout(mut self, timeout: Duration) -> Self {
self.options.timeout = timeout;
self
}
pub async fn build(self) -> Result<BuiltImage> {
self.builder.build(&self.source, &self.options).await
}
}