Skip to content

Commit 1e018ca

Browse files
authored
Merge pull request #796 from sap-contributions/cnb-lifecycle
RFC to introduce Cloud Native Buildpacks lifecycle
2 parents 9ef1467 + 9803665 commit 1e018ca

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

toc/rfc/rfc-draft-cnb-lifecycle.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
# Meta
2+
3+
[meta]: #meta
4+
- Name: Cloud Native Buildpacks Lifecycle
5+
- Start Date: 2024-03-19
6+
- Author(s): @c0d1ngm0nk3y, @pbusko, @nicolasbender, @modulo11
7+
- Status: Draft <!-- Acceptable values: Draft, Approved, On Hold, Superseded -->
8+
- RFC Pull Request: https://github.com/cloudfoundry/community/pull/796
9+
- Updates: [RFC 0017](https://github.com/cloudfoundry/community/blob/main/toc/rfc/rfc-0017-add-cnbs.md)
10+
11+
## Summary
12+
13+
[Cloud Native Buildpacks (CNBs)](https://buildpacks.io/), also known as v3 buildpacks, are the current generation of buildpacks and offer some improvements over the v2 buildpacks that CF Deployment currently uses. The Cloud Foundry Foundation already has an implementation of Cloud Native Buildpacks via the [Paketo](https://paketo.io/) project, however these CNBs can't currently be used in CF.
14+
15+
This RFC introduces a new optional lifecycle to Cloud Foundry which enables users to build their applications using Cloud Native Buildpacks.
16+
17+
## Problem
18+
19+
The v2 buildpacks are effectively in maintenance mode and do not receive substantial new features. By not integrating with v3 buildpacks, Cloud Foundry is missing out on new buildpacks (e.g. Java Native and Web Servers CNBs) as well as any new features that are added to the still-actively-developed v3 buildpacks.
20+
21+
## Proposal
22+
23+
- Introduce a new [lifecycle type](https://v3-apidocs.cloudfoundry.org/index.html#lifecycles) `cnb` and its lifecycle data
24+
- Introduce a new [app lifecycle](https://github.com/cloudfoundry/diego-design-notes#app-lifecycles) called `cnbapplifecycle` which interacts with the [CNB Lifecycle](https://github.com/buildpacks/lifecycle)
25+
- Reuse [cflinuxfs4](https://github.com/cloudfoundry/cflinuxfs4) as the base for staging and running apps
26+
- Introduce a new flag to CLI and the [app manifest](https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html) to be able to use Cloud Native Buildpacks instead of v2 buildpacks
27+
28+
### Architecture
29+
30+
This will require changes in the following releases:
31+
32+
- CF CLI
33+
- Cloud Controller
34+
- Diego
35+
36+
No changes to how Diego runs workloads are necessary to implement this RFC.
37+
38+
- The cli will forward a new app lifecycle type to the cloud controller.
39+
- The cloud controller will use a new `cnbapplifecycle` for the application.
40+
41+
Affected cloud controller APIs (all that interact with [lifecycles](https://v3-apidocs.cloudfoundry.org/index.html#lifecycles)):
42+
43+
- [apps](https://v3-apidocs.cloudfoundry.org/index.html#apps)
44+
- [builds](https://v3-apidocs.cloudfoundry.org/index.html#builds)
45+
- [droplets](https://v3-apidocs.cloudfoundry.org/index.html#droplets)
46+
- [manifests](https://v3-apidocs.cloudfoundry.org/index.html#manifests)
47+
48+
### Goals
49+
50+
- Establish the latest generation of buildpacks in CF as first-class citizen
51+
- Increase cohesion and app portability between CF Deployment and [Korifi](https://www.cloudfoundry.org/technology/korifi/), via mutual Paketo integration
52+
- Increase adoption of Cloud Native Buildpacks
53+
- Open the door for eventual deprecation of the v2 buildpacks, reducing maintenance costs (v2 buildpack deprecation is NOT included in this RFC)
54+
- No fundamental changes to the architecture of CF
55+
- Result of the staging process will be a droplet
56+
- No OCI registry necessary
57+
- Reuse cflinuxfs4 as rootfs during build and run
58+
- No change to how the Cloud Foundry platform provides service binding information (see [#804](https://github.com/cloudfoundry/community/pull/804) for how this will be covered in a separate RFC)
59+
60+
### High Level Implementation
61+
62+
#### CNB App Lifecycle
63+
64+
Introduce a new `lifecycle type` that enables the cloud controller to differentiate between the classical buildpacks and Cloud Native Buildpacks. On a high level, it will be very similar to the existing buildpackapplifecycle (v2 buildpacks). The new app lifecycle acts as a CNB [platform](https://buildpacks.io/docs/for-app-developers/concepts/platform/) and will:
65+
66+
1. Download the app source code from the blobstore
67+
1. Download the CNB app lifecycle from the blobstore
68+
1. Download the configured buildpacks
69+
1. Write an [order.toml](https://github.com/buildpacks/spec/blob/main/platform.md#ordertoml-toml) with configured buildpacks
70+
1. Execute [detect](https://github.com/buildpacks/spec/blob/main/platform.md#detector) and [build](https://github.com/buildpacks/spec/blob/main/platform.md#builder) phases using the [CNB lifecycle](https://github.com/buildpacks/lifecycle)
71+
1. Package the result into a droplet and upload it to the blobstore
72+
1. Write a result.json file with the [Staging Result](https://github.com/cloudfoundry/buildpackapplifecycle/blob/f4b2bc9ff6cc6229402d7c27e887763154cf0378/models.go#L73-L80)
73+
74+
#### CNB Lifecycle Type
75+
76+
Introduce a new type of lifecycle type which indicates that Cloud Native Buildpacks should be used. In future, this can be enhanced with additional CNB inputs. For this RFC we’d start with:
77+
78+
```json
79+
{
80+
"type": "cnb",
81+
"data": {
82+
"buildpacks": ["docker://gcr.io/paketo-buildpacks/java"],
83+
"stack": "cflinuxfs4"
84+
}
85+
}
86+
```
87+
88+
Both, building and running an app will be based on the configured stack. If no stack is provided, the platform default is used. An empty (or not provided) list of buildpacks will lead to an error. This essentially means, that no auto-detection is supported at the moment. Once [system CNBs](#system-buildpacks) are supported, this behavior will change.
89+
90+
#### CF CLI
91+
92+
New flag `–-lifecycle [buildpack|docker|cnb]` will be introduced to the `cf push` command.
93+
94+
#### App Manifest
95+
96+
New property `lifecycle: buildpack|docker|cnb` will be added to the App manifest. It will default to `lifecycle: buildpack`. Using `docker-*` properties implies `lifecycle: docker`.
97+
The buildpack URL must start with one of the following schemas: `docker://`, `http://` or `https://`.
98+
99+
```yaml
100+
---
101+
applications:
102+
- name: test-app
103+
instances: 1
104+
lifecycle: cnb
105+
buildpacks:
106+
- docker://gcr.io/paketo-buildpacks/java
107+
```
108+
109+
Both changes (CLI and manifest) were chosen because they are simple (from a user perspective), easy to implement and remove, if CNBs will become the standard lifecycle in future.
110+
111+
### Alternative APIs
112+
113+
- Instead of a lifecycle type switch, introduce a `buildpack-type` (`v2`/`v3` or `cf`/`cnb` or `classic`/`cnb`) to distinguish between different lifecycles.
114+
115+
#### Diego Release
116+
117+
The new lifecycle package `cnb_app_lifecycle` will be added to the Diego BOSH release, next to the existing `buildpack_app_lifecycle` and `docker_app_lifecycle`. This lifecycle package should be served by the File Server in the same way as existing lifecycle packages.
118+
119+
### Possible Future Work
120+
121+
#### Add Paketo Stack(s)
122+
123+
This RFC does not include the addition of a new stack to Cloud Foundry, rather the resulting droplet would run on top of the existing `cflinuxfs4`. This should work for most, if not all apps, as the stack is much bigger (in terms of native packages installed) than the stacks used by Paketo.
124+
125+
Paketo provides multiple stacks that are compatible with the Paketo buildpacks. There is an opportunity to adopt some or all of the Paketo stacks into CF Deployment. The Paketo buildpacks have greater cohesion with the Paketo stacks than with `cflinuxfs4`, and the Paketo "base" and "tiny" stacks could offer security-conscious CF Deployment users stacks with far fewer native packages than are currently included with `cflinuxfs4`.
126+
127+
This RFC does not cover the adoption of additional stacks into CF Deployment, but it does open the door to add these stacks in the future.
128+
129+
#### System Buildpacks
130+
131+
This RFC enables only the use of custom buildpacks. CNBs could be added as system buildpacks later to support some auto detection as for the existing v2 buildpacks.
132+
133+
#### Better SBoM Support
134+
135+
This RFC already introduces some SBoM capabilities offered by CNBs. Yet, it is not complete (runtime OS information is missing) and buried in the layers of the droplet. This could be further improved in future.
136+
137+
### Open Questions
138+
139+
#### Pulling Buildpacks from private registries
140+
141+
Cloud Foundry currently supports only a single set of credentials together with a single docker image being passed as part of a `cf push --docker`. However, with Cloud Native Buildpacks multiple images, from multiple registries, using different credentials is possible. Deducting the registry from the passed Cloud Native Buildpacks is not possible e.g. when they are consumed from unauthenticated (e.g. DockerHub) and authenticated registries.
142+
143+
Options:
144+
145+
- Require environment variable with docker config content.
146+
147+
```json
148+
{
149+
"auths": {
150+
"registry.io": {
151+
"auth": "dXNlcjpwYXNzd29yZA=="
152+
}
153+
}
154+
}
155+
```
156+
157+
- Require environment variable pointing to docker config file. CF CLI must parse the file and invoke helpers if needed for required registries.
158+
- Require custom credentials configuration e.g.
159+
160+
```bash
161+
CNB_REGISTRY_CREDS='{"registry.io":{"user":"password"}}' cf push ...
162+
```
163+
164+
```json
165+
{
166+
"type": "cnb",
167+
"data": {
168+
"buildpacks": ["docker://gcr.io/paketo-buildpacks/java"],
169+
"stack": "cflinuxfs4",
170+
"credentials": {
171+
"registry.io": {
172+
"user": "password"
173+
}
174+
}
175+
}
176+
}
177+
```

0 commit comments

Comments
 (0)