testcontainers-build 0.1.0

Build Testcontainers images from folders, remote contexts, and pluggable Git providers
Documentation
use crate::{BuildContext, BuildContextProvider, GitCliProvider, GitProvider, GitRequest, Result};
use async_trait::async_trait;

/// Resolve a Git request with a Git provider.
/// Keep the provider separate from image build execution.
pub struct GitSource {
    /// Set the source revision and location.
    /// The provider receives this request.
    pub request: GitRequest,
    /// Set the Git provider.
    /// It owns checkout behavior.
    pub provider: Box<dyn GitProvider>,
}

impl GitSource {
    /// Create a source with the Git CLI provider.
    /// Use the request to select the revision.
    pub fn new(request: GitRequest) -> Self {
        Self {
            request,
            provider: Box::new(GitCliProvider::default()),
        }
    }

    /// Create a source with a custom Git provider.
    /// Use the request to select the revision.
    pub fn with_provider(request: GitRequest, provider: impl GitProvider + 'static) -> Self {
        Self {
            request,
            provider: Box::new(provider),
        }
    }
}

#[async_trait]
impl BuildContextProvider for GitSource {
    async fn resolve(&self) -> Result<BuildContext> {
        self.provider.checkout(&self.request).await
    }
}