Skip to content

Commit b2bad08

Browse files
authored
Merge pull request cds-hooks#478 from mboldt/buildpack-0.7-0.8
Update docs for Buildpack API 0.7 -> 0.8
2 parents ea00ad5 + 7096f27 commit b2bad08

File tree

2 files changed

+72
-21
lines changed

2 files changed

+72
-21
lines changed

content/docs/reference/spec/buildpack-api.md

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ can be executables compiled from a language like Go.
2222
### Usage
2323

2424
```
25-
bin/detect PLATFORM_DIR BUILD_PLAN
25+
bin/detect
2626
```
2727

2828
### Summary
2929

3030
This entrypoint is used to determine if a buildpack should
3131
run against a given codebase. It will often check for the existence of a particular
3232
file or some configuration indicating what kind of application has been provided.
33-
It accepts two positional arguments:
33+
Two environment variables identify important file system paths:
3434

35-
* `PLATFORM_DIR` - a directory containing platform provided configuration, such as environment variables.
36-
* `BUILD_PLAN` - a path to a file containing the [Build Plan](#build-plan).
35+
* `CNB_PLATFORM_DIR` - a directory containing platform provided configuration, such as environment variables.
36+
* `CNB_BUILD_PLAN_PATH` - a path to a file containing the [Build Plan](#build-plan).
3737

3838
In addition, the working directory is defined as the location of the codebase
3939
the buildpack will execute against.
4040

41-
The executable must return an exit code of `0` if the codebase can be serviced by this buildpack.
41+
The executable must return an exit code of `0` if the codebase can be serviced by this buildpack, and `100` if it cannot.
42+
Other exit codes indicate an error during detection.
4243

4344
### Example
4445

@@ -52,7 +53,7 @@ if [ -f requirements.txt ]; then
5253
echo "Python Buildpack"
5354
exit 0
5455
else
55-
exit 1
56+
exit 100
5657
fi
5758
```
5859

@@ -61,35 +62,35 @@ fi
6162
### Usage
6263

6364
```
64-
bin/build LAYERS_DIR PLATFORM_DIR BUILD_PLAN
65+
bin/build
6566
```
6667

6768
This entrypoint transforms a codebase.
6869
It will often resolve dependencies, install binary packages, and compile code.
69-
It accepts three positional arguments:
70+
Three environment variables identify important file system paths:
7071

71-
* `LAYERS_DIR` - a directory that may contain subdirectories representing each layer created by the buildpack in the final image or build cache.
72-
* `PLATFORM_DIR` - a directory containing platform provided configuration, such as environment variables.
73-
* `BUILD_PLAN` - a path to a file containing the [Build Plan](#build-plan).
72+
* `CNB_LAYERS_DIR` - a directory that may contain subdirectories representing each layer created by the buildpack in the final image or build cache.
73+
* `CNB_PLATFORM_DIR` - a directory containing platform provided configuration, such as environment variables.
74+
* `CNB_BP_PLAN_PATH` - a path to a file containing the [Build Plan](#build-plan).
7475

7576
In addition, the working directory is defined as the location of the codebase
7677
this buildpack will execute against.
7778

7879
All changes to the codebase in the working directory will be included in the final
79-
image, along with any launch layers created in the `LAYERS_DIR`.
80+
image, along with any launch layers created in the `CNB_LAYERS_DIR`.
8081

8182
#### Layers
8283

83-
Each directory created by the buildpack under the `LAYERS_DIR` can be used for any
84+
Each directory created by the buildpack under the `CNB_LAYERS_DIR` can be used for any
8485
of the following purposes:
8586

8687
* Launch - the directory will be included in the run image as a single layer
8788
* Cache - the directory will be included in the cache
8889
* Build - the directory will be accessible by subsequent buildpacks
8990

9091
A buildpack defines how a layer will by used by creating a `<layer>.toml` with
91-
a name matching the directory it describes in the `LAYERS_DIR`. For example, a
92-
buildpack might create a `$LAYERS_DIR/python` directory and a `$LAYERS_DIR/python.toml`
92+
a name matching the directory it describes in the `CNB_LAYERS_DIR`. For example, a
93+
buildpack might create a `$CNB_LAYERS_DIR/python` directory and a `$CNB_LAYERS_DIR/python.toml`
9394
with the following contents:
9495

9596
```
@@ -109,9 +110,7 @@ to resolve dependencies:
109110
```
110111
#!/bin/sh
111112
112-
LAYERS_DIR="$1"
113-
114-
PIP_LAYER="$LAYERS_DIR/pip"
113+
PIP_LAYER="$CNB_LAYERS_DIR/pip"
115114
mkdir -p "$PIP_LAYER/modules" "$PIP_LAYER/env"
116115
117116
pip install -r requirements.txt -t "$PIP_LAYER/modules" \
@@ -129,7 +128,7 @@ A buildpack must contain a `buildpack.toml` file in its root directory.
129128
### Example
130129

131130
```
132-
api = "0.7"
131+
api = "0.8"
133132
134133
[buildpack]
135134
id = "example.com/python"
@@ -142,7 +141,7 @@ id = "io.buildpacks.stacks.bionic"
142141
### Schema
143142

144143
The schema is as follows:
145-
- **`api`** _(string, required, current: `0.7`)_\
144+
- **`api`** _(string, required, current: `0.8`)_\
146145
The Buildpack API version the buildpack adheres to. Used to ensure [compatibility](#api-compatibility) against
147146
the [lifecycle][lifecycle].
148147

@@ -268,7 +267,7 @@ The NPM buildpack could write the following to the build plan, if the buildpack
268267
name = "node"
269268
```
270269

271-
If, looking in the `package.json` file, the NPM buildpack see a specific version of `node` requested in the [engines](https://docs.npmjs.com/files/package.json#engines) field (e.g. `14.1`), it may write the following to the build plan:
270+
If, looking in the `package.json` file, the NPM buildpack sees a specific version of `node` requested in the [engines](https://docs.npmjs.com/files/package.json#engines) field (e.g. `14.1`), it may write the following to the build plan:
272271
```
273272
[[requires]]
274273
name = "node"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
+++
2+
title="Buildpack API 0.7 -> 0.8"
3+
+++
4+
5+
<!--more-->
6+
7+
This guide is most relevant to buildpack authors.
8+
9+
See the [spec release](https://github.com/buildpacks/spec/releases/tag/buildpack%2Fv0.8) for buildpack API 0.8 for the full list of changes and further details.
10+
11+
### Process-Specific Working Directory
12+
13+
Buildpacks may specify the working directory for a process by setting the `working-dir` field on the process in [`launch.toml`](https://github.com/buildpacks/spec/blob/buildpack/0.8/buildpack.md#launchtoml-toml).
14+
15+
Prior to this, all processes ran from the app directory (`CNB_APP_DIR`).
16+
Running a process from a different directory typically involved running a shell to execute a `cd` command and then start the process, like:
17+
18+
```
19+
[[processes]]
20+
command = "bash"
21+
args = ["-c", "cd <working-dir> && <start-process>"]
22+
```
23+
24+
Buildpacks can now specify the process directly with a specific working directory, like:
25+
26+
```
27+
[[processes]]
28+
command = "<start-process>"
29+
working-dir = "<working-dir>"
30+
```
31+
32+
For details, see [RFC 81](https://github.com/buildpacks/rfcs/blob/main/text/0081-process-specific-working-directory.md).
33+
34+
### Deprecate Positional Args to `build` and `detect` Executables
35+
36+
The positional arguments to the `detect` and `build` executables are deprecated.
37+
Lifecycle now accepts these values as environment variables.
38+
39+
To upgrade, buildpack authors should use the following environment variables:
40+
41+
For `detect`:
42+
43+
- `CNB_PLATFORM_DIR` replaces the first positional argument.
44+
- `CNB_BUILD_PLAN_PATH` replaces the second positional argument.
45+
46+
For `build`:
47+
48+
* `CNB_LAYERS_DIR` replaces the first positional argument.
49+
* `CNB_PLATFORM_DIR` replaces the second positional argument.
50+
* `CNB_BP_PLAN_PATH` replaces the third positional argument.
51+
52+
For details, see [RFC 100](https://github.com/buildpacks/rfcs/blob/main/text/0100-buildpack-input-vars.md).

0 commit comments

Comments
 (0)