Skip to content

Commit c58d66f

Browse files
authored
Merge pull request #415 from buildpacks/jjbustamante/0134-execution-env-buildpack
[Buildpack API] - Add Execution Enviroment definition
2 parents 732fc7b + c7071cd commit c58d66f

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

buildpack.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ Any combination of the three layer types are valid for a particular layer direct
138138
The following specifies the interface implemented by component buildpacks.
139139
The lifecycle MUST invoke executables in component buildpacks as described in the Phase sections.
140140

141+
### Execution Environments
142+
143+
Execution environments define the context in which a buildpack-created application is intended to run. Standard values include:
144+
- `production`: The default environment, optimized for running applications in production.
145+
- `test`: Environment optimized for testing applications.
146+
- `development`: Environment optimized for development workflows.
147+
148+
Buildpacks SHOULD adapt their behavior based on the `CNB_EXEC_ENV` environment variable during detection and build phases. This may include:
149+
- Installing different dependencies
150+
- Configuring different build options
151+
- Creating different launch processes
152+
- Providing environment-specific layers
153+
154+
Buildpacks MAY optimize their output based on the execution environment:
155+
- A buildpack MAY mark processes as applicable only to specific execution environments
156+
- A buildpack MAY create layers that are specific to certain execution environments
157+
- A buildpack MAY use different build strategies depending on the execution environment
158+
159+
When the `CNB_EXEC_ENV` environment variable is not set, buildpacks MUST assume the default value of `production`.
160+
161+
The value of `CNB_EXEC_ENV` MUST NOT contain the character `/` as it is reserved for future use.
162+
163+
When a platform builds an application with a different execution environment than was used in a previous build, the platform SHOULD NOT restore layers from the previous build's image. The lifecycle MAY ignore layer metadata from previous builds with different execution environments to ensure proper environment-specific behaviors are maintained.
164+
141165
### Buildpack API Compatibility
142166
Given a buildpack declaring `<buildpack API Version>` in its [`buildpack.toml`](#buildpacktoml-toml), the lifecycle:
143167
- MUST either conform to the matching version of this specification when interfacing with the buildpack or
@@ -166,6 +190,7 @@ Executable: `/bin/detect`, Working Dir: `<app[AR]>`
166190
| `$0` | | Absolute path of `/bin/detect` executable |
167191
| `$CNB_BUILD_PLAN_PATH` | E | Absolute path of the build plan |
168192
| `$CNB_BUILDPACK_DIR` | ER | Absolute path of the buildpack root directory |
193+
| `$CNB_EXEC_ENV` | AR | Target execution environment ("production", "test", "development") |
169194
| `$CNB_PLATFORM_DIR` | AR | Absolute path of the platform directory |
170195
| `$CNB_PLATFORM_DIR/env/` | AR | User-provided environment variables for build |
171196
| `$CNB_PLATFORM_DIR/#` | AR | Platform-specific extensions |
@@ -187,6 +212,7 @@ Executable: `/bin/build`, Working Dir: `<app[AI]>`
187212
| `$CNB_LAYERS_DIR` | EIC | Absolute path of the buildpack layers directory |
188213
| `$CNB_BP_PLAN_PATH` | ER | Relevant [Buildpack Plan entries](#buildpack-plan-toml) from detection (TOML) |
189214
| `$CNB_BUILDPACK_DIR` | ER | Absolute path of the buildpack root directory |
215+
| `$CNB_EXEC_ENV` | AR | Target execution environment ("production", "test", "development") |
190216
| `$CNB_PLATFORM_DIR` | AR | Absolute path of the platform directory |
191217
| `$CNB_PLATFORM_DIR/env/` | AR | User-provided environment variables for build |
192218
| `$CNB_PLATFORM_DIR/#` | AR | Platform-specific extensions |
@@ -907,6 +933,7 @@ command = ["<command>"]
907933
args = ["<arguments>"]
908934
default = false
909935
working-dir = "<working directory>"
936+
exec-env = ["<execution environment>"] # Optional. If not specified, applies to all execution environments
910937

911938
[[slices]]
912939
paths = ["<app sub-path glob>"]
@@ -935,6 +962,7 @@ For each process, the buildpack:
935962
- The `args` list is a default list of arguments that may be overridden by the user [^command-args].
936963
- MAY specify a `default` boolean that indicates that the process type should be selected as the [buildpack-provided default](https://github.com/buildpacks/spec/blob/main/platform.md#outputs-4) during the export phase.
937964
- MAY specify a `working-dir` for the process. The `working-dir` defaults to the application directory if not specified.
965+
- MAY specify an `exec-env` array to restrict the process to specific execution environments. If `exec-env` is not specified, the process applies to all execution environments.
938966

939967
[^command-args]: For versions of the Platform API that do not support overridable arguments, the arguments in `command` and `args` are always applied together with any user-provided arguments.
940968
In general, the [Platform Interface Specification](platform.md) is ultimately responsible for launching processes; consult that specification for details.
@@ -1021,13 +1049,15 @@ name = "<dependency name>"
10211049
cache = false
10221050

10231051
[metadata]
1024-
# buildpack-specific data
1052+
exec-env = ["<execution environment>"] # Optional. If not specified, applies to all execution environments
1053+
# other buildpack-specific data
10251054
```
10261055

10271056
For a given layer, the buildpack MAY specify:
10281057

10291058
- Whether the layer is cached, intended for build, and/or intended for launch.
10301059
- Metadata that describes the layer contents.
1060+
- An `exec-env` array in the `[metadata]` section to restrict the layer to specific execution environments. If `exec-env` is not specified, the layer applies to all execution environments.
10311061

10321062
### buildpack.toml (TOML)
10331063
This section describes the 'Buildpack descriptor'.
@@ -1049,11 +1079,15 @@ sbom-formats = [ "<string>" ]
10491079
type = "<string>"
10501080
uri = "<uri>"
10511081

1082+
[[buildpack.exec-env]]
1083+
name = "<execution environment>"
1084+
10521085
[[order]]
10531086
[[order.group]]
10541087
id = "<buildpack ID>"
10551088
version = "<buildpack version>"
10561089
optional = false
1090+
exec-env = ["<execution environment>"]
10571091

10581092
[[targets]]
10591093
os = "<OS name>"
@@ -1095,6 +1129,12 @@ The `[[buildpack.licenses]]` table is optional and MAY contain a list of buildpa
10951129
- `type` - This MAY use the SPDX 2.1 license expression, but is not limited to identifiers in the SPDX Licenses List.
10961130
- `uri` - If this buildpack is using a nonstandard license, then this key MAY be specified in lieu of or in addition to `type` to point to the license.
10971131

1132+
**The buildpack execution environments:**
1133+
1134+
The `[[buildpack.exec-env]]` table is optional and MAY contain a list of execution environments that the buildpack supports where:
1135+
1136+
- `name` - This MUST specify an execution environment name (e.g., "production", "test", "development").
1137+
10981138
**The buildpack SBOM:**
10991139

11001140
*Key: `sbom-formats = [ "<string>" ]`*
@@ -1123,6 +1163,8 @@ Metadata specified in `[[targets]]` is validated against the runtime and build-t
11231163

11241164
A buildpack reference inside of a `group` MUST contain an `id` and `version`. The `order` MUST include only buildpacks and MUST NOT include image extensions.
11251165

1166+
A buildpack reference inside of a `group` MAY contain an `exec-env` array to specify the execution environments for which the buildpack applies.
1167+
11261168
### Exec.d Output (TOML)
11271169
```
11281170
<name> = "<value>"

0 commit comments

Comments
 (0)