Skip to content

Commit

Permalink
fixup! Simplify caching example in author guide
Browse files Browse the repository at this point in the history
Signed-off-by: Aidan Delaney <[email protected]>
  • Loading branch information
AidanDelaney committed Nov 17, 2023
1 parent 1c48fc5 commit 398e8f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ One of the benefits of buildpacks is they can also populate the app image with m

You can find some of this information using `pack` via its `inspect-image` command. The bill-of-materials information will be available using `pack sbom download`.

<!-- test:exec -->
```bash
pack inspect-image test-node-js-app
```
<!--+- "{{execute}}"+-->
You should see the following:

<!-- test:assert=contains;ignore-lines=... -->
```text
Run Images:
cnbs/sample-base-run:jammy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ default = true
EOL
```

Now when you build your app:
Now when you build your app, the second call will reuse the layer:

<!-- test:exec -->
```text
pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack
pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack
```
<!--+- "{{execute}}"+-->

Expand All @@ -143,7 +144,7 @@ you will see the new caching logic at work during the `BUILDING` phase:
===> BUILDING
...
---> NodeJS Buildpack
---> Reusing NodeJS
-----> Reusing NodeJS
```

Next, let's see how buildpack users may be able to provide configuration to the buildpack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "nod
node_js_url=https://nodejs.org/dist/v${node_js_version}/node-v${node_js_version}-linux-x64.tar.xz
remote_nodejs_version=$(cat "${layersdir}/node-js.toml" 2> /dev/null | yj -t | jq -r .metadata.nodejs_version 2>/dev/null || echo 'NOT FOUND')
if [[ "${node_js_url}" != *"${remote_nodejs_version}"* ]] ; then
echo "-----> Downloading and extracting NodeJS"
echo "-----> Downloading and extracting NodeJS" ${node_js_version}
wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}"
else
echo "-----> Reusing NodeJS"
Expand Down Expand Up @@ -94,11 +94,11 @@ Finally, create a file `node-js-sample-app/.node-js-version` with the following
18.18.1
```

Now when you run:
In the following `pack` invocation we choose to `--clear-cache` so that we explicitly do not re-use cached layers. This helps us demonstrate that the NodeJS runtime layer does not get restored from a cache.

<!-- test:exec -->
```bash
pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack
pack build test-node-js-app --clear-cache --path ./node-js-sample-app --buildpack ./node-js-buildpack
```
<!--+- "{{execute}}"+-->

Expand All @@ -109,7 +109,7 @@ You will notice that version of NodeJS specified in the app's `.node-js-version`
===> BUILDING
...
---> NodeJS Buildpack
---> Downloading and extracting NodeJS 18.18.1
-----> Downloading and extracting NodeJS 18.18.1
```

Next, let's see how buildpacks can store information about the dependencies provided in the output app image for introspection.
Expand Down

0 comments on commit 398e8f7

Please sign in to comment.