|
| 1 | ++++ |
| 2 | +title="Platform API 0.11 -> 0.12" |
| 3 | ++++ |
| 4 | + |
| 5 | +<!--more--> |
| 6 | + |
| 7 | +This guide is most relevant to platform operators, base image authors, and builder authors. |
| 8 | + |
| 9 | +See the [spec release](https://github.com/buildpacks/spec/releases/tag/platform%2Fv0.12) for Platform API 0.12 for the full list of changes and further details. |
| 10 | + |
| 11 | +## Platform Operator |
| 12 | + |
| 13 | +### Stacks are deprecated |
| 14 | + |
| 15 | +In Platform 0.12, the concepts of stacks and mixins are removed |
| 16 | +in favor of existing constructs in the container image ecosystem such as operating system name, operating system distribution, and architecture. |
| 17 | + |
| 18 | +#### During build |
| 19 | + |
| 20 | +The `-stack` flag is removed from the `analyzer` and `exporter` and replaced with a `-run` flag |
| 21 | +that indicates the location of a `run.toml` file with schema: |
| 22 | + |
| 23 | +```toml |
| 24 | +[[images]] |
| 25 | + image = "<image>" |
| 26 | + mirrors = ["<mirror>", "<mirror>"] |
| 27 | +``` |
| 28 | + |
| 29 | +This file will be created automatically at `/cnb/run.toml` during `pack builder create` if the `pack` version is at least `0.30.0` (see below). |
| 30 | + |
| 31 | +For each image in `[[images]]`, `image` is a tag reference to a run image and `mirrors` contains tag references to its mirrors. |
| 32 | +Note that whereas `stack.toml` (removed in this API version) only contained a single run image with mirrors, `run.toml` contains a list of images. |
| 33 | +This is because of image extensions and the possibility of run image switching, introduced in Platform 0.10. |
| 34 | +For platforms that do not use image extensions, only a single run image with mirrors is needed in `run.toml`. |
| 35 | + |
| 36 | +#### After build |
| 37 | + |
| 38 | +The `stack` key in the `io.buildpacks.lifecycle.metadata` is removed. |
| 39 | +To find a tag reference to the run image and mirrors information, |
| 40 | +platforms should read the newly added `runImage.image` and `runImage.mirrors` in `io.buildpacks.lifecycle.metadata`. |
| 41 | + |
| 42 | +#### During rebase |
| 43 | + |
| 44 | +Additional validations were added to the `rebaser` along with a `-force` flag to force rebase when validations are not satisfied. |
| 45 | + |
| 46 | +If `-force` is not provided, |
| 47 | +* The following values in the image config for the new run image must match the original image config: |
| 48 | + * `os` |
| 49 | + * `architecture` |
| 50 | + * `variant` (if specified) |
| 51 | + * `io.buildpacks.base.distro.name` label (if specified) |
| 52 | + * `io.buildpacks.base.distro.version` label (if specified) |
| 53 | +* If `-run-image` is provided it must be found in `io.buildpacks.lifecycle.metadata` in either `runImage.image` or `runImage.mirrors` |
| 54 | +* `io.buildpacks.rebasable` must be `true` (see image extensions below) |
| 55 | + |
| 56 | +### Run image extensions is supported (experimental) |
| 57 | + |
| 58 | +In Platform 0.12, extensions can be used to extend not only build-time base images, but runtime base images as well. |
| 59 | + |
| 60 | +#### During build |
| 61 | + |
| 62 | +To use the feature, platforms should: |
| 63 | +* Invoke `analyzer` as usual for Platform 0.12 |
| 64 | +* Invoke `detector` with the `-run` flag, to specify the location of a `run.toml` file containing run image information |
| 65 | + * When extensions switch the run image, this is used to log a warning if the new run image is not a known run image |
| 66 | +* Invoke `restorer` with the `-dameon` flag (newly added in this Platform API version) if the export target is a daemon |
| 67 | + * When extensions switch the run image, the `restorer` must re-read target data from the new run image in order to provide this information to buildpacks; if `-daemon` is provided the `restorer` will look for the run image in a daemon instead of a registry |
| 68 | + * When extensions extend the run image, the `-daemon` flag has no effect as the `restorer` must be able to pull the run image manifest from a registry |
| 69 | +* Invoke `extender` as usual to extend the builder image (see [migration guide](/docs/reference/spec/migration/platform-api-0.9-0.10/index.html) for Platform 0.10) |
| 70 | +* Inspect the contents of `analyzed.toml` - if `run-image.extend` is `true` we must run the `extender` on the run image |
| 71 | +* Using the **run image** as the basis for the container, invoke `extender` with flags `-kind run` and `-extended <extended dir>` |
| 72 | + * `<extended dir>` is the directory where layers created from the application of each `run.Dockerfile` to the run image will be saved for use by the `exporter`; it defaults to `<layers>/extended` |
| 73 | + * Run image extension may be done in parallel with builder image extension |
| 74 | +* Invoke `exporter` with the `-extended` flag |
| 75 | + |
| 76 | +#### After build |
| 77 | + |
| 78 | +Note that unlike buildpack-provided layers, layers from extensions may NOT be safe to rebase. |
| 79 | +The `io.buildpacks.rebasable` label on the exported application image will be `false` if rebase is unsafe. |
| 80 | +The `-force` flag must be provided to the `rebaser` in order to rebase images with unsafe extension layers, |
| 81 | +and should be used with great care. |
| 82 | + |
| 83 | +### The `exporter` no longer deletes cache images |
| 84 | + |
| 85 | +The `exporter` will no longer delete the previous version of the cache image before saving the new version - |
| 86 | +which could lead to untagged blobs in the registry. |
| 87 | + |
| 88 | +Platforms should ensure that any untagged blobs are cleaned periodically if their registry does not already support such pruning. |
| 89 | + |
| 90 | +### OCI layout is a supported export format (experimental) |
| 91 | + |
| 92 | +Platform 0.12 adds a new capability to [export application images on disk in OCI layout format](https://github.com/buildpacks/rfcs/blob/main/text/0119-export-to-oci.md). |
| 93 | + |
| 94 | +#### Before build |
| 95 | + |
| 96 | +To use the feature, platforms must prepare a [layout directory](https://github.com/buildpacks/rfcs/blob/main/text/0119-export-to-oci.md#how-it-works) containing input images (`<run-image>` or `<previous-image>` if available) in OCI layout format, |
| 97 | +following the [rules](https://github.com/buildpacks/spec/blob/platform/v0.12/platform.md#map-an-image-reference-to-a-path-in-the-layout-directory) to convert the image reference to a path. |
| 98 | + |
| 99 | +#### During build |
| 100 | + |
| 101 | +The feature is enabled by providing a `-layout` flag or by setting the `CNB_USE_LAYOUT` environment variable to `true` for the following lifecycle phases: |
| 102 | + |
| 103 | +- [Analyze](https://buildpacks.io/docs/concepts/components/lifecycle/analyze/) |
| 104 | +- [Restore](https://buildpacks.io/docs/concepts/components/lifecycle/restore/) |
| 105 | +- [Export](https://buildpacks.io/docs/concepts/components/lifecycle/export/) |
| 106 | +- [Create](https://buildpacks.io/docs/concepts/components/lifecycle/create/) |
| 107 | + |
| 108 | +Additionally, the path to the layout directory must be specified, either by providing a `-layout-dir` flag or by setting the `CNB_LAYOUT_DIR` environment variable. |
| 109 | + |
| 110 | +**Note**: [Rebasing](https://buildpacks.io/docs/concepts/components/lifecycle/rebase/) an image exported to OCI layout format |
| 111 | +and extending OCI layout base images with Dockerfiles are currently not supported. |
| 112 | + |
| 113 | +## Base Image Author |
| 114 | + |
| 115 | +### Stacks are deprecated |
| 116 | + |
| 117 | +When creating build-time or runtime base images, base image authors should set `io.buildpacks.base.distro.name` and `io.buildpacks.base.distro.version` labels |
| 118 | +containing the values specified in `/etc/os-release` (`$ID` and `$VERSION_ID`). |
| 119 | +This information - along with operating system, architecture, and architecture variant from the OCI image config, |
| 120 | +will be exposed to buildpacks through `$CNB_TARGET_*` environment variables. |
| 121 | + |
| 122 | +Additionally, authors may set an `io.buildpacks.base.id` label on runtime base images to uniquely identify the image "flavor" - see the [Platform spec](https://github.com/buildpacks/spec/blob/main/platform.md#target-data) for further information and requirements. |
| 123 | + |
| 124 | +To allow newer builders to run on older platforms, base image authors should continue to set any `io.buildpacks.stack.*` labels that are still relevant. |
| 125 | +Note that "information only" labels such as `io.buildpacks.stack.maintainer` have new equivalents in `io.buildpacks.base.maintainer`, |
| 126 | +and it is recommended to set both sets of labels for the time being. |
| 127 | + |
| 128 | +To maintain compatibility with older buildpacks, build-time base images should continue to set `$CNB_STACK_ID` in the build environment. |
| 129 | + |
| 130 | +## Builder Author |
| 131 | + |
| 132 | +### Stacks are deprecated |
| 133 | + |
| 134 | +With the removal of stacks, there is also a new way to reference build-time and runtime base images in `builder.toml`. |
| 135 | +Builder authors should ensure their `pack` version is at least `0.30.0` in order to create builders that will work with newer platforms. |
| 136 | + |
| 137 | +The new `builder.toml` schema is: |
| 138 | + |
| 139 | +```toml |
| 140 | +[run] |
| 141 | +[[run.images]] |
| 142 | +image = "cnbs/some-run-image" |
| 143 | +mirrors = ["mirror1", "mirror2"] |
| 144 | +[build] |
| 145 | +image = "cnbs/some-build-image" |
| 146 | +``` |
| 147 | + |
| 148 | +Run image information will be translated to `run.toml` in the builder with schema: |
| 149 | + |
| 150 | +```toml |
| 151 | +[[images]] |
| 152 | + image = "cnbs/some-run-image" |
| 153 | + mirrors = ["mirror1", "mirror2"] |
| 154 | +``` |
| 155 | + |
| 156 | +Run image information will also be translated to `stack.toml` (for compatibility with older platforms) in the builder with schema: |
| 157 | + |
| 158 | +```toml |
| 159 | +[run-image] |
| 160 | + image = "cnbs/some-run-image" |
| 161 | + mirrors = ["mirror1", "mirror2"] |
| 162 | +``` |
| 163 | + |
| 164 | +The old `builder.toml` schema is still valid: |
| 165 | + |
| 166 | +```toml |
| 167 | +[stack] |
| 168 | +id = "some.stack.id" |
| 169 | +run-image = "cnbs/some-run-image" |
| 170 | +run-image-mirrors = ["mirror1", "mirror2"] |
| 171 | +build-image = "cnbs/some-build-image" |
| 172 | +``` |
| 173 | + |
| 174 | +If the old `builder.toml` schema is used, run image information will be translated to the same `run.toml` and `stack.toml` file formats as above. |
| 175 | + |
| 176 | +It is possible to define both the new and the old schema within `builder.toml`, but they must be consistent or `pack builder create` will fail. |
0 commit comments