pub trait Buildpack {
    type Platform: Platform;
    type Metadata: DeserializeOwned;
    type Error: Debug;
    fn detect(
        &self,
        context: DetectContext<Self>
    ) -> Result<DetectResult, Self::Error>;
fn build(
        &self,
        context: BuildContext<Self>
    ) -> Result<BuildResult, Self::Error>; fn on_error(&self, error: Error<Self::Error>) -> i32 { ... } }
Expand description

Represents a buildpack written with the libcnb framework.

To implement a buildpack with this framework, start by implementing this trait. Besides the main build and detect methods, it also holds associated types for the buildpack: the Platform it is targeting, the type for its metadata and the custom error type.

Associated Types

The platform targeted by this buildpack. If no specific platform is targeted, consider using GenericPlatform as the type.

The metadata type for this buildpack. This is the data within [metadata] of the buildpacks buildpack.toml. The framework will attempt to parse the data and will only continue if parsing succeeded. If you wish to use raw, untyped, TOML data instead, use GenericMetadata.

The error type for buildpack specific errors, usually an enum. Examples of values inside the enum are: MavenExecutionFailed, InvalidGemfileLock, IncompatiblePythonVersion. The framework itself has its own error type that contains more low-level errors that can occur during buildpack execution.

Required methods

Detect logic for this buildpack. Directly corresponds to detect in the CNB buildpack interface.

Build logic for this buildpack. Directly corresponds to build in the CNB buildpack interface.

Provided methods

If an unhandled error occurred within the framework or the buildpack, this method will be called by the framework to allow custom, buildpack specific, code to run before exiting. Usually, this method is implemented by logging the error in a user friendly manner.

Implementations are not limited to just logging, for example, buildpacks might want to collect and send metrics about occurring errors to a central system.

The default implementation will simply print the error (using its Display implementation) to stderr.

Implementors