testcontainers-build 0.1.0

Build Testcontainers images from folders, remote contexts, and pluggable Git providers
Documentation
use crate::{BuildContext, BuildContextProvider, ContextLocation, Error, Result};
use async_trait::async_trait;
use std::path::PathBuf;

/// Use an existing folder as a build context.
/// Do not copy or delete the folder.
pub struct FolderSource {
    /// Set the caller-owned folder path.
    /// The folder must exist when the source is resolved.
    pub path: PathBuf,
}

impl FolderSource {
    /// Set the folder path.
    /// Validate the folder when the source is resolved.
    pub fn new(path: impl Into<PathBuf>) -> Self {
        Self { path: path.into() }
    }
}

#[async_trait]
impl BuildContextProvider for FolderSource {
    async fn resolve(&self) -> Result<BuildContext> {
        let path = dunce::canonicalize(&self.path)?;
        if !path.is_dir() {
            return Err(Error::InvalidInput(
                "folder source must be a directory".into(),
            ));
        }
        Ok(BuildContext::new(ContextLocation::Directory(path)))
    }
}