From 314c19f5d8e2ac01cffcfa9b511e908f506fe93f Mon Sep 17 00:00:00 2001 From: Natalie Arellano Date: Wed, 20 Sep 2023 17:31:04 -0400 Subject: [PATCH 1/7] Clarify and expand on implications of upgrading to Platform API 0.10 Signed-off-by: Natalie Arellano --- .../spec/migration/buildpack-api-0.8-0.9.md | 2 +- .../spec/migration/platform-api-0.9-0.10.md | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/content/docs/reference/spec/migration/buildpack-api-0.8-0.9.md b/content/docs/reference/spec/migration/buildpack-api-0.8-0.9.md index 1f2a68a2d..59fdded88 100644 --- a/content/docs/reference/spec/migration/buildpack-api-0.8-0.9.md +++ b/content/docs/reference/spec/migration/buildpack-api-0.8-0.9.md @@ -22,7 +22,7 @@ Hand-in-hand with shell removal is the introduction of overridable process argum In `launch.toml`, `command` is now a list. The first element in `command` is the command, and all following entries are arguments that are always provided to the process, regardless of how the application is started. The `args` list now designates arguments that can be overridden by the end user - if supported by the platform (Platform API version 0.10 and above). For further details, see the platform [migration guide](/docs/reference/spec/migration/platform-api-0.9-0.10). -For older platforms (Platform API version 0.9 and below), arguments in `args` will be appended to arguments in `command`, negating the new functionality (but preserving compatibility). +For older platforms (Platform API version 0.9 and below), arguments in `command` will be prepended to arguments in `args`, negating the new functionality (but preserving compatibility). ### Image extensions are supported (experimental) diff --git a/content/docs/reference/spec/migration/platform-api-0.9-0.10.md b/content/docs/reference/spec/migration/platform-api-0.9-0.10.md index f652b1f57..cacddcd4c 100644 --- a/content/docs/reference/spec/migration/platform-api-0.9-0.10.md +++ b/content/docs/reference/spec/migration/platform-api-0.9-0.10.md @@ -38,6 +38,18 @@ docker run --entrypoint from-newer-buildpack my-image user-1 user-2 will result in the following command invocation: `some-command always-1 always-2 user-1 user-2`. +#### Implications of upgrading + +For processes from newer buildpacks, upgrading the platform (without changing anything else) will change the command invocation for end-users. + +As an example, the following on Platform API version 0.9: + +``` +docker run --entrypoint from-newer-buildpack my-image user-1 user-2 +``` + +will result in the following command invocation: `some-command always-1 always-2 override-1 override-2 user-1 user-2`, where overridable arguments are treated like regular arguments, and user-provided arguments are always appended. Upgrading the platform will cause `override-1` and `override-2` to be dropped, as shown above. + #### Older buildpacks Process types contributed by older buildpacks (Buildpack API 0.8 and below) do not have overridable process arguments. Looking at metadata.toml: @@ -51,7 +63,7 @@ args = ["always-1", "always-2"] The `command` list will never have more than one element. `always-1` and `always-2` are arguments that are always provided to `some-command`. If no user-provided arguments are specified when the application image is launched, `always-1` and `always-2` will be provided only. If user-provided arguments are specified, these will be **appended** to the `args` list. Example: ``` -docker run --entrypoint from-newer-buildpack my-image +docker run --entrypoint from-older-buildpack my-image ``` will result in the following command invocation: `some-command always-1 always-2`. However: @@ -62,6 +74,10 @@ docker run --entrypoint from-older-buildpack my-image user-1 user-2 will result in the following command invocation: `some-command always-1 always-2 user-1 user-2`. +#### Implications of upgrading + +For processes from older buildpacks, upgrading the platform will not change the command invocation. + ### Image extensions are supported (experimental) Platform 0.10 introduces image extensions as experimental components for customizing build and run-time base images (see [here](/docs/features/dockerfiles) for more information). Image extensions output Dockerfiles which are applied by the lifecycle using [kaniko][https://github.com/GoogleContainerTools/kaniko], a tool for building container images in Kubernetes, as a library. From 3704d51a057060d3a008f60bc1df17fb7a8b961b Mon Sep 17 00:00:00 2001 From: Ram Iyengar Date: Tue, 3 Oct 2023 19:15:52 +0530 Subject: [PATCH 2/7] Update kpack.md about recent kpack donation to CNCF A community member requested this change on Slack. https://cloud-native.slack.com/archives/C05GETJ2NP7/p1696332746643719 Signed-off-by: Ram Iyengar --- content/docs/tools/kpack.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/content/docs/tools/kpack.md b/content/docs/tools/kpack.md index 808163e5b..05a8b09fd 100644 --- a/content/docs/tools/kpack.md +++ b/content/docs/tools/kpack.md @@ -2,7 +2,7 @@ title="kpack" +++ -[kpack][kpack] is a Kubernetes native platform maintained by [VMware][vmware] under the [VMware Tanzu project][vmware-tanzu] that utilizes unprivileged Kubernetes primitives to provide builds of OCI images as a platform implementation of Cloud Native Buildpacks (CNB). +[kpack][kpack] is a Kubernetes native platform, belonging to the Buildpacks [buildpacks] project. It utilizes unprivileged Kubernetes primitives to provide builds of OCI images as a platform implementation of Cloud Native Buildpacks (CNB). ## Use @@ -35,9 +35,12 @@ kpack is also accompanied by a handy CLI utility called [kpack CLI][cli] that le - [kpack GitHub repository][kpack] - [kpack CLI Github repository][cli] - [kpack tutorial][tutorial] +- [kpack Donation announcement] [announcement] [vmware]: https://www.vmware.com/company.html [vmware-tanzu]: https://tanzu.vmware.com/build-service [kpack]: https://github.com/pivotal/kpack [tutorial]: https://github.com/pivotal/kpack/blob/master/docs/tutorial.md -[cli]: https://github.com/vmware-tanzu/kpack-cli/blob/master/docs/kp.md \ No newline at end of file +[cli]: https://github.com/vmware-tanzu/kpack-cli/blob/master/docs/kp.md +[buildpacks]: https://buildpacks.io +[announcement]: https://medium.com/buildpacks/kpack-joins-the-buildpacks-community-organization-223e59bda951 From 5b6419e76e5d6f701ed9ebc5cbce02a0d7a076d1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:14:48 +0000 Subject: [PATCH 3/7] Bump google.golang.org/grpc from 1.55.0 to 1.56.3 in /tools Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.55.0 to 1.56.3. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](https://github.com/grpc/grpc-go/compare/v1.55.0...v1.56.3) --- updated-dependencies: - dependency-name: google.golang.org/grpc dependency-type: indirect ... Signed-off-by: dependabot[bot] --- tools/go.mod | 2 +- tools/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/go.mod b/tools/go.mod index 4f8ef0b80..e0eecc0a9 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -200,7 +200,7 @@ require ( google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect - google.golang.org/grpc v1.55.0 // indirect + google.golang.org/grpc v1.56.3 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/warnings.v0 v0.1.2 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/tools/go.sum b/tools/go.sum index a8238b045..bd3d50774 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -1432,8 +1432,8 @@ google.golang.org/grpc v1.40.0/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9K google.golang.org/grpc v1.40.1/go.mod h1:ogyxbiOoUXAkP+4+xa6PZSE9DZgIHtSpzjDTB9KAK34= google.golang.org/grpc v1.44.0/go.mod h1:k+4IHHFw41K8+bbowsex27ge2rCb65oeWqe4jJ590SU= google.golang.org/grpc v1.45.0/go.mod h1:lN7owxKUQEqMfSyQikvvk5tf/6zMPsrK+ONuO11+0rQ= -google.golang.org/grpc v1.55.0 h1:3Oj82/tFSCeUrRTg/5E/7d/W5A1tj6Ky1ABAuZuv5ag= -google.golang.org/grpc v1.55.0/go.mod h1:iYEXKGkEBhg1PjZQvoYEVPTDkHo1/bjTnfwTeGONTY8= +google.golang.org/grpc v1.56.3 h1:8I4C0Yq1EjstUzUJzpcRVbuYA2mODtEmpWiQoN/b2nc= +google.golang.org/grpc v1.56.3/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= From ce1f1eba226bee724c5f0ba3671490d41f2dc347 Mon Sep 17 00:00:00 2001 From: Aidan Delaney Date: Mon, 16 Oct 2023 06:28:23 +0100 Subject: [PATCH 4/7] Port Buildpack author guide to NodeJS Simplify the buildpack author guide, using NodeJS instead of Ruby. The switch to NodeJS makes multi-arch demos more striaghtforward Signed-off-by: Aidan Delaney --- .../adding-bill-of-materials.md | 142 ++++++----------- .../create-buildpack/build-app.md | 100 +++++------- .../create-buildpack/building-blocks-cnb.md | 27 ++-- .../create-buildpack/caching.md | 148 +++++++++--------- .../create-buildpack/detection.md | 22 +-- .../create-buildpack/make-app-runnable.md | 55 +++---- .../make-buildpack-configurable.md | 90 +++++------ .../setup-local-environment.md | 51 +++--- .../specify-multiple-process-types.md | 76 ++++----- .../adding-bill-of-materials.md | 2 +- tools/go.mod | 33 ++-- tools/go.sum | 69 ++++---- 12 files changed, 362 insertions(+), 453 deletions(-) diff --git a/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md b/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md index b8f4224ac..48a0632f2 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md +++ b/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md @@ -17,7 +17,7 @@ You can find some of this information using `pack` via its `inspect-image` comma ```bash -pack inspect-image test-ruby-app +pack inspect-image test-node-js-app ``` You should see the following: @@ -30,28 +30,27 @@ Run Images: Buildpacks: ID VERSION HOMEPAGE - examples/ruby 0.0.1 - + examples/node-js 0.0.1 - Processes: TYPE SHELL COMMAND ARGS WORK DIR - web (default) bash bundle exec ruby app.rb /workspace - worker bash bundle exec ruby worker.rb /workspace + web (default) bash node-js app.js /workspace ``` -Apart from the above standard metadata, buildpacks can also populate information about the dependencies they have provided in form of a `Bill-of-Materials`. Let's see how we can use this to populate information about the version of `ruby` that was installed in the output app image. +Apart from the above standard metadata, buildpacks can also populate information about the dependencies they have provided in form of a `Bill-of-Materials`. Let's see how we can use this to populate information about the version of `node-js` that was installed in the output app image. -To add the `ruby` version to the output of `pack download sbom`, we will have to provide a [Software `Bill-of-Materials`](https://en.wikipedia.org/wiki/Software_bill_of_materials) (`SBOM`) containing this information. There are three "standard" ways to report SBOM data. You'll need to choose to use one of [CycloneDX](https://cyclonedx.org/), [SPDX](https://spdx.dev/) or [Syft](https://github.com/anchore/syft) update the `ruby.sbom.` (where `` is the extension appropriate for your SBOM standard, one of `cdx.json`, `spdx.json` or `syft.json`) at the end of your `build` script. Discussion of which SBOM format to choose is outside the scope of this tutorial, but we will note that the SBOM format you choose to use is likely to be the output format of any SBOM scanner (eg: [`syft cli`](https://github.com/anchore/syft)) you might choose to use. In this example we will use the CycloneDX json format. +To add the `node-js` version to the output of `pack download sbom`, we will have to provide a [Software `Bill-of-Materials`](https://en.wikipedia.org/wiki/Software_bill_of_materials) (`SBOM`) containing this information. There are three "standard" ways to report SBOM data. You'll need to choose to use one of [CycloneDX](https://cyclonedx.org/), [SPDX](https://spdx.dev/) or [Syft](https://github.com/anchore/syft) update the `node-js.sbom.` (where `` is the extension appropriate for your SBOM standard, one of `cdx.json`, `spdx.json` or `syft.json`) at the end of your `build` script. Discussion of which SBOM format to choose is outside the scope of this tutorial, but we will note that the SBOM format you choose to use is likely to be the output format of any SBOM scanner (eg: [`syft cli`](https://github.com/anchore/syft)) you might choose to use. In this example we will use the CycloneDX json format. First, annotate the `buildpack.toml` to specify that it emits CycloneDX: - + ```toml # Buildpack API version api = "0.8" # Buildpack ID and metadata [buildpack] - id = "examples/ruby" + id = "examples/node-js" version = "0.0.1" sbom-formats = [ "application/vnd.cyclonedx+json" ] @@ -69,8 +68,8 @@ Then, in our buildpack implementation we will generate the necessary SBOM metada ```bash # ... -# Append a Bill-of-Materials containing metadata about the provided ruby version -cat >> "$layersdir/ruby.sbom.cdx.json" << EOL +# Append a Bill-of-Materials containing metadata about the provided node-js version +cat >> "${layersdir}/node-js.sbom.cdx.json" << EOL { "bomFormat": "CycloneDX", "specVersion": "1.4", @@ -78,19 +77,19 @@ cat >> "$layersdir/ruby.sbom.cdx.json" << EOL "components": [ { "type": "library", - "name": "ruby", - "version": "$ruby_version" + "name": "node-js", + "version": "$node-js_version" } ] } EOL ``` -We can also add an SBOM entry for each dependency listed in `Gemfile.lock`. Here we use `jq` to add a new record to the `components` array in `bundler.sbom.cdx.json`: +We can also add an SBOM entry for each dependency listed in `package.json`. Here we use `jq` to add a new record to the `components` array in `bundler.sbom.cdx.json`: ```bash -crubybom="${layersdir}/ruby.sbom.cdx.json" -cat >> ${rubybom} << EOL +cnode-jsbom="${layersdir}/node-js.sbom.cdx.json" +cat >> ${node-jsbom} << EOL { "bomFormat": "CycloneDX", "specVersion": "1.4", @@ -98,98 +97,68 @@ cat >> ${rubybom} << EOL "components": [ { "type": "library", - "name": "ruby", - "version": "$ruby_version" + "name": "node-js", + "version": "$node-js_version" } ] } EOL -if [[ -f Gemfile.lock ]] ; then +if [[ -f package.json ]] ; then for gem in $(gem dep -q | grep ^Gem | sed 's/^Gem //') do version=${gem##*-} name=${gem%-${version}} DEP=$(jq --arg name "${name}" --arg version "${version}" \ '.components[.components| length] |= . + {"type": "library", "name": $name, "version": $version}' \ - "${rubybom}") - echo ${DEP} > "${rubybom}" + "${node-jsbom}") + echo ${DEP} > "${node-jsbom}" done fi ``` -Your `ruby-buildpack/bin/build` script should look like the following: +Your `node-js-buildpack/bin/build` script should look like the following: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # 1. GET ARGS layersdir=$1 plan=$3 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" - -# 3. DOWNLOAD RUBY -ruby_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "ruby") | .metadata.version') -echo "---> Downloading and extracting Ruby $ruby_version" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-$ruby_version.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" - -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" - -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" - -# 6. INSTALL GEMS -# Compares previous Gemfile.lock checksum to the current Gemfile.lock -bundlerlayer="$layersdir/bundler" -local_bundler_checksum=$((sha256sum Gemfile.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "$layersdir/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') -# Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "$layersdir/bundler.toml" - -if [[ -f Gemfile.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then - # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install - echo "---> Reusing gems" - bundle config --local path "$bundlerlayer" >/dev/null - bundle config --local bin "$bundlerlayer/bin" >/dev/null -else - # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems - echo "---> Installing gems" - mkdir -p "$bundlerlayer" - cat >> "$layersdir/bundler.toml" << EOL -[metadata] -checksum = "$local_bundler_checksum" -EOL - bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" +node-js_layer="${layersdir}"/node-js +mkdir -p "${node-js_layer}" -fi +# 3. DOWNLOAD node-js +node-js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') +echo "---> Downloading and extracting NodeJS" +node-js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "$node-js_url" | tar -xxf - -C "${node-js_layer}" + +# 4. MAKE node-js AVAILABLE DURING LAUNCH +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" + +# 5. MAKE node-js AVAILABLE TO THIS SCRIPT +export PATH="${node-js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node-js_layer}/lib" -# 7. SET DEFAULT START COMMAND -cat > "$layersdir/launch.toml" << EOL +# 6. SET DEFAULT START COMMAND +cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "node app.js" default = true - -# our worker process -[[processes]] -type = "worker" -command = "bundle exec ruby worker.rb" EOL # ========== ADDED =========== -# 8. ADD A SBOM -rubybom="${layersdir}/ruby.sbom.cdx.json" -cat >> ${rubybom} << EOL +# 7. ADD A SBOM +node-jsbom="${layersdir}/node-js.sbom.cdx.json" +cat >> ${node-jsbom} << EOL { "bomFormat": "CycloneDX", "specVersion": "1.4", @@ -197,30 +166,19 @@ cat >> ${rubybom} << EOL "components": [ { "type": "library", - "name": "ruby", - "version": "$ruby_version" + "name": "node-js", + "version": "$node-js_version" } ] } EOL -if [[ -f Gemfile.lock ]] ; then - for gem in $(gem dep -q | grep ^Gem | sed 's/^Gem //') - do - version=${gem##*-} - name=${gem%-${version}} - DEP=$(jq --arg name "${name}" --arg version "${version}" \ - '.components[.components| length] |= . + {"type": "library", "name": $name, "version": $version}' \ - "${rubybom}") - echo ${DEP} > "${rubybom}" - done -fi ``` Then rebuild your app using the updated buildpack: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` @@ -228,7 +186,7 @@ Viewing your bill-of-materials requires extracting (or `download`ing) the bill-o ```bash -pack sbom download test-ruby-app +pack sbom download test-node-js-app ``` @@ -236,10 +194,10 @@ The SBOM information is now downloaded to the local file system: ```bash -cat layers/sbom/launch/examples_ruby/ruby/sbom.cdx.json | jq -M +cat layers/sbom/launch/examples_node-js/node-js/sbom.cdx.json | jq -M ``` -You should find that the included `ruby` version is `3.1.0` as expected. +You should find that the included `node-js` version is `3.1.0` as expected. ```text @@ -250,7 +208,7 @@ You should find that the included `ruby` version is `3.1.0` as expected. "components": [ { "type": "library", - "name": "ruby", + "name": "node-js", "version": "3.1.0" }, ... @@ -264,7 +222,7 @@ Congratulations! You’ve created your first configurable Cloud Native Buildpack Now that you've finished your buildpack, how about extending it? Try: -- Caching the downloaded Ruby version +- Caching the downloaded NodeJS version - [Packaging your buildpack for distribution][package-a-buildpack] [package-a-buildpack]: /docs/buildpack-author-guide/package-a-buildpack/ diff --git a/content/docs/buildpack-author-guide/create-buildpack/build-app.md b/content/docs/buildpack-author-guide/create-buildpack/build-app.md index 7f252565b..c1f964694 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/build-app.md +++ b/content/docs/buildpack-author-guide/create-buildpack/build-app.md @@ -7,113 +7,88 @@ weight=404 Now we'll change the build step you created to install application dependencies. This will require updates to the `build` script such that it performs the following steps: -1. Creates a layer for the Ruby runtime -1. Downloads the Ruby runtime and installs it to the layer -1. Installs Bundler (the Ruby dependency manager) -1. Uses Bundler to install dependencies +1. Create a layer for the NodeJS runtime +1. Download the NodeJS runtime and installs it to the layer By doing this, you'll learn how to create arbitrary layers with your buildpack, and how to read the contents of the app in order to perform actions like downloading dependencies. -Let's begin by changing the `ruby-buildpack/bin/build` so that it creates a layer for Ruby. +Let's begin by changing the `node-js-buildpack/bin/build` so that it creates a layer for NodeJS. ### Creating a Layer -A Buildpack layer is represented by a directory inside the [layers directory][layers-dir] provided to our buildpack by the Buildpack execution environment. To create a new layer directory representing the Ruby runtime, change the `build` script to look like this: +A Buildpack layer is represented by a directory inside the [layers directory][layers-dir] provided to our buildpack by the Buildpack execution environment. As defined by the buildpack specification, the layers directory is always passed to the `build` script as the first positional parameter. To create a new layer directory representing the NodeJS runtime, change the `build` script to look like this: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" layersdir=$1 -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" ``` -The `rubylayer` directory is a sub-directory of the directory provided as the first positional argument to the build script (the [layers directory][layers-dir]), and this is where we'll store the Ruby runtime. +The `node_js_layer` directory is a sub-directory of the directory provided as the first positional argument to the build script (the [layers directory][layers-dir]), and this is where we'll store the NodeJS runtime. -Next, we'll download the Ruby runtime and install it into the layer directory. Add the following code to the end of the `build` script: +Next, we'll download the NodeJS runtime and install it into the layer directory. Add the following code to the end of the `build` script: - + ```bash -echo "---> Downloading and extracting Ruby" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-3.1.3.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +echo "---> Downloading and extracting NodeJS" +node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "${node_js_url}" | tar -xJf - -C "${node_js_layer}" ``` -This code uses the `wget` tool to download the Ruby binaries from the given URL, and extracts it to the `rubylayer` directory. +This code uses the `wget` tool to download the NodeJS binaries from the given URL, and extracts it to the `node_js_layer` directory. -The last step in creating a layer is writing a TOML file that contains metadata about the layer. The TOML file's name must match the name of the layer (in this example it's `ruby.toml`). Without this file, the Buildpack lifecycle will ignore the layer directory. For the Ruby layer, we need to ensure it is available in the launch image by setting the `launch` key to `true`. Add the following code to the build script: +The last step in creating a layer is writing a TOML file that contains metadata about the layer. The TOML file's name must match the name of the layer (in this example it's `node-js.toml`). Without this file, the Buildpack lifecycle will ignore the layer directory. For the NodeJS layer, we need to ensure it is available in the launch image by setting the `launch` key to `true`. Add the following code to the build script: - + ```bash -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" -``` - -### Installing Dependencies - -Next, we'll use the Ruby runtime you installed to download the application's dependencies. First, we need to make the Ruby executables available to our script by putting it on the Path. Add the following code to the end of the `build` script: - - -```bash -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" -``` - -Now we can install Bundler, a dependency manager for Ruby, and run the `bundle install` command. Append the following code to the script: - - -```bash -echo "---> Installing gems" -bundle install +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" ``` Now the Buildpack is ready to test. ### Running the Build -Your complete `ruby-buildpack/bin/build` script should look like this: +Your complete `node-js-buildpack/bin/build` script should look like this: - - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # 1. GET ARGS layersdir=$1 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" - -# 3. DOWNLOAD RUBY -echo "---> Downloading and extracting Ruby" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-3.1.3.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" +# 3. DOWNLOAD node-js +echo "---> Downloading and extracting NodeJS" +node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "${node_js_url}" | tar -xJf - -C "${node_js_layer}" -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" +# 4. MAKE node-js AVAILABLE DURING LAUNCH +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" -# 6. INSTALL GEMS -echo "---> Installing gems" -bundle install +# 5. MAKE node-js AVAILABLE TO THIS SCRIPT +export PATH="${node_js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" ``` Build your app again: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` @@ -124,16 +99,15 @@ You will see the following output: ... ===> RESTORING ===> BUILDING ----> Ruby Buildpack ----> Downloading and extracting Ruby ----> Installing gems +---> NodeJS Buildpack +---> Downloading and extracting NodeJS ... ===> EXPORTING ... -Successfully built image 'test-ruby-app' +Successfully built image 'test-node-js-app' ``` -A new image named `test-ruby-app` was created in your Docker daemon with a layer containing the Ruby runtime. However, your app image is not yet runnable. We'll make the app image runnable in the next section. +A new image named `test-node-js-app` was created in your Docker daemon with a layer containing the NodeJS runtime. However, your app image is not yet runnable. We'll make the app image runnable in the next section. --- diff --git a/content/docs/buildpack-author-guide/create-buildpack/building-blocks-cnb.md b/content/docs/buildpack-author-guide/create-buildpack/building-blocks-cnb.md index 29f28d64a..5ad6beb20 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/building-blocks-cnb.md +++ b/content/docs/buildpack-author-guide/create-buildpack/building-blocks-cnb.md @@ -16,14 +16,14 @@ The `buildpack new ` command will create a directory named for the buildpack Example: ```bash -pack buildpack new examples/ruby \ +pack buildpack new examples/node-js \ --api 0.8 \ - --path ruby-buildpack \ + --path node-js-buildpack \ --version 0.0.1 \ --stacks io.buildpacks.samples.stacks.jammy ``` -This command will create `ruby-buildpack` directory which contains `buildpack.toml`, `bin/build`, `bin/detect` files. +This command will create `node-js-buildpack` directory which contains `buildpack.toml`, `bin/build`, `bin/detect` files. ### Additional Parameters - `-a, --api` Buildpack API compatibility of the generated buildpack @@ -33,19 +33,18 @@ This command will create `ruby-buildpack` directory which contains `buildpack.to - `-V, --version` the version of the buildpack in buildpack.toml - ### buildpack.toml -You will have `ruby-buildpack/buildpack.toml` in your buildpack directory to describe our buildpack. +You will have `node-js-buildpack/buildpack.toml` in your buildpack directory to describe our buildpack. - + ```toml # Buildpack API version api = "0.8" # Buildpack ID and metadata [buildpack] - id = "examples/ruby" + id = "examples/node-js" version = "0.0.1" # Targets the buildpack will work with @@ -67,9 +66,9 @@ The stack ID (deprecated) uniquely identifies a build and run image configuratio Next, we will cover the `detect` and `build` scripts. These files are created in `bin` directory in your buildpack directory. -Now update your `ruby-buildpack/bin/detect` file and copy in the following contents: +Now update your `node-js-buildpack/bin/detect` file and copy in the following contents: - + ```bash #!/usr/bin/env bash set -eo pipefail @@ -77,14 +76,14 @@ set -eo pipefail exit 1 ``` -Also update your `ruby-buildpack/bin/build` file and copy in the following contents: +Also update your `node-js-buildpack/bin/build` file and copy in the following contents: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" exit 1 ``` @@ -114,7 +113,7 @@ Then run the following `pack` command: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` @@ -126,7 +125,7 @@ After running the command, you should see that it failed to detect, as the `dete ``` ===> DETECTING ... -err: examples/ruby@0.0.1 (1) +err: examples/node-js@0.0.1 (1) ... ERROR: No buildpack groups passed detection. ERROR: failed to detect: buildpack(s) failed with err diff --git a/content/docs/buildpack-author-guide/create-buildpack/caching.md b/content/docs/buildpack-author-guide/create-buildpack/caching.md index 0810188fd..4016d640a 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/caching.md +++ b/content/docs/buildpack-author-guide/create-buildpack/caching.md @@ -5,76 +5,72 @@ weight=407 -We can improve performance by caching dependencies between builds, only re-downloading when necessary. To begin, let's create a cacheable `bundler` layer. +We can improve performance by caching the runtime between builds, only re-downloading when necessary. To begin, let's cache the runtime layer. -## Creating the `bundler` layer +## Cache the runtime layer To do this, replace the following lines in the `build` script: ```bash -echo "---> Installing gems" -bundle install +# 4. MAKE node-js AVAILABLE DURING LAUNCH +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" ``` with the following: ```bash -echo "---> Installing gems" -bundlerlayer="$layersdir/bundler" -mkdir -p "$bundlerlayer" -echo -e '[types]\ncache = true\nlaunch = true' > "$layersdir/bundler.toml" -bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" - +# 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE it +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" ``` -Your full `ruby-buildpack/bin/build` script should now look like the following: +Your full `node-js-buildpack/bin/build` script should now look like the following: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # 1. GET ARGS layersdir=$1 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" # 3. DOWNLOAD RUBY -echo "---> Downloading and extracting Ruby" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-3.1.3.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +echo "---> Downloading and extracting NodeJS" +node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" # 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" # 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" +export PATH="${node_js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" # ======= MODIFIED ======= # 6. INSTALL GEMS echo "---> Installing gems" -bundlerlayer="$layersdir/bundler" -mkdir -p "$bundlerlayer" -echo -e '[types]\ncache = true\nlaunch = true' > "$layersdir/bundler.toml" -bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" +runtimelayer="${layersdir}/bundler" +mkdir -p "${runtimelayer}" +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/bundler.toml" +bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" # 7. SET DEFAULT START COMMAND -cat > "$layersdir/launch.toml" << EOL +cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "bundle exec node-js app.rb" default = true # our worker process [[processes]] type = "worker" -command = "bundle exec ruby worker.rb" +command = "bundle exec node-js worker.rb" EOL ``` @@ -82,7 +78,7 @@ Now when we run: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` @@ -90,20 +86,20 @@ You will see something similar to the following during the `EXPORTING` phase: ```text -Adding layer 'examples/ruby:bundler' +Adding layer 'examples/node-js:bundler' ``` ## Caching dependencies -Now, let's implement the caching logic. We'll first need to create a `ruby-sample-app/Gemfile.lock` file with the contents given below: +Now, let's implement the caching logic. We'll first need to create a `node-js-sample-app/Gemfile.lock` file with the contents given below: > Typically you would run `bundle install` locally to generate this file, but for the sake -> of simplicity we'll create `ruby-sample-app/Gemfile.lock` manually. +> of simplicity we'll create `node-js-sample-app/Gemfile.lock` manually. - + ```text GEM - remote: https://rubygems.org/ + remote: https://node-jsgems.org/ specs: mustermann (1.0.3) rack (2.0.7) @@ -117,7 +113,7 @@ GEM tilt (2.0.9) PLATFORMS - ruby + node-js DEPENDENCIES sinatra @@ -132,10 +128,10 @@ Replace the gem installation logic from the previous step: # ... echo "---> Installing gems" -bundlerlayer="$layersdir/bundler" -mkdir -p "$bundlerlayer" -echo -e '[types]\ncache = true\nlaunch = true' > "$layersdir/bundler.toml" -bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" +runtimelayer="${layersdir}/bundler" +mkdir -p "${runtimelayer}" +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/bundler.toml" +bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" # ... @@ -145,101 +141,101 @@ with the new logic below that checks to see if any gems have been changed. This We'll now write additional metadata to our `bundler.toml` of the form `cache = true` and `launch = true`. This directs the lifecycle to cache our gems and provide them when launching our application. With `cache = true` the lifecycle can keep existing gems around so that build times are fast, even with minor `Gemfile.lock` changes. -Note that there may be times when you would want to clean the cached layer from the previous build, in which case you should always ensure to remove the contents of the layer before proceeding with the build. In the case below this can be done using a simple `rm -rf "$bundlerlayer"/*` after the `mkdir -p "$bundlerlayer"` command. +Note that there may be times when you would want to clean the cached layer from the previous build, in which case you should always ensure to remove the contents of the layer before proceeding with the build. In the case below this can be done using a simple `rm -rf "${runtimelayer}"/*` after the `mkdir -p "${runtimelayer}"` command. ```bash # Compares previous Gemfile.lock checksum to the current Gemfile.lock -bundlerlayer="$layersdir/bundler" +runtimelayer="${layersdir}/bundler" local_bundler_checksum=$((sha256sum Gemfile.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "$layersdir/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') +remote_bundler_checksum=$(cat "${layersdir}/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') # Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "$layersdir/bundler.toml" +echo -e '[types]\ncache = true\nlaunch = true' >> "${layersdir}/bundler.toml" if [[ -f Gemfile.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install echo "---> Reusing gems" - bundle config --local path "$bundlerlayer" >/dev/null - bundle config --local bin "$bundlerlayer/bin" >/dev/null + bundle config --local path "${runtimelayer}" >/dev/null + bundle config --local bin "${runtimelayer}/bin" >/dev/null else # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems echo "---> Installing gems" - mkdir -p "$bundlerlayer" - cat >> "$layersdir/bundler.toml" << EOL + mkdir -p "${runtimelayer}" + cat >> "${layersdir}/bundler.toml" << EOL [metadata] checksum = "$local_bundler_checksum" EOL - bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" + bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" fi ``` -Your full `ruby-buildpack/bin/build` script will now look like this: +Your full `node-js-buildpack/bin/build` script will now look like this: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # 1. GET ARGS layersdir=$1 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" # 3. DOWNLOAD RUBY -echo "---> Downloading and extracting Ruby" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-3.1.3.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +echo "---> Downloading and extracting NodeJS" +node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" # 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" # 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" +export PATH="${node_js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" # ======= MODIFIED ======= # 6. INSTALL GEMS # Compares previous Gemfile.lock checksum to the current Gemfile.lock -bundlerlayer="$layersdir/bundler" +runtimelayer="${layersdir}/bundler" local_bundler_checksum=$((sha256sum Gemfile.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "$layersdir/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') +remote_bundler_checksum=$(cat "${layersdir}/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') # Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "$layersdir/bundler.toml" +echo -e '[types]\ncache = true\nlaunch = true' >> "${layersdir}/bundler.toml" if [[ -f Gemfile.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install echo "---> Reusing gems" - bundle config --local path "$bundlerlayer" >/dev/null - bundle config --local bin "$bundlerlayer/bin" >/dev/null + bundle config --local path "${runtimelayer}" >/dev/null + bundle config --local bin "${runtimelayer}/bin" >/dev/null else # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems echo "---> Installing gems" - mkdir -p "$bundlerlayer" - cat >> "$layersdir/bundler.toml" << EOL + mkdir -p "${runtimelayer}" + cat >> "${layersdir}/bundler.toml" << EOL [metadata] checksum = "$local_bundler_checksum" EOL - bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" + bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" fi # 7. SET DEFAULT START COMMAND -cat > "$layersdir/launch.toml" << EOL +cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "bundle exec node-js app.rb" default = true # our worker process [[processes]] type = "worker" -command = "bundle exec ruby worker.rb" +command = "bundle exec node-js worker.rb" EOL ``` @@ -247,7 +243,7 @@ Now when you build your app: ```text -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` @@ -257,8 +253,8 @@ it will download the gems: ```text ===> BUILDING ... ----> Ruby Buildpack ----> Downloading and extracting Ruby +---> NodeJS Buildpack +---> Downloading and extracting NodeJS ---> Installing gems ``` @@ -266,7 +262,7 @@ If you build the app again: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` @@ -276,8 +272,8 @@ you will see the new caching logic at work during the `BUILDING` phase: ```text ===> BUILDING ... ----> Ruby Buildpack ----> Downloading and extracting Ruby +---> NodeJS Buildpack +---> Downloading and extracting NodeJS ---> Reusing gems ``` diff --git a/content/docs/buildpack-author-guide/create-buildpack/detection.md b/content/docs/buildpack-author-guide/create-buildpack/detection.md index 6534c903c..4098834d0 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/detection.md +++ b/content/docs/buildpack-author-guide/create-buildpack/detection.md @@ -5,50 +5,50 @@ weight=403 -Next, you will want to actually detect that the app you are building is a Ruby app. In order to do this, you will need to check for a `Gemfile`. +Next, you will want to actually detect that the app you are building is a node-js app. In order to do this, you will need to check for a `package.json`. Replace `exit 1` in the `detect` script with the following check: ```bash -if [[ ! -f Gemfile ]]; then +if [[ ! -f package.json ]]; then exit 100 fi ``` -Your `ruby-buildpack/bin/detect` script should look like this: +Your `node-js-buildpack/bin/detect` script should look like this: - + ```bash #!/usr/bin/env bash set -eo pipefail -if [[ ! -f Gemfile ]]; then +if [[ ! -f package.json ]]; then exit 100 fi ``` Next, rebuild your app with the updated buildpack: - + ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` You should see the following output: ``` -Previous image with name "test-ruby-app" not found +Previous image with name "test-node-js-app" not found ===> DETECTING -examples/ruby 0.0.1 +examples/node-js 0.0.1 ===> RESTORING ===> BUILDING ----> Ruby Buildpack +---> node-js Buildpack ERROR: failed to build: exit status 1 ERROR: failed to build: executing lifecycle: failed with status code: 51 ``` -Notice that `detect` now passes because there is a valid `Gemfile` in the Ruby app at `ruby-sample-app`, but now `build` fails because it is currently written to error out. +Notice that `detect` now passes because there is a valid `package.json` in the NodeJS app at `node-js-sample-app`, but now `build` fails because it is currently written to error out. You will also notice that `RESTORING` now appears in the build output. This step is part of the buildpack lifecycle that looks to see if any previous image builds have layers that the buildpack can re-use. We will get into this topic in more detail later. diff --git a/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md b/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md index 5b5f42776..618b75e0f 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md +++ b/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md @@ -7,59 +7,55 @@ weight=405 To make your app runnable, a default start command must be set. You'll need to add the following to the end of your `build` script: - + ```bash # ... # Set default start command -cat > "$layersdir/launch.toml" << EOL +cat > "${layersdir}/launch.toml" << EOL [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "node app.js" default = true EOL # ... ``` -Your full `ruby-buildpack/bin/build` script should now look like the following: +Your full `node-js-buildpack/bin/build` script should now look like the following: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # 1. GET ARGS layersdir=$1 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" -# 3. DOWNLOAD RUBY -echo "---> Downloading and extracting Ruby" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-3.1.3.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +# 3. DOWNLOAD node-js +echo "---> Downloading and extracting NodeJS" +node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" +# 4. MAKE node-js AVAILABLE DURING LAUNCH +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" - -# 6. INSTALL GEMS -echo "---> Installing gems" -bundle install +# 5. MAKE node-js AVAILABLE TO THIS SCRIPT +export PATH="${node_js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" # ========== ADDED =========== -# 7. SET DEFAULT START COMMAND -cat > "$layersdir/launch.toml" << EOL +# 6. SET DEFAULT START COMMAND +cat > "${layersdir}/launch.toml" << EOL [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "node app.js" default = true EOL ``` @@ -68,24 +64,21 @@ Then rebuild your app using the updated buildpack: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` -You should then be able to run your new Ruby app: +You should then be able to run your new NodeJS app: ```bash -docker run --rm -p 8080:8080 test-ruby-app +docker run --rm -p 8080:8080 test-node-js-app ``` and see the server log output: ```text -[2019-04-02 18:04:48] INFO WEBrick 1.4.2 -[2019-04-02 18:04:48] INFO ruby 2.5.1 (2018-03-29) [x86_64-linux] -== Sinatra (v2.0.5) has taken the stage on 8080 for development with backup from WEBrick -[2019-04-02 18:04:48] INFO WEBrick::HTTPServer#start: pid=1 port=8080 +Server running at http://0.0.0.0:8080/ ``` Test it out by navigating to [localhost:8080](http://localhost:8080) in your favorite browser! diff --git a/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md b/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md index 2df46933d..f7f4f1cab 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md +++ b/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md @@ -5,20 +5,20 @@ weight=408 -It's likely that not all Ruby apps will want to use the same version of Ruby. Let's make the Ruby version configurable. +It's likely that not all NodeJS apps will want to use the same version of NodeJS. Let's make the NodeJS version configurable. -## Select Ruby version +## Select NodeJS version -We'll allow buildpack users to define the desired Ruby version via a `.ruby-version` file in their app. We'll first update the `detect` script to check for this file. We will then record the dependency we can `provide` (Ruby), as well as the specific dependency the application will `require`, in the `Build Plan`, a document the lifecycle uses to determine if the buildpack will provide everything the application needs. +We'll allow buildpack users to define the desired NodeJS version via a `.node-js-version` file in their app. We'll first update the `detect` script to check for this file. We will then record the dependency we can `provide` (NodeJS), as well as the specific dependency the application will `require`, in the `Build Plan`, a document the lifecycle uses to determine if the buildpack will provide everything the application needs. -Update `ruby-buildpack/bin/detect` to look like this: +Update `node-js-buildpack/bin/detect` to look like this: - + ```bash #!/usr/bin/env bash set -eo pipefail -if [[ ! -f Gemfile ]]; then +if [[ ! -f package.json ]]; then exit 100 fi @@ -26,25 +26,25 @@ fi plan=$2 version=3.1.3 -if [[ -f .ruby-version ]]; then - version=$(cat .ruby-version | tr -d '[:space:]') +if [[ -f .node-js-version ]]; then + version=$(cat .node-js-version | tr -d '[:space:]') fi -echo "provides = [{ name = \"ruby\" }]" > "$plan" -echo "requires = [{ name = \"ruby\", metadata = { version = \"$version\" } }]" >> "$plan" +echo "provides = [{ name = \"node-js\" }]" > "$plan" +echo "requires = [{ name = \"node-js\", metadata = { version = \"$version\" } }]" >> "$plan" # ======= /ADDED ======= ``` -Then you will need to update your `build` script to look for the recorded Ruby version in the build plan: +Then you will need to update your `build` script to look for the recorded NodeJS version in the build plan: -Your `ruby-buildpack/bin/build` script should look like the following: +Your `node-js-buildpack/bin/build` script should look like the following: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # ======= MODIFIED ======= # 1. GET ARGS @@ -52,32 +52,32 @@ layersdir=$1 plan=$3 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" # ======= MODIFIED ======= -# 3. DOWNLOAD RUBY -ruby_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "ruby") | .metadata.version') -echo "---> Downloading and extracting Ruby $ruby_version" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-$ruby_version.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +# 3. DOWNLOAD node-js +node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') +echo "---> Downloading and extracting NodeJS $node_js_version" +node_js_url=https://nodejs.org/dist/v${node_js_version}/node-v${node_js_version}-linux-x64.tar.xz +wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" +# 4. MAKE node-js AVAILABLE DURING LAUNCH +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" +# 5. MAKE node-js AVAILABLE TO THIS SCRIPT +export PATH="${node_js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" # 6. INSTALL GEMS -# Compares previous Gemfile.lock checksum to the current Gemfile.lock -bundlerlayer="$layersdir/bundler" -local_bundler_checksum=$((sha256sum Gemfile.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "$layersdir/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') +# Compares previous package.json.lock checksum to the current package.json.lock +bundlerlayer="${layersdir}/bundler" +local_bundler_checksum=$((sha256sum package.json.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) +remote_bundler_checksum=$(cat "${layersdir}/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') # Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "$layersdir/bundler.toml" +echo -e '[types]\ncache = true\nlaunch = true' >> "${layersdir}/bundler.toml" -if [[ -f Gemfile.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then +if [[ -f package.json.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install echo "---> Reusing gems" bundle config --local path "$bundlerlayer" >/dev/null @@ -86,7 +86,7 @@ else # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems echo "---> Installing gems" mkdir -p "$bundlerlayer" - cat >> "$layersdir/bundler.toml" << EOL + cat >> "${layersdir}/bundler.toml" << EOL [metadata] checksum = "$local_bundler_checksum" EOL @@ -95,43 +95,43 @@ EOL fi # 7. SET DEFAULT START COMMAND -cat > "$layersdir/launch.toml" << EOL +cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "node app.js" default = true -# our worker process +# our debug process [[processes]] -type = "worker" -command = "bundle exec ruby worker.rb" +type = "debug" +command = "node --inspect app.js" EOL ``` -Finally, create a file `ruby-sample-app/.ruby-version` with the following contents: +Finally, create a file `node-js-sample-app/.node-js-version` with the following contents: - + ``` -3.1.0 +18.18.1 ``` Now when you run: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` -You will notice that version of Ruby specified in the app's `.ruby-version` file is downloaded. +You will notice that version of NodeJS specified in the app's `.node-js-version` file is downloaded. ```text ===> BUILDING ... ----> Ruby Buildpack ----> Downloading and extracting Ruby 3.1.0 +---> NodeJS Buildpack +---> 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. diff --git a/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md b/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md index 391bc9a6a..8cab7bb7d 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md +++ b/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md @@ -8,7 +8,7 @@ weight=401 @@ -16,7 +16,7 @@ pack config trusted-builders add cnbs/sample-builder:jammy @@ -24,34 +24,37 @@ First, we'll create a sample Ruby app that you can use when developing your buil ```bash -mkdir ruby-sample-app +mkdir node-js-sample-app ``` -Create a file in the current directory called `ruby-sample-app/app.rb` with the following contents: - - -```ruby -require 'sinatra' - -set :bind, '0.0.0.0' -set :port, 8080 - -get '/' do - 'Hello World!' -end +Create a file in the current directory called `node-js-sample-app/app.js` with the following contents: + + +```javascript +const http = require('http'); + +const hostname = '0.0.0.0'; +const port = 8080; + +const server = http.createServer((req, res) => { + res.statusCode = 200; + res.setHeader('Content-Type', 'text/plain'); + res.end('Hello World!'); +}); + +server.listen(port, hostname, () => { + console.log(`Server running at http://${hostname}:${port}/`); +}); ``` -Then, create a file called `ruby-sample-app/Gemfile` with the following contents: - - -```ruby -source 'http://rubygems.org' - -git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } +We also create a `package.json` file with the following contents: -gem 'sinatra' -gem 'webrick' + +```javascript +{ + name = "example-application" +} ``` Finally, make sure your local Docker daemon is running by executing: diff --git a/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md b/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md index ca4cec496..d094d0f58 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md +++ b/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md @@ -5,67 +5,56 @@ weight=406 -One of the benefits of buildpacks is that they are multi-process - an image can have multiple entrypoints for each operational mode. Let's see how this works. We will extend our app to have a worker process. +One of the benefits of buildpacks is that they are multi-process - an image can have multiple entrypoints for each operational mode. Let's see how this works. We will extend our app to have an entrypoint that allows a debugger to attach to it. -Let's create a worker file, `ruby-sample-app/worker.rb`, with the following contents: - - -```ruby -for i in 0..5 - puts "Running a worker task..." -end -``` - -After building our app, we could run the resulting image with the `web` process (currently the default) or our new worker process. - -To enable running the worker process, we'll need to have our buildpack define a "process type" for the worker. Modify the section where processes are defined to: +To enable running the debug process, we'll need to have our buildpack define a "process type" for the worker. Modify the section where processes are defined to: ```bash # ... -cat > "$layersdir/launch.toml" << EOL +cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "node app.js" default = true -# our worker process +# our debug process [[processes]] -type = "worker" -command = "bundle exec ruby worker.rb" +type = "debug" +command = "node --inspect app.js" EOL # ... ``` -Your full `ruby-buildpack/bin/build` script should now look like the following: +Your full `node-js-buildpack/bin/build` script should now look like the following: - + ```bash #!/usr/bin/env bash set -eo pipefail -echo "---> Ruby Buildpack" +echo "---> NodeJS Buildpack" # 1. GET ARGS layersdir=$1 # 2. CREATE THE LAYER DIRECTORY -rubylayer="$layersdir"/ruby -mkdir -p "$rubylayer" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" -# 3. DOWNLOAD RUBY -echo "---> Downloading and extracting Ruby" -ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-3.1.3.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +# 3. DOWNLOAD node-js +echo "---> Downloading and extracting NodeJS" +node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz +wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" +# 4. MAKE node-js AVAILABLE DURING LAUNCH +echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="$rubylayer"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"$rubylayer/lib" +# 5. MAKE node-js AVAILABLE TO THIS SCRIPT +export PATH="${node_js_layer}"/bin:$PATH +export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" # 6. INSTALL GEMS echo "---> Installing gems" @@ -73,17 +62,17 @@ bundle install # ========== MODIFIED =========== # 7. SET DEFAULT START COMMAND -cat > "$layersdir/launch.toml" << EOL +cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec ruby app.rb" +command = "node app.js" default = true -# our worker process +# our debug process [[processes]] -type = "worker" -command = "bundle exec ruby worker.rb" +type = "debug" +command = "node --inspect app.js" EOL ``` @@ -91,15 +80,15 @@ Now if you rebuild your app using the updated buildpack: ```bash -pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack +pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack ``` -You should then be able to run your new Ruby worker process: +You should then be able to run your new NodeJS debug process: ```bash -docker run --rm --entrypoint worker test-ruby-app +docker run --rm --entrypoint worker test-node-js-app ``` @@ -107,12 +96,7 @@ and see the worker log output: ```text -Running a worker task... -Running a worker task... -Running a worker task... -Running a worker task... -Running a worker task... -Running a worker task... +Debugger listening on ws://127.0.0.1:9229/ ``` Next, we'll look at how to improve our buildpack by leveraging cache. diff --git a/katacoda/scenarios/buildpack-author-guide/adding-bill-of-materials.md b/katacoda/scenarios/buildpack-author-guide/adding-bill-of-materials.md index 6f17d9dde..63bad20fd 100644 --- a/katacoda/scenarios/buildpack-author-guide/adding-bill-of-materials.md +++ b/katacoda/scenarios/buildpack-author-guide/adding-bill-of-materials.md @@ -133,7 +133,7 @@ mkdir -p "$rubylayer" ruby_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "ruby") | .metadata.version') echo "---> Downloading and extracting Ruby $ruby_version" ruby_url=https://s3-external-1.amazonaws.com/heroku-buildpack-ruby/heroku-22/ruby-$ruby_version.tgz -wget -q -O - "$ruby_url" | tar -xzf - -C "$rubylayer" +wget -q -O - "$ruby_url" | tar -xJf - -C "$rubylayer" # 4. MAKE RUBY AVAILABLE DURING LAUNCH echo -e '[types]\nlaunch = true' > "$layersdir/ruby.toml" diff --git a/tools/go.mod b/tools/go.mod index 2f27bb5e8..fb9f3b863 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -3,7 +3,7 @@ module github.com/buildpacks/docs/tools go 1.20 require ( - github.com/buildpacks/pack v0.30.0 + github.com/buildpacks/pack v0.31.0 github.com/gohugoio/hugo v0.100.2 github.com/spf13/cobra v1.7.0 ) @@ -31,7 +31,7 @@ require ( github.com/BurntSushi/toml v1.3.2 // indirect github.com/Masterminds/semver v1.5.0 // indirect github.com/Microsoft/go-winio v0.6.1 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect @@ -72,7 +72,7 @@ require ( github.com/bep/overlayfs v0.6.0 // indirect github.com/bep/tmc v0.5.1 // indirect github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c // indirect - github.com/buildpacks/lifecycle v0.17.0 // indirect + github.com/buildpacks/lifecycle v0.17.1 // indirect github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect github.com/clbanning/mxj/v2 v2.5.6 // indirect github.com/cli/safeexec v1.0.0 // indirect @@ -81,12 +81,13 @@ require ( github.com/containerd/stargz-snapshotter/estargz v0.14.3 // indirect github.com/containerd/typeurl v1.0.2 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/dimchansky/utfbom v1.1.1 // indirect github.com/disintegration/gift v1.2.1 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect - github.com/docker/cli v24.0.5+incompatible // indirect + github.com/docker/cli v24.0.6+incompatible // indirect github.com/docker/distribution v2.8.2+incompatible // indirect - github.com/docker/docker v24.0.7+incompatible // indirect + github.com/docker/docker v24.0.6+incompatible // indirect github.com/docker/docker-credential-helpers v0.7.0 // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -100,8 +101,8 @@ require ( github.com/getkin/kin-openapi v0.96.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect - github.com/go-git/go-billy/v5 v5.4.1 // indirect - github.com/go-git/go-git/v5 v5.8.1 // indirect + github.com/go-git/go-billy/v5 v5.5.0 // indirect + github.com/go-git/go-git/v5 v5.9.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/swag v0.21.1 // indirect github.com/gobuffalo/flect v0.2.5 // indirect @@ -154,7 +155,7 @@ require ( github.com/niklasfasching/go-org v1.6.5 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/opencontainers/image-spec v1.1.0-rc4 // indirect + github.com/opencontainers/image-spec v1.1.0-rc5 // indirect github.com/opencontainers/runc v1.1.7 // indirect github.com/opencontainers/selinux v1.11.0 // indirect github.com/pelletier/go-toml v1.9.5 // indirect @@ -163,7 +164,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect github.com/rivo/tview v0.0.0-20220610163003-691f46d6f500 // indirect github.com/rivo/uniseg v0.4.3 // indirect - github.com/rogpeppe/go-internal v1.9.0 // indirect + github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/rwcarlsen/goexif v0.0.0-20190401172101-9e8deecbddbd // indirect github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect @@ -184,16 +185,16 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.9.0 // indirect gocloud.dev v0.25.0 // indirect - golang.org/x/crypto v0.14.0 // indirect - golang.org/x/image v0.10.0 // indirect + golang.org/x/crypto v0.13.0 // indirect + golang.org/x/image v0.0.0-20220601225756-64ec528b34cd // indirect golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.17.0 // indirect - golang.org/x/oauth2 v0.11.0 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/oauth2 v0.12.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/term v0.13.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/term v0.12.0 // indirect golang.org/x/text v0.13.0 // indirect - golang.org/x/tools v0.9.3 // indirect + golang.org/x/tools v0.13.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect google.golang.org/api v0.126.0 // indirect google.golang.org/appengine v1.6.7 // indirect diff --git a/tools/go.sum b/tools/go.sum index 50337becf..6c499b526 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -152,8 +152,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= github.com/Microsoft/hcsshim v0.10.0-rc.8 h1:YSZVvlIIDD1UxQpJp0h+dnpLUw+TrY0cx8obKsp3bek= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95 h1:KLq8BE0KwCL+mmXnjLWEAOYO+2l2AE4YMmqG1ZpZHBs= -github.com/ProtonMail/go-crypto v0.0.0-20230717121422-5aa5874ade95/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg= +github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0= github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI= github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M= @@ -295,10 +295,10 @@ github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg= github.com/bep/workers v1.0.0/go.mod h1:7kIESOB86HfR2379pwoMWNy8B50D7r99fRLUyPSNyCs= github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c h1:HlRuSz+JGAzudNtNCfHIzXe0AEuHX6Vx8uZgmjvX02o= github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c/go.mod h1:mBG5M3GJW5nknCEOOqtmMHyPYnSpw/5GEiciuYU/COw= -github.com/buildpacks/lifecycle v0.17.0 h1:vX/kpQfuh4LZvsIhi1wNkx/zahvwiF72bgc46rQ+3z0= -github.com/buildpacks/lifecycle v0.17.0/go.mod h1:WFzcNp1WG4bwgHuXtKxMg4tdU3AguL44ZlP3knANeVs= -github.com/buildpacks/pack v0.30.0 h1:1beK8QAp7By4K40QigYl9JG/Os4nA93dQxYR/GMMbTo= -github.com/buildpacks/pack v0.30.0/go.mod h1:ZtkyUJKcTdWgEDFi0KOmtHQAOkeQeOeJ2wre1+0ipnA= +github.com/buildpacks/lifecycle v0.17.1 h1:sCNj83TH1YE8Z3+CKHoFx/HK+llCVF1RlQUbj3xdNBQ= +github.com/buildpacks/lifecycle v0.17.1/go.mod h1:WFzcNp1WG4bwgHuXtKxMg4tdU3AguL44ZlP3knANeVs= +github.com/buildpacks/pack v0.31.0 h1:rmO1Bwjhmqi7ZYNbDORsqEs5B0VAMiS0lqf/uohHr9Q= +github.com/buildpacks/pack v0.31.0/go.mod h1:y+Y9JCPAKli4I9UBiAB0dcwDfPovUBozbUfz5dqcPIw= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -340,7 +340,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= -github.com/cyphar/filepath-securejoin v0.2.3 h1:YX6ebbZCZP7VkM3scTTokDgBL2TY741X51MTk3ycuNI= +github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= +github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -357,12 +358,12 @@ github.com/djherbis/atime v1.1.0/go.mod h1:28OF6Y8s3NQWwacXc5eZTsEsiMzp7LF8MbXE+ github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= -github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc= -github.com/docker/cli v24.0.5+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/cli v24.0.6+incompatible h1:fF+XCQCgJjjQNIMjzaSmiKJSCcfcXb3TWTcc7GAneOY= +github.com/docker/cli v24.0.6+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= -github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.6+incompatible h1:hceabKCtUgDqPu+qm0NgsaXf28Ljf4/pWFL7xjWWDgE= +github.com/docker/docker v24.0.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -372,7 +373,7 @@ github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDD github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/elazarl/goproxy v0.0.0-20221015165544-a0805db90819 h1:RIB4cRk+lBqKK3Oy0r2gRX4ui7tuhiZq2SuTtTCi0/0= +github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a h1:mATvB/9r/3gvcejNsXKSkQ6lcIaNec2nyfOdlTBR2lU= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -416,11 +417,11 @@ github.com/gin-gonic/gin v1.7.3/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjX github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4= -github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg= +github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= +github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f h1:Pz0DHeFij3XFhoBRGUDPzSJ+w2UcK5/0JvF8DRI58r8= -github.com/go-git/go-git/v5 v5.8.1 h1:Zo79E4p7TRk0xoRgMq0RShiTHGKcKI4+DI6BfJc/Q+A= -github.com/go-git/go-git/v5 v5.8.1/go.mod h1:FHFuoD6yGz5OSKEBK+aWN9Oah0q54Jxl0abmj6GnqAo= +github.com/go-git/go-git/v5 v5.9.0 h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrObY= +github.com/go-git/go-git/v5 v5.9.0/go.mod h1:RKIqga24sWdMGZF+1Ekv9kylsDz6LzdTSI2s/OsZWE0= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -754,8 +755,8 @@ github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1Cpa github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0= -github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= +github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI= +github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= github.com/opencontainers/runc v1.1.7 h1:y2EZDS8sNng4Ksf0GUYNhKbTShZJPJg1FiXJNH/uoCk= github.com/opencontainers/runc v1.1.7/go.mod h1:CbUumNnWCuTGFukNXahoo/RFBZvDAgRh/smNYNOhA50= github.com/opencontainers/selinux v1.11.0 h1:+5Zbo97w3Lbmb3PeqQtpmTkMwsW5nRI3YaLpt7tQ7oU= @@ -785,8 +786,9 @@ github.com/rogpeppe/fastuuid v1.1.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= +github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= +github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= @@ -933,8 +935,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= +golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -948,8 +950,8 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/image v0.10.0 h1:gXjUUtwtx5yOE0VKWq1CH4IJAClq4UGgUA3i+rpON9M= -golang.org/x/image v0.10.0/go.mod h1:jtrku+n79PfroUbvDdeUWMAI+heR786BofxrbiSF+J0= +golang.org/x/image v0.0.0-20220601225756-64ec528b34cd h1:9NbNcTg//wfC5JskFW4Z3sqwVnjmJKHxLAol1bW2qgw= +golang.org/x/image v0.0.0-20220601225756-64ec528b34cd/go.mod h1:doUCurBvlfPMKfmIpRIywoHmhN3VyhnoFDbvIEWF4hY= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1029,8 +1031,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= -golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1051,8 +1053,8 @@ golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= -golang.org/x/oauth2 v0.11.0 h1:vPL4xzxBM4niKCW6g9whtaWVXTJf1U5e4aZxxFx/gbU= -golang.org/x/oauth2 v0.11.0/go.mod h1:LdF7O/8bLR/qWK9DrpXmbHLTouvRHK0SgJl0GmDBchk= +golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= +golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1156,8 +1158,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1166,8 +1168,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= -golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= +golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= +golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1181,7 +1183,6 @@ golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1252,8 +1253,8 @@ golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.9.3 h1:Gn1I8+64MsuTb/HpH+LmQtNas23LhUVr3rYZ0eKuaMM= -golang.org/x/tools v0.9.3/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= +golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 114efac1e729ffbd45dc7bbd87b8813b69f91bb5 Mon Sep 17 00:00:00 2001 From: Aidan Delaney Date: Wed, 15 Nov 2023 10:04:44 +0000 Subject: [PATCH 5/7] Further simplify create-buildpack example Use a "fake" server application. Cache the runtime for use in subsequent builds. Signed-off-by: Aidan Delaney --- .../adding-bill-of-materials.md | 61 +++--- .../create-buildpack/build-app.md | 10 +- .../create-buildpack/caching.md | 198 +++--------------- .../create-buildpack/make-app-runnable.md | 8 +- .../make-buildpack-configurable.md | 56 ++--- .../setup-local-environment.md | 10 +- .../specify-multiple-process-types.md | 16 +- tools/go.mod | 28 +-- tools/go.sum | 60 +++--- 9 files changed, 137 insertions(+), 310 deletions(-) diff --git a/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md b/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md index 48a0632f2..3c4d44c39 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md +++ b/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md @@ -78,7 +78,7 @@ cat >> "${layersdir}/node-js.sbom.cdx.json" << EOL { "type": "library", "name": "node-js", - "version": "$node-js_version" + "version": "${node_js_version}" } ] } @@ -88,7 +88,7 @@ EOL We can also add an SBOM entry for each dependency listed in `package.json`. Here we use `jq` to add a new record to the `components` array in `bundler.sbom.cdx.json`: ```bash -cnode-jsbom="${layersdir}/node-js.sbom.cdx.json" +node-jsbom="${layersdir}/node-js.sbom.cdx.json" cat >> ${node-jsbom} << EOL { "bomFormat": "CycloneDX", @@ -98,22 +98,11 @@ cat >> ${node-jsbom} << EOL { "type": "library", "name": "node-js", - "version": "$node-js_version" + "version": "${node_js_version}" } ] } EOL -if [[ -f package.json ]] ; then - for gem in $(gem dep -q | grep ^Gem | sed 's/^Gem //') - do - version=${gem##*-} - name=${gem%-${version}} - DEP=$(jq --arg name "${name}" --arg version "${version}" \ - '.components[.components| length] |= . + {"type": "library", "name": $name, "version": $version}' \ - "${node-jsbom}") - echo ${DEP} > "${node-jsbom}" - done -fi ``` Your `node-js-buildpack/bin/build` script should look like the following: @@ -125,30 +114,38 @@ set -eo pipefail echo "---> NodeJS Buildpack" +# ======= MODIFIED ======= # 1. GET ARGS layersdir=$1 plan=$3 # 2. CREATE THE LAYER DIRECTORY -node-js_layer="${layersdir}"/node-js -mkdir -p "${node-js_layer}" +node_js_layer="${layersdir}"/node-js +mkdir -p "${node_js_layer}" +# ======= MODIFIED ======= # 3. DOWNLOAD node-js -node-js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') -echo "---> Downloading and extracting NodeJS" -node-js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "$node-js_url" | tar -xxf - -C "${node-js_layer}" - -# 4. MAKE node-js AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" +node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') || "18.18.1" +node_js_url=https://nodejs.org/dist/v18.18.1/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" + node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz + wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" + cat >> "${layersdir}/node-js.toml" << EOL +[metadata] +nodejs-version = "${node_js_version}" +EOL +else + echo "-----> Reusing NodeJS" +fi -# 5. MAKE node-js AVAILABLE TO THIS SCRIPT -export PATH="${node-js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node-js_layer}/lib" +# 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE the LAYER +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" -# 6. SET DEFAULT START COMMAND +# ========== ADDED =========== +# 5. SET DEFAULT START COMMAND cat > "${layersdir}/launch.toml" << EOL -# our web process [[processes]] type = "web" command = "node app.js" @@ -156,7 +153,7 @@ default = true EOL # ========== ADDED =========== -# 7. ADD A SBOM +# 6. ADD A SBOM node-jsbom="${layersdir}/node-js.sbom.cdx.json" cat >> ${node-jsbom} << EOL { @@ -167,7 +164,7 @@ cat >> ${node-jsbom} << EOL { "type": "library", "name": "node-js", - "version": "$node-js_version" + "version": "${node_js_version}" } ] } @@ -197,7 +194,7 @@ The SBOM information is now downloaded to the local file system: cat layers/sbom/launch/examples_node-js/node-js/sbom.cdx.json | jq -M ``` -You should find that the included `node-js` version is `3.1.0` as expected. +You should find that the included `node-js` version is `18.18.1` as expected. ```text @@ -209,7 +206,7 @@ You should find that the included `node-js` version is `3.1.0` as expected. { "type": "library", "name": "node-js", - "version": "3.1.0" + "version": "18.18.1" }, ... ] diff --git a/content/docs/buildpack-author-guide/create-buildpack/build-app.md b/content/docs/buildpack-author-guide/create-buildpack/build-app.md index c1f964694..91e59c670 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/build-app.md +++ b/content/docs/buildpack-author-guide/create-buildpack/build-app.md @@ -39,10 +39,10 @@ Next, we'll download the NodeJS runtime and install it into the layer directory. ```bash echo "---> Downloading and extracting NodeJS" node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "${node_js_url}" | tar -xJf - -C "${node_js_layer}" +wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" ``` -This code uses the `wget` tool to download the NodeJS binaries from the given URL, and extracts it to the `node_js_layer` directory. +This code uses the `wget` tool to download the NodeJS binaries from the given URL, and extracts it to the `node_js_layer` directory. We use `tar` to extract the NodeJS distribution into the `node_js_layer`. During the extraction we remove the top level directory (i.e. `--strip-components 1`). This means that we will end up with `${node_js_layer}/bin` and `${node_js_layer}/lib`. When starting the container the layers `bin` will automatically be added to the runtime `${PATH}`. The last step in creating a layer is writing a TOML file that contains metadata about the layer. The TOML file's name must match the name of the layer (in this example it's `node-js.toml`). Without this file, the Buildpack lifecycle will ignore the layer directory. For the NodeJS layer, we need to ensure it is available in the launch image by setting the `launch` key to `true`. Add the following code to the build script: @@ -74,14 +74,10 @@ mkdir -p "${node_js_layer}" # 3. DOWNLOAD node-js echo "---> Downloading and extracting NodeJS" node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "${node_js_url}" | tar -xJf - -C "${node_js_layer}" +wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" # 4. MAKE node-js AVAILABLE DURING LAUNCH echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" - -# 5. MAKE node-js AVAILABLE TO THIS SCRIPT -export PATH="${node_js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" ``` Build your app again: diff --git a/content/docs/buildpack-author-guide/create-buildpack/caching.md b/content/docs/buildpack-author-guide/create-buildpack/caching.md index 4016d640a..7482c9fe0 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/caching.md +++ b/content/docs/buildpack-author-guide/create-buildpack/caching.md @@ -39,46 +39,36 @@ layersdir=$1 node_js_layer="${layersdir}"/node-js mkdir -p "${node_js_layer}" -# 3. DOWNLOAD RUBY +# 3. DOWNLOAD NodeJS echo "---> Downloading and extracting NodeJS" node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" +wget -q -O - "$node_js_url" | tar -xJf - --strip-components 1 -C "${node_js_layer}" -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" - -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="${node_js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" - -# ======= MODIFIED ======= -# 6. INSTALL GEMS -echo "---> Installing gems" -runtimelayer="${layersdir}/bundler" -mkdir -p "${runtimelayer}" -echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/bundler.toml" -bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" +# 4. MAKE NodeJS AVAILABLE DURING LAUNCH and CACHE the LAYER +# ========== MODIFIED =========== +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" -# 7. SET DEFAULT START COMMAND +# 5. SET DEFAULT START COMMAND cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] type = "web" -command = "bundle exec node-js app.rb" +command = "node app.js" default = true -# our worker process +# our debug process [[processes]] -type = "worker" -command = "bundle exec node-js worker.rb" +type = "debug" +command = "node --inspect app.js" EOL ``` -Now when we run: +Now when we build the image twice we should see the `node-js` layer is reused on the second build: ```bash 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 ``` @@ -86,94 +76,15 @@ You will see something similar to the following during the `EXPORTING` phase: ```text -Adding layer 'examples/node-js:bundler' +Reusing layer 'examples/node-js:node-js' ``` ## Caching dependencies -Now, let's implement the caching logic. We'll first need to create a `node-js-sample-app/Gemfile.lock` file with the contents given below: - -> Typically you would run `bundle install` locally to generate this file, but for the sake -> of simplicity we'll create `node-js-sample-app/Gemfile.lock` manually. - - -```text -GEM - remote: https://node-jsgems.org/ - specs: - mustermann (1.0.3) - rack (2.0.7) - rack-protection (2.0.7) - rack - sinatra (2.0.7) - mustermann (~> 1.0) - rack (~> 2.0) - rack-protection (= 2.0.7) - tilt (~> 2.0) - tilt (2.0.9) - -PLATFORMS - node-js - -DEPENDENCIES - sinatra - -BUNDLED WITH - 2.0.2 -``` - -Replace the gem installation logic from the previous step: - -```bash -# ... - -echo "---> Installing gems" -runtimelayer="${layersdir}/bundler" -mkdir -p "${runtimelayer}" -echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/bundler.toml" -bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" - - -# ... -``` - -with the new logic below that checks to see if any gems have been changed. This simply creates a checksum for the previous `Gemfile.lock` and compares it to the checksum of the current `Gemfile.lock`. If they are the same, the gems are reused. If they are not, the new gems are installed. - -We'll now write additional metadata to our `bundler.toml` of the form `cache = true` and `launch = true`. This directs the lifecycle to cache our gems and provide them when launching our application. With `cache = true` the lifecycle can keep existing gems around so that build times are fast, even with minor `Gemfile.lock` changes. - -Note that there may be times when you would want to clean the cached layer from the previous build, in which case you should always ensure to remove the contents of the layer before proceeding with the build. In the case below this can be done using a simple `rm -rf "${runtimelayer}"/*` after the `mkdir -p "${runtimelayer}"` command. - -```bash -# Compares previous Gemfile.lock checksum to the current Gemfile.lock -runtimelayer="${layersdir}/bundler" -local_bundler_checksum=$((sha256sum Gemfile.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "${layersdir}/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') - -# Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "${layersdir}/bundler.toml" - -if [[ -f Gemfile.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then - # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install - echo "---> Reusing gems" - bundle config --local path "${runtimelayer}" >/dev/null - bundle config --local bin "${runtimelayer}/bin" >/dev/null -else - # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems - echo "---> Installing gems" - mkdir -p "${runtimelayer}" - cat >> "${layersdir}/bundler.toml" << EOL -[metadata] -checksum = "$local_bundler_checksum" -EOL - bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" - -fi -``` - -Your full `node-js-buildpack/bin/build` script will now look like this: +Now, let's implement the caching logic. We need to record the version of the NodeJS runtime that is used in a build. On subsequent builds, the caching logic will detect the current requested NodeJS version and restore the previous layer from the cache if the current requested NodeJS version matches the previous NodeJS runtime version. -```bash +``` #!/usr/bin/env bash set -eo pipefail @@ -186,56 +97,31 @@ layersdir=$1 node_js_layer="${layersdir}"/node-js mkdir -p "${node_js_layer}" -# 3. DOWNLOAD RUBY -echo "---> Downloading and extracting NodeJS" +# 3. DOWNLOAD node-js node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" - -# 4. MAKE RUBY AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" - -# 5. MAKE RUBY AVAILABLE TO THIS SCRIPT -export PATH="${node_js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" - -# ======= MODIFIED ======= -# 6. INSTALL GEMS -# Compares previous Gemfile.lock checksum to the current Gemfile.lock -runtimelayer="${layersdir}/bundler" -local_bundler_checksum=$((sha256sum Gemfile.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "${layersdir}/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') -# Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "${layersdir}/bundler.toml" - -if [[ -f Gemfile.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then - # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install - echo "---> Reusing gems" - bundle config --local path "${runtimelayer}" >/dev/null - bundle config --local bin "${runtimelayer}/bin" >/dev/null -else - # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems - echo "---> Installing gems" - mkdir -p "${runtimelayer}" - cat >> "${layersdir}/bundler.toml" << EOL +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" + node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz + wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" + cat >> "${layersdir}/node-js.toml" << EOL [metadata] -checksum = "$local_bundler_checksum" +nodejs-version = "18.18.1" EOL - bundle config set --local path "${runtimelayer}" && bundle install && bundle binstubs --all --path "${runtimelayer}/bin" - +else + echo "-----> Reusing NodeJS" fi -# 7. SET DEFAULT START COMMAND +# 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE the LAYER +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" + +# ========== ADDED =========== +# 5. SET DEFAULT START COMMAND cat > "${layersdir}/launch.toml" << EOL -# our web process [[processes]] type = "web" -command = "bundle exec node-js app.rb" +command = "node app.js" default = true - -# our worker process -[[processes]] -type = "worker" -command = "bundle exec node-js worker.rb" EOL ``` @@ -247,25 +133,6 @@ pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-bu ``` -it will download the gems: - - -```text -===> BUILDING -... ----> NodeJS Buildpack ----> Downloading and extracting NodeJS ----> Installing gems -``` - -If you build the app again: - - -```bash -pack build test-node-js-app --path ./node-js-sample-app --buildpack ./node-js-buildpack -``` - - you will see the new caching logic at work during the `BUILDING` phase: @@ -273,8 +140,7 @@ you will see the new caching logic at work during the `BUILDING` phase: ===> BUILDING ... ---> NodeJS Buildpack ----> Downloading and extracting NodeJS ----> Reusing gems +---> Reusing node-js ``` Next, let's see how buildpack users may be able to provide configuration to the buildpack. diff --git a/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md b/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md index 618b75e0f..d8592e834 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md +++ b/content/docs/buildpack-author-guide/create-buildpack/make-app-runnable.md @@ -41,17 +41,13 @@ mkdir -p "${node_js_layer}" # 3. DOWNLOAD node-js echo "---> Downloading and extracting NodeJS" node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" +wget -q -O - "$node_js_url" | tar -xJf - --strip-components 1 -C "${node_js_layer}" # 4. MAKE node-js AVAILABLE DURING LAUNCH echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" -# 5. MAKE node-js AVAILABLE TO THIS SCRIPT -export PATH="${node_js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" - # ========== ADDED =========== -# 6. SET DEFAULT START COMMAND +# 5. SET DEFAULT START COMMAND cat > "${layersdir}/launch.toml" << EOL [[processes]] type = "web" diff --git a/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md b/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md index f7f4f1cab..210c8e78e 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md +++ b/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md @@ -57,55 +57,31 @@ mkdir -p "${node_js_layer}" # ======= MODIFIED ======= # 3. DOWNLOAD node-js -node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') -echo "---> Downloading and extracting NodeJS $node_js_version" -node_js_url=https://nodejs.org/dist/v${node_js_version}/node-v${node_js_version}-linux-x64.tar.xz -wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" - -# 4. MAKE node-js AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" - -# 5. MAKE node-js AVAILABLE TO THIS SCRIPT -export PATH="${node_js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" - -# 6. INSTALL GEMS -# Compares previous package.json.lock checksum to the current package.json.lock -bundlerlayer="${layersdir}/bundler" -local_bundler_checksum=$((sha256sum package.json.lock || echo 'DOES_NOT_EXIST') | cut -d ' ' -f 1) -remote_bundler_checksum=$(cat "${layersdir}/bundler.toml" | yj -t | jq -r .metadata.checksum 2>/dev/null || echo 'DOES_NOT_EXIST') -# Always set the types table so that we re-use the appropriate layers -echo -e '[types]\ncache = true\nlaunch = true' >> "${layersdir}/bundler.toml" - -if [[ -f package.json.lock && $local_bundler_checksum == $remote_bundler_checksum ]] ; then - # Determine if no gem dependencies have changed, so it can reuse existing gems without running bundle install - echo "---> Reusing gems" - bundle config --local path "$bundlerlayer" >/dev/null - bundle config --local bin "$bundlerlayer/bin" >/dev/null -else - # Determine if there has been a gem dependency change and install new gems to the bundler layer; re-using existing and un-changed gems - echo "---> Installing gems" - mkdir -p "$bundlerlayer" - cat >> "${layersdir}/bundler.toml" << EOL +node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') || "18.18.1" +node_js_url=https://nodejs.org/dist/v18.18.1/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" + node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz + wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" + cat >> "${layersdir}/node-js.toml" << EOL [metadata] -checksum = "$local_bundler_checksum" +nodejs-version = "${node_js_version}" EOL - bundle config set --local path "$bundlerlayer" && bundle install && bundle binstubs --all --path "$bundlerlayer/bin" - +else + echo "-----> Reusing NodeJS" fi -# 7. SET DEFAULT START COMMAND +# 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE the LAYER +echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" + +# ========== ADDED =========== +# 5. SET DEFAULT START COMMAND cat > "${layersdir}/launch.toml" << EOL -# our web process [[processes]] type = "web" command = "node app.js" default = true - -# our debug process -[[processes]] -type = "debug" -command = "node --inspect app.js" EOL ``` diff --git a/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md b/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md index 8cab7bb7d..9168eaf35 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md +++ b/content/docs/buildpack-author-guide/create-buildpack/setup-local-environment.md @@ -43,9 +43,13 @@ const server = http.createServer((req, res) => { res.end('Hello World!'); }); -server.listen(port, hostname, () => { - console.log(`Server running at http://${hostname}:${port}/`); -}); +// For demo purposes we do not actually start the server. This +// allows us pretend to start the server and check if the output +// message is correct. +//server.listen(port, hostname, () => { +// console.log(`Server running at http://${hostname}:${port}/`); +//}); +console.log(`Server running at http://${hostname}:${port}/`) ``` We also create a `package.json` file with the following contents: diff --git a/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md b/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md index d094d0f58..b284b9076 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md +++ b/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md @@ -47,21 +47,13 @@ mkdir -p "${node_js_layer}" # 3. DOWNLOAD node-js echo "---> Downloading and extracting NodeJS" node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz -wget -q -O - "$node_js_url" | tar -xJf - -C "${node_js_layer}" +wget -q -O - "$node_js_url" | tar -xJf - --strip-components 1 -C "${node_js_layer}" # 4. MAKE node-js AVAILABLE DURING LAUNCH echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" -# 5. MAKE node-js AVAILABLE TO THIS SCRIPT -export PATH="${node_js_layer}"/bin:$PATH -export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+${LD_LIBRARY_PATH}:}"${node_js_layer}/lib" - -# 6. INSTALL GEMS -echo "---> Installing gems" -bundle install - # ========== MODIFIED =========== -# 7. SET DEFAULT START COMMAND +# 5. SET DEFAULT START COMMAND cat > "${layersdir}/launch.toml" << EOL # our web process [[processes]] @@ -88,11 +80,11 @@ You should then be able to run your new NodeJS debug process: ```bash -docker run --rm --entrypoint worker test-node-js-app +docker run --rm --entrypoint debug test-node-js-app ``` -and see the worker log output: +and see the debug log output: ```text diff --git a/tools/go.mod b/tools/go.mod index fb9f3b863..12d20dfe8 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -3,7 +3,7 @@ module github.com/buildpacks/docs/tools go 1.20 require ( - github.com/buildpacks/pack v0.31.0 + github.com/buildpacks/pack v0.32.1 github.com/gohugoio/hugo v0.100.2 github.com/spf13/cobra v1.7.0 ) @@ -71,8 +71,8 @@ require ( github.com/bep/gowebp v0.1.0 // indirect github.com/bep/overlayfs v0.6.0 // indirect github.com/bep/tmc v0.5.1 // indirect - github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c // indirect - github.com/buildpacks/lifecycle v0.17.1 // indirect + github.com/buildpacks/imgutil v0.0.0-20231102131059-84d632186b59 // indirect + github.com/buildpacks/lifecycle v0.17.2 // indirect github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect github.com/clbanning/mxj/v2 v2.5.6 // indirect github.com/cli/safeexec v1.0.0 // indirect @@ -85,9 +85,9 @@ require ( github.com/dimchansky/utfbom v1.1.1 // indirect github.com/disintegration/gift v1.2.1 // indirect github.com/dlclark/regexp2 v1.4.0 // indirect - github.com/docker/cli v24.0.6+incompatible // indirect + github.com/docker/cli v24.0.7+incompatible // indirect github.com/docker/distribution v2.8.2+incompatible // indirect - github.com/docker/docker v24.0.6+incompatible // indirect + github.com/docker/docker v24.0.7+incompatible // indirect github.com/docker/docker-credential-helpers v0.7.0 // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect @@ -102,7 +102,7 @@ require ( github.com/ghodss/yaml v1.0.0 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/go-billy/v5 v5.5.0 // indirect - github.com/go-git/go-git/v5 v5.9.0 // indirect + github.com/go-git/go-git/v5 v5.10.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/swag v0.21.1 // indirect github.com/gobuffalo/flect v0.2.5 // indirect @@ -114,7 +114,7 @@ require ( github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.3 // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-containerregistry v0.16.1 // indirect github.com/google/s2a-go v0.1.4 // indirect github.com/google/uuid v1.3.0 // indirect @@ -185,14 +185,14 @@ require ( go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.9.0 // indirect gocloud.dev v0.25.0 // indirect - golang.org/x/crypto v0.13.0 // indirect + golang.org/x/crypto v0.14.0 // indirect golang.org/x/image v0.0.0-20220601225756-64ec528b34cd // indirect - golang.org/x/mod v0.12.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/oauth2 v0.12.0 // indirect - golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/term v0.12.0 // indirect + golang.org/x/mod v0.13.0 // indirect + golang.org/x/net v0.17.0 // indirect + golang.org/x/oauth2 v0.13.0 // indirect + golang.org/x/sync v0.4.0 // indirect + golang.org/x/sys v0.13.0 // indirect + golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/tools v0.13.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/tools/go.sum b/tools/go.sum index 6c499b526..ee4057f66 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -293,12 +293,12 @@ github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI= github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0= github.com/bep/workers v1.0.0 h1:U+H8YmEaBCEaFZBst7GcRVEoqeRC9dzH2dWOwGmOchg= github.com/bep/workers v1.0.0/go.mod h1:7kIESOB86HfR2379pwoMWNy8B50D7r99fRLUyPSNyCs= -github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c h1:HlRuSz+JGAzudNtNCfHIzXe0AEuHX6Vx8uZgmjvX02o= -github.com/buildpacks/imgutil v0.0.0-20230626185301-726f02e4225c/go.mod h1:mBG5M3GJW5nknCEOOqtmMHyPYnSpw/5GEiciuYU/COw= -github.com/buildpacks/lifecycle v0.17.1 h1:sCNj83TH1YE8Z3+CKHoFx/HK+llCVF1RlQUbj3xdNBQ= -github.com/buildpacks/lifecycle v0.17.1/go.mod h1:WFzcNp1WG4bwgHuXtKxMg4tdU3AguL44ZlP3knANeVs= -github.com/buildpacks/pack v0.31.0 h1:rmO1Bwjhmqi7ZYNbDORsqEs5B0VAMiS0lqf/uohHr9Q= -github.com/buildpacks/pack v0.31.0/go.mod h1:y+Y9JCPAKli4I9UBiAB0dcwDfPovUBozbUfz5dqcPIw= +github.com/buildpacks/imgutil v0.0.0-20231102131059-84d632186b59 h1:5g+dMdOO6Ufx/bDa5gUH/Aw9FN6wt7T3HzKSkHVvue4= +github.com/buildpacks/imgutil v0.0.0-20231102131059-84d632186b59/go.mod h1:PsazEB9yz+NG/cgm0Z1oQ0Xq6rD/U7eNMt5Su41afYY= +github.com/buildpacks/lifecycle v0.17.2 h1:CfJYWHIC5v996idgjDamYHBTk+G+c1Qt7Yk80MlbWpw= +github.com/buildpacks/lifecycle v0.17.2/go.mod h1:h8MrqltqMM+HQnn2F2JOQaKWmeybZ54qvlNV3pAiAqw= +github.com/buildpacks/pack v0.32.1 h1:TlKxevNRR8LAhtBpf8HuR8ODYnGqF0tpAwqojD8xVus= +github.com/buildpacks/pack v0.32.1/go.mod h1:xiyqG2a/wwxkAuSvTr7yCAGWlTjxmZ/HFm6OsAtjyns= github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= @@ -358,12 +358,12 @@ github.com/djherbis/atime v1.1.0/go.mod h1:28OF6Y8s3NQWwacXc5eZTsEsiMzp7LF8MbXE+ github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ= -github.com/docker/cli v24.0.6+incompatible h1:fF+XCQCgJjjQNIMjzaSmiKJSCcfcXb3TWTcc7GAneOY= -github.com/docker/cli v24.0.6+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/cli v24.0.7+incompatible h1:wa/nIwYFW7BVTGa7SWPVyyXU9lgORqUb1xfI36MSkFg= +github.com/docker/cli v24.0.7+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v24.0.6+incompatible h1:hceabKCtUgDqPu+qm0NgsaXf28Ljf4/pWFL7xjWWDgE= -github.com/docker/docker v24.0.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v24.0.7+incompatible h1:Wo6l37AuwP3JaMnZa226lzVXGA3F9Ig1seQen0cKYlM= +github.com/docker/docker v24.0.7+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= github.com/docker/docker-credential-helpers v0.7.0 h1:xtCHsjxogADNZcdv1pKUHXryefjlVRqWqIhk/uXJp0A= github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0= github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= @@ -419,9 +419,9 @@ github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66D github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+mTU= github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow= -github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20230305113008-0c11038e723f h1:Pz0DHeFij3XFhoBRGUDPzSJ+w2UcK5/0JvF8DRI58r8= -github.com/go-git/go-git/v5 v5.9.0 h1:cD9SFA7sHVRdJ7AYck1ZaAa/yeuBvGPxwXDL8cxrObY= -github.com/go-git/go-git/v5 v5.9.0/go.mod h1:RKIqga24sWdMGZF+1Ekv9kylsDz6LzdTSI2s/OsZWE0= +github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= +github.com/go-git/go-git/v5 v5.10.0 h1:F0x3xXrAWmhwtzoCokU4IMPcBdncG+HAAqi9FcOOjbQ= +github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYvhWHvZGhoo= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -520,8 +520,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-containerregistry v0.16.1 h1:rUEt426sR6nyrL3gt+18ibRcvYpKYdpsa5ZW7MA08dQ= github.com/google/go-containerregistry v0.16.1/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= github.com/google/go-replayers/grpcreplay v1.1.0 h1:S5+I3zYyZ+GQz68OfbURDdt/+cSMqCK1wrvNx7WBzTE= @@ -752,7 +752,7 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= -github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= +github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI= @@ -935,8 +935,8 @@ golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -978,8 +978,8 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY= +golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1031,8 +1031,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -1053,8 +1053,8 @@ golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc= -golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4= -golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4= +golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY= +golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -1068,8 +1068,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1158,8 +1158,8 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1168,8 +1168,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= -golang.org/x/term v0.12.0 h1:/ZfYdc3zq+q02Rv9vGqTeSItdzZTSNDmfTi0mBAuidU= -golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= +golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= From 899b0cd7b1e31f855f99a0ba08f3822dee60a806 Mon Sep 17 00:00:00 2001 From: Aidan Delaney Date: Fri, 17 Nov 2023 11:18:49 +0000 Subject: [PATCH 6/7] Simplify caching example in author guide Work out the gremlins in the caching example. We now cache only the layer creating the runtime. Signed-off-by: Aidan Delaney --- .../adding-bill-of-materials.md | 34 ++++++++----------- .../create-buildpack/caching.md | 32 +++++++++-------- .../make-buildpack-configurable.md | 30 ++++++++-------- .../specify-multiple-process-types.md | 5 ++- 4 files changed, 53 insertions(+), 48 deletions(-) diff --git a/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md b/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md index 3c4d44c39..f21aefa89 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md +++ b/content/docs/buildpack-author-guide/create-buildpack/adding-bill-of-materials.md @@ -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`. - ```bash pack inspect-image test-node-js-app ``` - You should see the following: - ```text Run Images: cnbs/sample-base-run:jammy @@ -123,29 +120,29 @@ plan=$3 node_js_layer="${layersdir}"/node-js mkdir -p "${node_js_layer}" -# ======= MODIFIED ======= # 3. DOWNLOAD node-js -node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') || "18.18.1" -node_js_url=https://nodejs.org/dist/v18.18.1/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') +default_node_js_version="18.18.1" +node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version' || echo ${default_node_js_version}) +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" - node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" - cat >> "${layersdir}/node-js.toml" << EOL -[metadata] -nodejs-version = "${node_js_version}" -EOL else echo "-----> Reusing NodeJS" fi # 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE the LAYER -echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" + cat > "${layersdir}/node-js.toml" << EOL +[types] +cache = true +launch = true +[metadata] +nodejs_version = "${node_js_version}" +EOL -# ========== ADDED =========== # 5. SET DEFAULT START COMMAND -cat > "${layersdir}/launch.toml" << EOL +cat >> "${layersdir}/launch.toml" << EOL [[processes]] type = "web" command = "node app.js" @@ -154,8 +151,8 @@ EOL # ========== ADDED =========== # 6. ADD A SBOM -node-jsbom="${layersdir}/node-js.sbom.cdx.json" -cat >> ${node-jsbom} << EOL +node_jsbom="${layersdir}/node-js.sbom.cdx.json" +cat >> ${node_jsbom} << EOL { "bomFormat": "CycloneDX", "specVersion": "1.4", @@ -196,7 +193,6 @@ cat layers/sbom/launch/examples_node-js/node-js/sbom.cdx.json | jq -M You should find that the included `node-js` version is `18.18.1` as expected. - ```text { "bomFormat": "CycloneDX", @@ -207,7 +203,7 @@ You should find that the included `node-js` version is `18.18.1` as expected. "type": "library", "name": "node-js", "version": "18.18.1" - }, + } ... ] } diff --git a/content/docs/buildpack-author-guide/create-buildpack/caching.md b/content/docs/buildpack-author-guide/create-buildpack/caching.md index 7482c9fe0..57e15a6cf 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/caching.md +++ b/content/docs/buildpack-author-guide/create-buildpack/caching.md @@ -81,7 +81,7 @@ Reusing layer 'examples/node-js:node-js' ## Caching dependencies -Now, let's implement the caching logic. We need to record the version of the NodeJS runtime that is used in a build. On subsequent builds, the caching logic will detect the current requested NodeJS version and restore the previous layer from the cache if the current requested NodeJS version matches the previous NodeJS runtime version. +Now, let's implement the caching logic. We need to record the version of the NodeJS runtime that is used in a build. On subsequent builds, the caching logic will detect if the NodeJS version is the same as the version in the cached layer. We restore the previous layer from the cache if the current requested NodeJS version matches the previous NodeJS runtime version. ``` @@ -97,27 +97,30 @@ layersdir=$1 node_js_layer="${layersdir}"/node-js mkdir -p "${node_js_layer}" +# ======= MODIFIED ======= # 3. DOWNLOAD node-js -node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-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 +node_js_version="18.18.1" +node_js_url=https://nodejs.org/dist/v${node_js_version}/node-v${node_js_version}-linux-x64.tar.xz +cached_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}" != *"${cached_nodejs_version}"* ]] ; then echo "-----> Downloading and extracting NodeJS" - node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" - cat >> "${layersdir}/node-js.toml" << EOL -[metadata] -nodejs-version = "18.18.1" -EOL else echo "-----> Reusing NodeJS" fi +# ======= MODIFIED ======= # 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE the LAYER -echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" + cat > "${layersdir}/node-js.toml" << EOL +[types] +cache = true +launch = true +[metadata] +nodejs_version = "${node_js_version}" +EOL -# ========== ADDED =========== # 5. SET DEFAULT START COMMAND -cat > "${layersdir}/launch.toml" << EOL +cat >> "${layersdir}/launch.toml" << EOL [[processes]] type = "web" command = "node app.js" @@ -125,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: ```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 ``` @@ -140,7 +144,7 @@ you will see the new caching logic at work during the `BUILDING` phase: ===> BUILDING ... ---> NodeJS Buildpack ----> Reusing node-js +-----> Reusing NodeJS ``` Next, let's see how buildpack users may be able to provide configuration to the buildpack. diff --git a/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md b/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md index 210c8e78e..81687352c 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md +++ b/content/docs/buildpack-author-guide/create-buildpack/make-buildpack-configurable.md @@ -57,27 +57,29 @@ mkdir -p "${node_js_layer}" # ======= MODIFIED ======= # 3. DOWNLOAD node-js -node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version') || "18.18.1" -node_js_url=https://nodejs.org/dist/v18.18.1/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') +default_node_js_version="18.18.1" +node_js_version=$(cat "$plan" | yj -t | jq -r '.entries[] | select(.name == "node-js") | .metadata.version' || echo ${default_node_js_version}) +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" - node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz + echo "-----> Downloading and extracting NodeJS" ${node_js_version} wget -q -O - "${node_js_url}" | tar -xJf - --strip-components 1 -C "${node_js_layer}" - cat >> "${layersdir}/node-js.toml" << EOL -[metadata] -nodejs-version = "${node_js_version}" -EOL else echo "-----> Reusing NodeJS" fi # 4. MAKE node-js AVAILABLE DURING LAUNCH and CACHE the LAYER -echo -e '[types]\ncache = true\nlaunch = true' > "${layersdir}/node-js.toml" + cat > "${layersdir}/node-js.toml" << EOL +[types] +cache = true +launch = true +[metadata] +nodejs_version = "${node_js_version}" +EOL # ========== ADDED =========== # 5. SET DEFAULT START COMMAND -cat > "${layersdir}/launch.toml" << EOL +cat >> "${layersdir}/launch.toml" << EOL [[processes]] type = "web" command = "node app.js" @@ -92,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. ```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 ``` @@ -107,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. diff --git a/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md b/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md index b284b9076..936b76206 100644 --- a/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md +++ b/content/docs/buildpack-author-guide/create-buildpack/specify-multiple-process-types.md @@ -50,7 +50,10 @@ node_js_url=https://nodejs.org/dist/v18.18.1/node-v18.18.1-linux-x64.tar.xz wget -q -O - "$node_js_url" | tar -xJf - --strip-components 1 -C "${node_js_layer}" # 4. MAKE node-js AVAILABLE DURING LAUNCH -echo -e '[types]\nlaunch = true' > "${layersdir}/node-js.toml" + cat > "${layersdir}/node-js.toml" << EOL +[types] +launch = true +EOL # ========== MODIFIED =========== # 5. SET DEFAULT START COMMAND From b85fb97cad27fc563bcce62f1204d168aed7f54d Mon Sep 17 00:00:00 2001 From: Aidan Delaney Date: Thu, 30 Nov 2023 17:21:48 +0000 Subject: [PATCH 7/7] Update content/docs/tools/kpack.md Co-authored-by: Natalie Arellano Signed-off-by: Aidan Delaney --- content/docs/tools/kpack.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/docs/tools/kpack.md b/content/docs/tools/kpack.md index 05a8b09fd..58622c4c7 100644 --- a/content/docs/tools/kpack.md +++ b/content/docs/tools/kpack.md @@ -2,7 +2,7 @@ title="kpack" +++ -[kpack][kpack] is a Kubernetes native platform, belonging to the Buildpacks [buildpacks] project. It utilizes unprivileged Kubernetes primitives to provide builds of OCI images as a platform implementation of Cloud Native Buildpacks (CNB). +[kpack][kpack] is a Kubernetes native platform, belonging to the [Buildpacks Community](https://github.com/buildpacks-community) organization. It utilizes unprivileged Kubernetes primitives to provide builds of OCI images as a platform implementation of Cloud Native Buildpacks (CNB). ## Use