1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::;
/// Trait for images that can be built from within your tests or testcontainer libraries.
///
/// Unlike the [`Image`] trait which represents existing Docker images, `BuildableImage`
/// represents images that need to be constructed from a, possibly even dynamic, `Dockerfile``
/// and the needed Docker build context.
///
/// If you want to dynamically create Dockerfiles look at Dockerfile generator crates like:
/// <https://crates.io/crates/dockerfile_builder>
///
/// The build process, executed by [`crate::runners::SyncBuilder`] / [`crate::runners::AsyncBuilder`], follows these steps:
/// 1. Collect build context via `build_context()` which will be tarred and sent to buildkit.
/// 2. Generate image descriptor via `descriptor()` which will be passed to the container
/// 3. Build the Docker image using the Docker API
/// 4. Convert to runnable [`Image`] via `into_image()` which consumes the `BuildableImage`
/// into an `Image`
///
/// # Example
///
/// ```rust
/// use testcontainers::{GenericBuildableImage, runners::AsyncBuilder};
///
/// #[tokio::test]
/// async fn test_example() -> anyhow::Result<()> {
/// let image = GenericBuildableImage::new("example-tc", "1.0")
/// .with_dockerfile_string("FROM alpine:latest\nRUN echo 'hello'")
/// .build_image().await?;
/// // start container
/// // use it
/// }
/// ```
///