Skip to content

Commit

Permalink
Fix content in the 'for-buildpack-authors' directory
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Hayakawa <hhiroshell@gmail.com>
  • Loading branch information
hhiroshell committed May 31, 2024
1 parent 38b95bb commit 8a4c3a5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 48 deletions.
14 changes: 7 additions & 7 deletions content/docs/for-buildpack-authors/concepts/lifecycle-phases.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The lifecycle is a binary responsible for orchestrating buildpacks.

There are five phases to a buildpacks build.

We work through a full example of building a "hello world" NodeJs web application.
We work through a full example of building a "hello world" NodeJS web application.

In the example we run `pack` on the NodeJS application to produce an application image. We assume that we have a NodeJS buildpack, `registry.fake/buildpacks/nodejs:latest`, that is decomposed into buildpacks that help with the build. We expand each of the buildpacks phases to explain the process. Throughout the example we take a production-level view of their operation. For example, our assumed NodeJS buildpack will be described to create different build, cache and launch layers in a manner similar to how a real NodeJS buildpack would operate.

Expand Down Expand Up @@ -84,7 +84,7 @@ We build our application using the default builder and specify to only use the `
<asciinema-player
idle-time-limit="0.5s"
font-size="medium"
poster="data:text/plain,$ pack build example --verbose --buildpack docker://registry.fake/buildpacks/nodejs:latest" src="/images/pack-hello-world-nodejs.cast"></asciinema-player>
poster="data:text/plain,$ pack build registry.fake/example --verbose --buildpack docker://registry.fake/buildpacks/nodejs:latest" src="/images/pack-hello-world-nodejs.cast"></asciinema-player>

Now that we understand the example application we can step through each of the Buildpack phases.

Expand All @@ -100,16 +100,16 @@ At a high-level each layer:
* Build phase - Executes buildpacks (via /bin/build).
* Export phase - Creates an image and caches layers.

We consider each of the buildpacks phases in the context of our invocation of `pack build example --buildpack docker://registry.fake/buildpacks/nodejs:latest`.
We consider each of the buildpacks phases in the context of our invocation of `pack build registry.fake/example --buildpack docker://registry.fake/buildpacks/nodejs:latest`.

### Phase 1: Analyze

The analyze phase checks a registry for previous images called `example`. It resolves the image metadata making it available to the subsequent restore phase. In addition, analyze verifies that we have write access to the registry to create or update the image called `example`.
The analyze phase checks a registry for previous images called `registry.fake/example`. It resolves the image metadata making it available to the subsequent restore phase. In addition, analyze verifies that we have write access to the registry to create or update the image called `registry.fake/example`.

In our case `pack` tells us that there is no previous `example` image. It provides the output.
In our case `pack` tells us that there is no previous `registry.fake/example` image. It provides the output.

```
Previous image with name "example" not found
Previous image with name "registry.fake/example" not found
Analyzing image "98070ee549c522cbc08d15683d134aa0af1817fcdc56f450b07e6b4a7903f9b
0"
```
Expand All @@ -120,7 +120,7 @@ The analyze phase writes to disk the metadata it has found. The metadata is use

The detect phase runs the `detect` binary of each buildpack in the order provided in the buildpack metadata.

The invocation of `pack build example --buildpack docker://registry.fake/buildpacks/nodejs:latest` explicitly defines a buildpack order. The command line invocation includes a single `nodejs` buildpack. In our example the detect phase runs the `detect` binary from each buildpack in the first order group. The `yarn-install` `detect` binary will fail as no yarn lock file is present in our source project. As the `detect` binary of a non-optional buildpack has failed, then detection of the entire build group containing `yarn-install` has failed. The detect phase then proceeds to run the `detect` binary of each buildpack in the second order group. As all non-optional buildpacks in this group have passed the detect phase, all the passing buildpacks are added to the build order.
The invocation of `pack build registry.fake/example --buildpack docker://registry.fake/buildpacks/nodejs:latest` explicitly defines a buildpack order. The command line invocation includes a single `nodejs` buildpack. In our example the detect phase runs the `detect` binary from each buildpack in the first order group. The `yarn-install` `detect` binary will fail as no yarn lock file is present in our source project. As the `detect` binary of a non-optional buildpack has failed, then detection of the entire build group containing `yarn-install` has failed. The detect phase then proceeds to run the `detect` binary of each buildpack in the second order group. As all non-optional buildpacks in this group have passed the detect phase, all the passing buildpacks are added to the build order.

![nodejs order groups](/images/order-groups-detect.svg)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const server = http.createServer((req, res) => {
console.log(`Server running at http://${hostname}:${port}/`)
```

We also create a `package.json` file with the following contents:
We also create a `node-js-sample-app/package.json` file with the following contents:

<!-- test:file=node-js-sample-app/package.json -->
```javascript
Expand Down
86 changes: 46 additions & 40 deletions themes/buildpacks/static/images/pack-hello-world-nodejs.cast
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{"version": 2, "width": 80, "height": 25, "timestamp": 1657723938, "idle_time_limit": 1.0, "env": {"SHELL": "/opt/homebrew/bin/bash", "TERM": "xterm-256color"}}
[0.079559, "o", "Error response from daemon: conflict: unable to remove repository reference \"example\" (must force) - container 0db28c3cd61b is using its referenced image d3bd4a0b0f10\r\n"]
[0.079559, "o", "Error response from daemon: conflict: unable to remove repository reference \"registry.fake/example\" (must force) - container 0db28c3cd61b is using its referenced image d3bd4a0b0f10\r\n"]
[0.084779, "o", "\u001b[H\u001b[2J"]
[0.090209, "o", "\u001b[?1034h$ "]
[0.092132, "o", "\u001b["]
Expand All @@ -10,41 +10,47 @@
[0.656374, "o", " b"]
[0.748559, "o", "ui"]
[0.840975, "o", "ld"]
[0.9381, "o", " e"]
[1.03159, "o", "xam"]
[1.125792, "o", "pl"]
[1.220231, "o", "e "]
[1.31229, "o", "--"]
[1.40592, "o", "ve"]
[1.500738, "o", "rbo"]
[1.594896, "o", "se"]
[1.785162, "o", " -"]
[1.879617, "o", "-b"]
[1.973787, "o", "ui"]
[2.068474, "o", "ldp"]
[2.162632, "o", "ac"]
[2.254715, "o", "k "]
[2.348842, "o", "do"]
[2.443116, "o", "ck"]
[2.536463, "o", "er:"]
[2.629926, "o", "//"]
[2.720655, "o", "re"]
[2.815347, "o", "gi"]
[2.908777, "o", "st"]
[3.003889, "o", "ry"]
[3.097536, "o", ".f"]
[3.286436, "o", "ak"]
[3.379736, "o", "e/"]
[3.940756, "o", "bu"]
[4.034545, "o", "ild"]
[4.129854, "o", "pa"]
[4.223589, "o", "ck"]
[4.314146, "o", "s/"]
[4.407892, "o", "no"]
[4.502507, "o", "dej"]
[4.597216, "o", "s:"]
[4.783788, "o", "la"]
[4.87724, "o", "te"]
[0.939319, "o", " re"]
[1.037663, "o", "gis"]
[1.136007, "o", "tr"]
[1.234351, "o", "y."]
[1.332695, "o", "fa"]
[1.431039, "o", "ke"]
[1.529383, "o", "/e"]
[1.627726, "o", "xam"]
[1.72607, "o", "pl"]
[1.824414, "o", "e "]
[1.922758, "o", "--"]
[2.021102, "o", "ve"]
[2.119446, "o", "rbo"]
[2.21779, "o", "se"]
[2.316134, "o", " -"]
[2.414478, "o", "-b"]
[2.512822, "o", "ui"]
[2.611166, "o", "ldp"]
[2.70951, "o", "ac"]
[2.807854, "o", "k "]
[2.906198, "o", "do"]
[3.004541, "o", "ck"]
[3.102885, "o", "er:"]
[3.201229, "o", "//"]
[3.299573, "o", "re"]
[3.397917, "o", "gi"]
[3.496261, "o", "st"]
[3.594605, "o", "ry"]
[3.692949, "o", ".f"]
[3.791293, "o", "ak"]
[3.889637, "o", "e/"]
[3.987981, "o", "bu"]
[4.086325, "o", "ild"]
[4.184669, "o", "pa"]
[4.283013, "o", "ck"]
[4.381356, "o", "s/"]
[4.4797, "o", "no"]
[4.578044, "o", "dej"]
[4.676388, "o", "s:"]
[4.774732, "o", "la"]
[4.873076, "o", "te"]
[4.97142, "o", "st"]
[5.065215, "o", "\u001b[0"]
[5.159212, "o", "m"]
Expand All @@ -65,7 +71,7 @@
[11.83871, "o", "Adding buildpack \u001b[94mexample/yarn-install@0.0.2\u001b[0m (diffID=sha256:f57bf53c89612c3311160c3ee3269ae2722bf0458e5d931e74753b42e329471d)\r\nAdding buildpack \u001b[94mexample/yarn-start@0.0.3\u001b[0m (diffID=sha256:427c75273cda4a0c50dc6390361aaecd05adf348271ad904d5f7f357ae9bab20)\r\nAdding buildpack \u001b[94mexample/node-engine@0.0.5\u001b[0m (diffID=sha256:89fdef43b493b54a30a2dabd64ff020e11bc96dad55019a22f62975a0be57bdb)\r\nAdding buildpack \u001b[94mexample/npm-install@0.0.2\u001b[0m (diffID=sha256:22f7a9932deefd2182498b844c226f0265af561e61ecf435c1496b61e675842e)\r\nAdding buildpack \u001b[94mexample/npm-start@0.0.2\u001b[0m (diffID=sha256:e3c9a25efa16ace06627a5921a98a2fe6df2090f225542ad20ef71472aa3353d)\r\nAdding buildpack \u001b[94mexample/procfile@0.0.2\u001b[0m (diffID=sha256:6587ae66d2844fb9c1deb10fbb030f66236c2026a723be71aa2673b35aff344e)\r\n"]
[11.838805, "o", "Adding buildpack \u001b[94mexample/nodejs@0.0.4\u001b[0m (diffID=sha256:664944158a8294271850e50f6b6a5e175c70620f3e8c1faa9d7a4f5b12b23ca5)\r\nAdding buildpack \u001b[94mexample/yarn@0.0.3\u001b[0m (diffID=sha256:18d9fcfcbd3ddc5c091c4dc7c0920840db9c64d3a68b7c153f43fb01746e598f)\r\n"]
[14.283132, "o", "Using build cache volume \u001b[94mpack-cache-library_example_latest-f7816b8f3425.build\u001b[0m\r\nRunning the \u001b[94mcreator\u001b[0m on OS \u001b[94mlinux\u001b[0m with:\r\nContainer Settings:\r\n"]
[14.283284, "o", " Args: \u001b[94m/cnb/lifecycle/creator -daemon -launch-cache /launch-cache -log-level debug -app /workspace -cache-dir /cache -run-image cnbs/sample-stack-run:bionic example\u001b[0m\r\n System Envs: \u001b[94mCNB_PLATFORM_API=0.8\u001b[0m\r\n Image: \u001b[94mpack.local/builder/796d69686a7168636a6a:latest\u001b[0m\r\n User: \u001b[94mroot\u001b[0m\r\n Labels: \u001b[94mmap[author:pack]\u001b[0m\r\nHost Settings:\r\n Binds: \u001b[94mpack-cache-library_example_latest-f7816b8f3425.build:/cache /var/run/docker.sock:/var/run/docker.sock pack-cache-library_example_latest-f7816b8f3425.launch:/launch-cache pack-layers-ardrxkmcst:/layers pack-app-ewomqovqzg:/workspace\u001b[0m\r\n Network Mode: \u001b[94m\u001b[0m\r\n"]
[14.283284, "o", " Args: \u001b[94m/cnb/lifecycle/creator -daemon -launch-cache /launch-cache -log-level debug -app /workspace -cache-dir /cache -run-image cnbs/sample-stack-run:bionic registry.fake/example\u001b[0m\r\n System Envs: \u001b[94mCNB_PLATFORM_API=0.8\u001b[0m\r\n Image: \u001b[94mpack.local/builder/796d69686a7168636a6a:latest\u001b[0m\r\n User: \u001b[94mroot\u001b[0m\r\n Labels: \u001b[94mmap[author:pack]\u001b[0m\r\nHost Settings:\r\n Binds: \u001b[94mpack-cache-library_example_latest-f7816b8f3425.build:/cache /var/run/docker.sock:/var/run/docker.sock pack-cache-library_example_latest-f7816b8f3425.launch:/launch-cache pack-layers-ardrxkmcst:/layers pack-app-ewomqovqzg:/workspace\u001b[0m\r\n Network Mode: \u001b[94m\u001b[0m\r\n"]
[14.77181, "o", "\u001b[36m===> ANALYZING\u001b[0m\r\n"]
[14.8345, "o", "Analyzing image \"d3bd4a0b0f104223fdfeff82ed35701bda03507e2f344c946717a460a74b7227\"\r\n"]
[14.835838, "o", "Analyzing image \"98070ee549c522cbc08d15683d134aa0af1817fcdc56f450b07e6b4a7903f9b0\"\r\n"]
Expand Down Expand Up @@ -146,12 +152,12 @@
[19.812886, "o", "Setting CNB_LAYERS_DIR=/layers\r\n"]
[19.813317, "o", "Setting CNB_APP_DIR=/workspace\r\nSetting CNB_PLATFORM_API=0.8\r\nSetting CNB_DEPRECATION_MODE=quiet\r\nPrepending /cnb/process and /cnb/lifecycle to PATH\r\nSetting WORKDIR: '/workspace'\r\n"]
[19.814291, "o", "Setting default process type 'web'\r\nSetting ENTRYPOINT: '/cnb/process/web'\r\n"]
[19.815027, "o", "Saving example...\r\n"]
[25.279734, "o", "*** Images (6591be01b232):\r\n example\r\n\r\n*** Image ID: 6591be01b2325ae61859bd8785b3dad81ff74f93dddf2a0a84f04a3bdf6de555\r\n"]
[19.815027, "o", "Saving registry.fake/example...\r\n"]
[25.279734, "o", "*** Images (6591be01b232):\r\n registry.fake/example\r\n\r\n*** Image ID: 6591be01b2325ae61859bd8785b3dad81ff74f93dddf2a0a84f04a3bdf6de555\r\n"]
[25.282556, "o", "Reading buildpack directory: /layers/example_node-engine\r\nReading buildpack directory item: build.toml\r\nReading buildpack directory item: launch.toml\r\nReading buildpack directory item: node\r\nReading buildpack directory item: node.toml\r\nReusing tarball for layer \"example/node-engine:node\" with SHA: sha256:6ac1a8b14410f49cd70d3d99e417b99babf380fd3125d6558dd1eedc77a64f96\r\nReusing cache layer 'example/node-engine:node'\r\nLayer 'example/node-engine:node' SHA: sha256:6ac1a8b14410f49cd70d3d99e417b99babf380fd3125d6558dd1eedc77a64f96\r\n"]
[25.282701, "o", "Reading buildpack directory: /layers/example_npm-install\r\nReading buildpack directory item: modules\r\nReading buildpack directory item: modules.toml\r\nReading buildpack directory item: npm-cache\r\nReading buildpack directory item: npm-cache.toml\r\n"]
[25.283785, "o", "Reusing tarball for layer \"example/npm-install:modules\" with SHA: sha256:8af63f1830260914c7fb3035a8e3571d827c4794751e78947ed15023bf126a7d\r\nReusing cache layer 'example/npm-install:modules'\r\nLayer 'example/npm-install:modules' SHA: sha256:8af63f1830260914c7fb3035a8e3571d827c4794751e78947ed15023bf126a7d\r\n"]
[25.284453, "o", "Reusing tarball for layer \"example/npm-install:npm-cache\" with SHA: sha256:2722e8ba23077a19d55b5fc7768bde14b735d36049fb3afb26bc46e969fe1344\r\nReusing cache layer 'example/npm-install:npm-cache'\r\nLayer 'example/npm-install:npm-cache' SHA: sha256:2722e8ba23077a19d55b5fc7768bde14b735d36049fb3afb26bc46e969fe1344\r\nReading buildpack directory: /layers/example_npm-start\r\n"]
[25.284678, "o", "Reading buildpack directory item: launch.toml\r\n"]
[25.563929, "o", "Successfully built image \u001b[94mexample\u001b[0m\r\n"]
[25.563929, "o", "Successfully built image \u001b[94mregistry.fake/example\u001b[0m\r\n"]
[25.569356, "o", "\r\n"]

0 comments on commit 8a4c3a5

Please sign in to comment.