Skip to content

Commit c7071cd

Browse files
authored
Merge branch 'main' into jjbustamante/0134-execution-env-buildpack
2 parents bf7d6a1 + 732fc7b commit c7071cd

File tree

2 files changed

+60
-6
lines changed

2 files changed

+60
-6
lines changed

buildpack.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,9 @@ The following additional environment variables MUST NOT be overridden by the lif
818818
| `HOME` | Current user's home directory | [x] | [x] | [x] |
819819

820820
During the detection and build phases, the lifecycle MUST provide as environment variables any user-provided files in `<platform>/env/` with environment variable names and contents matching the file names and contents.
821-
During the detection and build phases, the lifecycle MUST provide as environment variables any operator-provided files in `<build-config>/env` with environment variable names and contents matching the file names and contents. This applies for all values of `clear-env` or if `clear-env` is undefined in `buildpack.toml`.
821+
During the detection and build phases, the lifecycle MUST provide as environment variables any operator-provided files in `<platform>/env` with environment variable names and contents matching the file names and contents. This applies for all values of `clear-env` or if `clear-env` is undefined in `buildpack.toml`.
822822

823-
When `clear-env` in `buildpack.toml` is set to `true` for a given buildpack, the lifecycle MUST NOT set user-provided environment variables in the environment of `/bin/detect` or `/bin/build`.
823+
When `clear-env` in `buildpack.toml` is set to `true` for a given buildpack, the lifecycle MUST NOT set user-provided environment variables in the environment of `/bin/detect` or `/bin/build`. The user-provided files in `<platform>/env/` contents will still be available.
824824

825825
When `clear-env` in `buildpack.toml` is not set to `true` for a given buildpack, the lifecycle MUST set user-provided environment variables in the environment of `/bin/detect` or `/bin/build` such that:
826826
1. For layer path environment variables, user-provided values are prepended before any existing values and are delimited by the OS path list separator.

platform.md

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Examples of a platform might include:
8888
- [`project-metadata.toml` (TOML)](#project-metadatatoml-toml)
8989
- [`report.toml` (TOML)](#reporttoml-toml)
9090
- [`run.toml` (TOML)](#runtoml-toml)
91+
- [`system.toml` (TOML)](#systemtoml-toml)
9192
- [Labels](#labels)
9293
- [`io.buildpacks.build.metadata` (JSON)](#iobuildpacksbuildmetadata-json)
9394
- [`io.buildpacks.lifecycle.metadata` (JSON)](#iobuildpackslifecyclemetadata-json)
@@ -130,6 +131,8 @@ A **launcher layer** refers to a layer in the app OCI image containing the **lau
130131

131132
The **launcher** refers to a lifecycle executable packaged in the **app image** for the purpose of executing processes at runtime.
132133

134+
An **execution environment** refers to the context in which an application is intended to run. Standard values include "production", "test", and "development". Production is the default if not specified. The value MUST NOT contain the character `/` as it is reserved for future use.
135+
133136
An **image extension** refers to software compliant with the [Image Extension Interface Specification](image_extension.md). Image extensions participate in detection and execute before the buildpack build process.
134137

135138
A **stack** (deprecated, see [deprecations](#deprecations)) is a contract, implemented by a **build image** and **run image**, that guarantees properties of the **build environment** and **app image**.
@@ -389,7 +392,8 @@ Usage:
389392
[-order <order>] \
390393
[-plan <plan>] \
391394
[-platform <platform>] \
392-
[-run <run> ]
395+
[-run <run> ] \
396+
[-system <system>]
393397
```
394398

395399
##### Inputs
@@ -400,6 +404,7 @@ Usage:
400404
| `<app>` | `CNB_APP_DIR` | `/workspace` | Path to application directory |
401405
| `<build-config>` | `CNB_BUILD_CONFIG_DIR` | `/cnb/build-config` | Path to build config directory |
402406
| `<buildpacks>` | `CNB_BUILDPACKS_DIR` | `/cnb/buildpacks` | Path to buildpacks directory (see [Buildpacks Directory Layout](#buildpacks-directory-layout)) |
407+
| `<exec-env>` | `CNB_EXEC_ENV` | `production` | Target execution environment. Standard values: "production", "test", "development". |
403408
| `<extensions>`^ | `CNB_EXTENSIONS_DIR` | `/cnb/extensions` | Path to image extensions directory (see [Image Extensions Directory Layout](#image-extensions-directory-layout) |
404409
| `<generated>`^ | `CNB_GENERATED_DIR` | `<layers>/generated` | Path to output directory for generated Dockerfiles |
405410
| `<group>` | `CNB_GROUP_PATH` | `<layers>/group.toml` | Path to output group definition |
@@ -409,6 +414,7 @@ Usage:
409414
| `<plan>` | `CNB_PLAN_PATH` | `<layers>/plan.toml` | Path to output resolved build plan |
410415
| `<platform>` | `CNB_PLATFORM_DIR` | `/platform` | Path to platform directory |
411416
| `<run>`^ | `CNB_RUN_PATH` | `/cnb/run.toml` | Path to run file (see [`run.toml`](#runtoml-toml)) |
417+
| `<system>` | `CNB_SYSTEM_PATH` | `/cnb/system.toml` | Path to system buildpacks file (see [`system.toml`](#systemtoml-toml)) |
412418

413419
> ^Only needed when using image extensions
414420
@@ -438,10 +444,20 @@ Usage:
438444
| `91` | Extension generate error |
439445
| `92-99` | Generation-specific lifecycle errors |
440446

447+
When `<system>` is provided (optional), the lifecycle:
448+
- SHALL merge the `system.pre.buildpacks` group with each group from `<order>` such that the `pre` buildpacks are placed at the beginning of each order group before running detection.
449+
- System buildpacks in `pre` SHALL NOT be merged if the group already contains a buildpack with the same ID.
450+
- SHALL merge the `system.post.buildpacks` group with each group from `<order>` such that the `post` buildpacks are placed at the end of each order group before running detection.
451+
- System buildpacks in `post` SHALL NOT be merged if the group already contains a buildpack with the same ID.
452+
441453
The lifecycle:
442454
- SHALL detect a single group from `<order>` and write it to `<group>` using the [detection process](buildpack.md#phase-1-detection) outlined in the Buildpack Interface Specification
443455
- SHALL write the resolved build plan from the detected group to `<plan>`
444456
- SHALL provide `run-image.target` data in `<analyzed>` to buildpacks according to the process outlined in the [Buildpack Interface Specification](buildpack.md).
457+
- When `CNB_EXEC_ENV` is set to a value other than the default:
458+
- The lifecycle SHALL skip buildpacks that do not support the current execution environment during detection
459+
- If all buildpacks in a group are skipped due to execution environment mismatch, the lifecycle SHALL continue to the next group in the order
460+
- This allows the platform to select buildpack groups appropriate for the target execution environment
445461

446462
When image extensions are present in the order (optional), the lifecycle:
447463
- SHALL execute all image extensions in the order defined in `<group>` according to the process outlined in the [Buildpack Interface Specification](buildpack.md).
@@ -501,6 +517,7 @@ Usage:
501517
| `<skip-layers>` | `CNB_SKIP_LAYERS` | `false` | Do not perform [layer restoration](#layer-restoration) |
502518
| `<uid>` | `CNB_USER_ID` | | UID of the build image `User` |
503519
| `<run>`** | `CNB_RUN_PATH` | `/cnb/run.toml` | Path to run file (see [`run.toml`](#runtoml-toml)) |
520+
| `<exec-env>` | `CNB_EXEC_ENV` | `production` | Target execution environment. Standard values: "production", "test", "development". |
504521
> ^ Only needed when using image extensions
505522
506523
> \* Only needed when using image extensions to extend the build image
@@ -543,7 +560,9 @@ Usage:
543560

544561
##### Layer Restoration
545562

546-
lifeycle MUST use the provided `cache-dir` or `cache-image` to retrieve cache contents. The [rules](https://github.com/buildpacks/spec/blob/main/buildpack.md#layer-types) for restoration MUST be followed when determining how and when to store cache layers.
563+
The lifecycle MUST use the provided `cache-dir` or `cache-image` to retrieve cache contents. The [rules](https://github.com/buildpacks/spec/blob/main/buildpack.md#layer-types) for restoration MUST be followed when determining how and when to store cache layers.
564+
565+
When a platform builds an application with a different execution environment than was used in a previous build (different value of `CNB_EXEC_ENV`), 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.
547566

548567
#### `extender` (optional)
549568

@@ -588,6 +607,7 @@ Usage:
588607
| `<plan>`* | `CNB_PLAN_PATH` | `<layers>/plan.toml` | Path to resolved build plan (see [`plan.toml`](#plantoml-toml)) |
589608
| `<platform>` | `CNB_PLATFORM_DIR` | `/platform` | Path to platform directory |
590609
| `<uid>`* | `CNB_USER_ID` | | UID of the build image `User` |
610+
| `<exec-env>` | `CNB_EXEC_ENV` | `production` | Target execution environment. Standard values: "production", "test", "development". |
591611

592612
> \* Only needed when extending the build image
593613
@@ -656,6 +676,7 @@ Usage:
656676
| `<app>` | `CNB_APP_DIR` | `/workspace` | Path to application directory |
657677
| `<build-config>` | `CNB_BUILD_CONFIG_DIR` | `/cnb/build-config` | Path to build config directory |
658678
| `<buildpacks>` | `CNB_BUILDPACKS_DIR` | `/cnb/buildpacks` | Path to buildpacks directory (see [Buildpacks Directory Layout](#buildpacks-directory-layout)) |
679+
| `<exec-env>` | `CNB_EXEC_ENV` | `production` | Target execution environment. Standard values: "production", "test", "development". |
659680
| `<group>` | `CNB_GROUP_PATH` | `<layers>/group.toml` | Path to group definition (see [`group.toml`](#grouptoml-toml)) |
660681
| `<layers>` | `CNB_LAYERS_DIR` | `/layers` | Path to layers directory |
661682
| `<log-level>` | `CNB_LOG_LEVEL` | `info` | Log Level |
@@ -988,6 +1009,7 @@ Usage:
9881009
| Input | Environment Variable | Default Value | Description |
9891010
|------------------------------------|----------------------|---------------|-----------------------------------------------------------|
9901011
| `<app>` | `CNB_APP_DIR` | `/workspace` | Path to application directory |
1012+
| `<exec-env>` | `CNB_EXEC_ENV` | `production` | Target execution environment. Standard values: "production", "test", "development". |
9911013
| `<layers>` | `CNB_LAYERS_DIR` | `/layers` | Path to layer directory |
9921014
| `<process-type>` | | | `type` of process to launch |
9931015
| `<direct>` | | | Process execution strategy |
@@ -1004,7 +1026,12 @@ The launcher:
10041026
- **If** the final path element in `$0`, matches the type of any buildpack-provided process type
10051027
- `<process-type>` SHALL be the final path element in `$0`
10061028
- The lifecycle:
1007-
- MUST select the process with type equal to `<process-type>` from `<layers>/config/metadata.toml`
1029+
- MUST select the process with type equal to `<process-type>` from `<layers>/config/metadata.toml` that is eligible for the current execution environment
1030+
- **If** no process with the requested type is eligible for the current execution environment, the lifecycle MUST fail
1031+
- A process is considered eligible for the current execution environment if:
1032+
- It has no execution environment specified in `exec-env`, OR
1033+
- Its `exec-env` includes the value of `<exec-env>`, OR
1034+
- Its `exec-env` includes the special value `"*"` which indicates compatibility with all execution environments
10081035
- MUST set `<working-dir>` to the value defined for the process in `<layers>/config/metadata.toml`, or to `<app>` if not defined
10091036
- **If** the buildpack that provided the process supports default process args
10101037
- `<direct>` SHALL be `true`
@@ -1328,6 +1355,7 @@ command = ["<command>"]
13281355
args = ["<arguments>"]
13291356
direct = false
13301357
working-dir = "<working directory>"
1358+
exec-env = ["<execution environment>"] # Optional. If not specified, applies to all execution environments. The special value "*" indicates compatibility with all execution environments. If exec-env is ["*"] or not specified, the process is eligible for all execution environments.
13311359

13321360
[[slices]]
13331361
paths = ["<app sub-path glob>"]
@@ -1336,6 +1364,9 @@ paths = ["<app sub-path glob>"]
13361364
Where:
13371365
- `id`, `version`, and `api` MUST be present for each buildpack
13381366
- `processes` contains the complete set of processes contributed by all buildpacks
1367+
- The `exec-env` field MUST be set to `["*"]` if the process applies to all execution environments
1368+
- The `exec-env` field MUST contain specific execution environment values (e.g., `["production"]`, `["test", "development"]`) if the process is restricted to certain environments
1369+
- If `exec-env` is not specified, it SHALL be treated as `["*"]` (applies to all environments)
13391370
- `slices` contains the complete set of slices defined by all buildpacks
13401371

13411372
#### `order.toml` (TOML)
@@ -1433,6 +1464,27 @@ Where:
14331464
- SHOULD reference an image with ID identical to that of `image.image`
14341465
- `image.image` and `image.mirrors.[]` SHOULD each refer to a unique registry
14351466

1467+
#### `system.toml` (TOML)
1468+
1469+
```toml
1470+
[[system.pre.buildpacks]]
1471+
id = "<buildpack ID>"
1472+
version = "<buildpack version>"
1473+
optional = false
1474+
1475+
[[system.post.buildpacks]]
1476+
id = "<buildpack ID>"
1477+
version = "<buildpack version>"
1478+
optional = false
1479+
```
1480+
1481+
Where:
1482+
1483+
- `system.pre.buildpacks` MAY contain a list of buildpacks to insert at the beginning of every order group before detection.
1484+
- `system.post.buildpacks` MAY contain a list of buildpacks to insert at the end of every order group before detection.
1485+
- Both `id` and `version` MUST be present for each buildpack object in `system.pre.buildpacks` and `system.post.buildpacks`.
1486+
- The value of `optional` MUST default to `false` if not specified.
1487+
14361488
### Labels
14371489

14381490
#### `io.buildpacks.build.metadata` (JSON)
@@ -1448,7 +1500,8 @@ Where:
14481500
],
14491501
"direct": false,
14501502
"working-dir": "<working-dir>",
1451-
"buildpackID": "<buildpack ID>"
1503+
"buildpackID": "<buildpack ID>",
1504+
"exec-env": ["<execution environment>"] // Array of execution environments. Use ["*"] for all environments. If omitted, defaults to ["*"]
14521505
}
14531506
],
14541507
"buildpacks": [
@@ -1498,6 +1551,7 @@ Where:
14981551
"config": {
14991552
"sha": "<config-layer-diffID>"
15001553
},
1554+
"exec-env": "<execution environment>",
15011555
"launcher": {
15021556
"sha": "<launcher-layer-diffID>"
15031557
},

0 commit comments

Comments
 (0)