-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #664 from buildpacks/consolidate-common-concepts
Consolidate common concepts
- Loading branch information
Showing
34 changed files
with
614 additions
and
624 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
+++ | ||
title="What is a buildpack?" | ||
weight=1 | ||
+++ | ||
|
||
A `buildpack` is software that transforms application source code into runnable artifacts | ||
by analyzing the code and determining the best way to build it. | ||
|
||
<!--more--> | ||
|
||
![buildpacks](/images/what.svg) | ||
|
||
## Why buildpacks? | ||
|
||
Buildpacks allow application developers to focus on what they do best - writing code, without having to worry about image security, optimizing container images, or container build strategy. | ||
|
||
How much time have you spent struggling to wrangle yet another Dockerfile? Copying and pasting random Dockerfile snippets into every project? Buildpacks can help! They are a better approach to building container images for applications. | ||
|
||
## What do they look like? | ||
|
||
Typical buildpacks consist of at least three files: | ||
|
||
* `buildpack.toml` -- provides metadata about the buildpack, containing information such as its name, ID, and version. | ||
* `bin/detect` -- performs [detect](#detect). | ||
* `bin/build` -- performs [build](#build). | ||
|
||
## How do they work? | ||
|
||
![how](/images/how.svg) | ||
|
||
**Each buildpack has two jobs to do** | ||
|
||
### Detect | ||
|
||
The buildpack determines if it is needed or not. | ||
|
||
For example: | ||
|
||
- A Python buildpack may look for a `requirements.txt` or a `setup.py` file. | ||
- A Node buildpack may look for a `package-lock.json` file. | ||
|
||
### Build | ||
|
||
The buildpack transforms application source code in some way, for example by | ||
|
||
- Setting build-time and run-time environment variables. | ||
- Downloading dependencies. | ||
- Running source code compilation (if needed). | ||
- Configuring the application entrypoint and any startup scripts. | ||
|
||
For example: | ||
|
||
- A Python buildpack may run `pip install -r requirements.txt` if it detected a `requirements.txt` file. | ||
- A Node buildpack may run `npm install` if it detected a `package-lock.json` file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
+++ | ||
title="What is a composite buildpack?" | ||
weight=99 | ||
+++ | ||
|
||
A composite buildpack, also sometimes called a "meta-buildpack", | ||
is a buildpack that does not contain any `./bin/detect` or `./bin/build` binaries, | ||
but instead references other buildpacks in its `buildpack.toml` via the `[[order]]` array. | ||
|
||
This is useful for composing more complex detection strategies. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
+++ | ||
title="What is an image extension?" | ||
aliases=[ | ||
"/docs/features/dockerfiles" | ||
] | ||
weight=99 | ||
+++ | ||
|
||
An `image extension` is software that generates Dockerfiles that can be used to extend base images for buildpacks builds. | ||
|
||
<!--more--> | ||
|
||
## Why image extensions? | ||
|
||
Buildpacks can do a lot, but there are some things buildpacks can't do. They can't install operating system packages, | ||
for example. Why not? | ||
|
||
Buildpacks do not run as the `root` user and cannot make arbitrary changes to the filesystem. This enhances security, | ||
enables buildpack interoperability, and preserves the ability to rebase - but it comes at a cost. Base image authors | ||
must anticipate the OS-level dependencies that will be needed at build and run-time ahead of time, and this isn't always | ||
possible. | ||
|
||
This has been a longstanding source of [discussion](https://github.com/buildpacks/rfcs/pull/173) within the CNB project: | ||
how can we preserve the benefits of buildpacks while enabling more powerful capabilities? | ||
|
||
### Buildpacks and Dockerfiles can work together | ||
|
||
Buildpacks are often presented as an alternative to Dockerfiles, but we think buildpacks and Dockerfiles can work | ||
together. | ||
|
||
Buildpacks are optimized for creating layers that are efficient and logically mapped to the dependencies that they | ||
provide. By contrast, Dockerfiles are the most-used and best-understood mechanism for constructing base images and | ||
installing OS-level dependencies for containers. | ||
|
||
The CNB Dockerfiles feature allows Dockerfiles to "provide" dependencies that buildpacks "require" through a | ||
shared [build plan], by introducing the concept of image extensions. | ||
|
||
## What do they look like? | ||
|
||
Image extensions are buildpack-like components that use a restricted `Dockerfile` syntax to expand base images. Their | ||
purpose is to generate Dockerfiles that can be used to extend the builder or run images prior to buildpacks builds. | ||
|
||
An image extension could be defined with the following directory: | ||
|
||
``` | ||
. | ||
├── extension.toml <- similar to a buildpack buildpack.toml | ||
├── bin | ||
│ ├── detect <- similar to a buildpack ./bin/detect | ||
│ ├── generate <- similar to a buildpack ./bin/build | ||
``` | ||
|
||
* The `extension.toml` provides metadata about the extension, containing information such as its name, ID, and version. | ||
* `./bin/detect` performs [detect](#detect). It analyzes application source code to determine if the extension | ||
is needed and contributes build plan entries. | ||
* `./bin/generate` performs [generate](#generate) (a new lifecycle phase that happens after `detect`). It | ||
outputs either or both of `build.Dockerfile` or `run.Dockerfile` for extending the builder or run image. | ||
|
||
## How do they work? | ||
|
||
**Each image extension has two jobs to do** | ||
|
||
### Detect | ||
|
||
The extension determines if it is needed or not. | ||
|
||
Like buildpacks, extensions participate in the `detect` phase - analyzing application source code to determine if they | ||
are needed. During `detect`, extensions can contribute to | ||
the [build plan] - recording dependencies that they are able to " | ||
provide" (though unlike buildpacks, they can't "require" anything). | ||
|
||
If the provided order contains extensions, the output of `detect` will be a group of image extensions and a group of | ||
buildpacks that together produce a valid build plan. Image extensions only generate Dockerfiles - they don't create | ||
layers or participate in the `build` phase. | ||
|
||
### Generate | ||
|
||
The extension outputs Dockerfiles that can be used to extend either or both of the build-time base image and the runtime base image. | ||
|
||
For more information and to see a build in action, | ||
see [authoring an image extension](/docs/for-buildpack-authors/tutorials/basic-extension). | ||
|
||
[build plan]: /docs/for-buildpack-authors/how-to/write-buildpacks/use-build-plan |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
+++ | ||
title="How To" | ||
weight=3 | ||
|
||
include_summaries=true | ||
+++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
+++ | ||
title="Concepts" | ||
weight=2 | ||
|
||
include_summaries=true | ||
+++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
+++ | ||
title="How To" | ||
weight=3 | ||
|
||
include_summaries=true | ||
+++ |
10 changes: 10 additions & 0 deletions
10
content/docs/for-buildpack-authors/how-to/distribute-buildpacks/craft-order.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
+++ | ||
title="Craft a buildpack order" | ||
weight=99 | ||
+++ | ||
|
||
<!--more--> | ||
|
||
This page is a stub! The CNB project is applying to [Google Season of Docs](https://developers.google.com/season-of-docs/docs/timeline) to receive support for improving our documentation. Please check back soon. | ||
|
||
If you are familiar with this content and would like to make a contribution, please feel free to open a PR :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
content/docs/for-buildpack-authors/how-to/write-buildpacks/add-sbom.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 43 additions & 3 deletions
46
content/docs/for-buildpack-authors/how-to/write-buildpacks/create-layer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,50 @@ | ||
+++ | ||
title="Create dependency layers" | ||
weight=99 | ||
weight=3 | ||
+++ | ||
|
||
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. | ||
|
||
<!--more--> | ||
|
||
This page is a stub! The CNB project is applying to [Google Season of Docs](https://developers.google.com/season-of-docs/docs/timeline) to receive support for improving our documentation. Please check back soon. | ||
That is, each directory can be used for any of the following purposes: | ||
|
||
| Layer Type | | | ||
|------------|-------------------------------------------------------------------------------------------------------------| | ||
| `Launch` | the directory will be included in the **final app image** as a single layer | | ||
| `Cache` | the directory will be included in the **build cache** and restored to the `CNB_LAYERS_DIR` on future builds | | ||
| `Build` | the directory will be accessible to **buildpacks that follow** in the build (via the environment) | | ||
|
||
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`. | ||
|
||
### Example | ||
|
||
A buildpack might create a `$CNB_LAYERS_DIR/python` directory and a `$CNB_LAYERS_DIR/python.toml` with the following contents: | ||
|
||
``` | ||
launch = true | ||
cache = true | ||
build = true | ||
``` | ||
|
||
In this example: | ||
* the final app image will contain a layer with `python`, as this is needed to run the app | ||
* the `$CNB_LAYERS_DIR/python` directory will be pre-created for future builds, avoiding the need to re-download this large dependency | ||
* buildpacks that follow in the build will be able to use `python` | ||
|
||
### Example | ||
|
||
This is a simple `./bin/build` script for a buildpack that runs Python's `pip` package manager to resolve dependencies: | ||
|
||
``` | ||
#!/bin/sh | ||
PIP_LAYER="$CNB_LAYERS_DIR/pip" | ||
mkdir -p "$PIP_LAYER/modules" "$PIP_LAYER/env" | ||
pip install -r requirements.txt -t "$PIP_LAYER/modules" \ | ||
--install-option="--install-scripts=$PIP_LAYER/bin" \ | ||
--exists-action=w --disable-pip-version-check --no-cache-dir | ||
If you are familiar with this content and would like to make a contribution, please feel free to open a PR :) | ||
echo "launch = true" > "$PIP_LAYER.toml" | ||
``` |
Oops, something went wrong.