|
1 | 1 | +++
|
2 | 2 | title="Create dependency layers"
|
3 |
| -weight=99 |
| 3 | +weight=3 |
4 | 4 | +++
|
5 | 5 |
|
6 |
| -Each directory created by the buildpack under the `CNB_LAYERS_DIR` can be used as a layer in the final image or build cache. |
| 6 | +Each directory created by the buildpack under the `CNB_LAYERS_DIR` can be used as a layer in the final app image or build cache. |
7 | 7 |
|
8 | 8 | <!--more-->
|
9 | 9 |
|
10 | 10 | That is, each directory can be used for any of the following purposes:
|
11 | 11 |
|
12 |
| -* Launch - the directory will be included in the run image as a single layer |
13 |
| -* Cache - the directory will be included in the cache and restored on future builds |
14 |
| -* Build - the directory will be accessible by subsequent buildpacks |
| 12 | +| Layer Type | | |
| 13 | +|------------|-------------------------------------------------------------------------------------------------------------| |
| 14 | +| `Launch` | the directory will be included in the **final app image** as a single layer | |
| 15 | +| `Cache` | the directory will be included in the **build cache** and restored to the `CNB_LAYERS_DIR` on future builds | |
| 16 | +| `Build` | the directory will be accessible to **buildpacks that follow** in the build (via the environment) | |
15 | 17 |
|
16 |
| -A buildpack defines how a layer will by used by creating a `<layer>.toml` |
17 |
| -with a name matching the directory it describes in the `CNB_LAYERS_DIR`. |
| 18 | +A buildpack can control how a layer will be used by creating a `<layer>.toml` with a name matching the directory it describes in the `CNB_LAYERS_DIR`. |
18 | 19 |
|
19 |
| -For example, a buildpack might create a `$CNB_LAYERS_DIR/python` directory |
20 |
| -and a `$CNB_LAYERS_DIR/python.toml` with the following contents: |
| 20 | +### Example |
| 21 | + |
| 22 | +A buildpack might create a `$CNB_LAYERS_DIR/python` directory and a `$CNB_LAYERS_DIR/python.toml` with the following contents: |
21 | 23 |
|
22 | 24 | ```
|
23 | 25 | launch = true
|
24 | 26 | cache = true
|
25 | 27 | build = true
|
26 | 28 | ```
|
27 | 29 |
|
28 |
| -In this example, the `python` directory will be included in the run image, |
29 |
| -cached for future builds, and will be accessible to subsequent buildpacks via the environment. |
| 30 | +In this example: |
| 31 | +* the final app image will contain a layer with `python`, as this is needed to run the app |
| 32 | +* the `$CNB_LAYERS_DIR/python` directory will be pre-created for future builds, avoiding the need to re-download this large dependency |
| 33 | +* buildpacks that follow in the build will be able to use `python` |
30 | 34 |
|
31 | 35 | ### Example
|
32 | 36 |
|
33 |
| -This is a simple example of a buildpack that runs Python's `pip` package manager |
34 |
| -to resolve dependencies: |
| 37 | +This is a simple `./bin/build` script for a buildpack that runs Python's `pip` package manager to resolve dependencies: |
35 | 38 |
|
36 | 39 | ```
|
37 | 40 | #!/bin/sh
|
|
0 commit comments