Skip to content

Commit

Permalink
Merge pull request #604 from buildpacks/fix/extensions-demo
Browse files Browse the repository at this point in the history
Fix extensions demo now that samples repo has been updated
  • Loading branch information
AidanDelaney committed Aug 9, 2023
2 parents ddfcca0 + 85fc5dd commit b954b2a
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 71 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install pack
uses: buildpacks/github-actions/setup-pack@v5.2.0
with:
pack-version: '0.28.0'
pack-version: '0.30.0-rc1'
- name: Test
run: make test
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ pack inspect-image test-ruby-app
<!--+- "{{execute}}"+-->
You should see the following:

<!-- test:assert=contains -->
<!-- test:assert=contains;ignore-lines=... -->
```text
Run Images:
cnbs/sample-stack-run:jammy
...
Buildpacks:
ID VERSION HOMEPAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ The `pack build` command takes in your Ruby sample app as the `--path` argument

After running the command, you should see that it failed to detect, as the `detect` script is currently written to simply error out.

<!-- test:assert=contains -->
<!-- test:assert=contains;ignore-lines=... -->
```
===> DETECTING
...
err: examples/ruby@0.0.1 (1)
...
ERROR: No buildpack groups passed detection.
ERROR: failed to detect: buildpack(s) failed with err
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ it will download the gems:
<!-- test:assert=contains;ignore-lines=... -->
```text
===> BUILDING
...
---> Ruby Buildpack
---> Downloading and extracting Ruby
---> Installing gems
Expand All @@ -274,6 +275,7 @@ you will see the new caching logic at work during the `BUILDING` phase:
<!-- test:assert=contains;ignore-lines=... -->
```text
===> BUILDING
...
---> Ruby Buildpack
---> Downloading and extracting Ruby
---> Reusing gems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack
You will notice that version of Ruby specified in the app's `.ruby-version` file is downloaded.
<!-- test:assert=contains -->
<!-- test:assert=contains;ignore-lines=... -->
```text
===> BUILDING
...
---> Ruby Buildpack
---> Downloading and extracting Ruby 3.1.0
```
Expand Down
44 changes: 13 additions & 31 deletions content/docs/extension-guide/create-extension/build-dockerfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,34 @@ aliases = [

<!-- test:suite=dockerfiles;weight=4 -->

### Examine `tree` extension
### Examine `vim` extension

#### detect

<!-- test:exec -->
```bash
cat $PWD/samples/extensions/tree/bin/detect
cat $PWD/samples/extensions/vim/bin/detect
```

The extension always detects (because its exit code is `0`) and provides a dependency called `tree` by writing to the build plan.
The extension always detects (because its exit code is `0`) and provides a dependency called `vim` by writing to the build plan.

#### generate

<!-- test:exec -->
```bash
cat $PWD/samples/extensions/tree/bin/generate
cat $PWD/samples/extensions/vim/bin/generate
```

The extension generates a `build.Dockerfile` that installs `tree` on the builder image.

### Re-create our builder with `hello-extensions` updated to require `tree`

Edit `$PWD/samples/buildpacks/hello-extensions/bin/detect` to uncomment the first set of lines that output `[[requires]]` to the build plan:

<!-- test:exec -->
```bash
sed -i "10,11s/#//" $PWD/samples/buildpacks/hello-extensions/bin/detect
```

(On Mac, use `sed -i '' "10,11s/#//" $PWD/samples/buildpacks/hello-extensions/bin/detect`)

Re-create the builder:

<!-- test:exec -->
```
pack builder create localhost:5000/extensions-builder \
--config $PWD/samples/builders/alpine/builder.toml \
--publish
```
The extension generates a `build.Dockerfile` that installs `vim` on the builder image.

### Re-build the application image

<!-- test:exec -->
```
pack build hello-extensions \
--builder localhost:5000/extensions-builder \
--env BP_EXT_DEMO=1 \
--env BP_REQUIRES=vim \
--network host \
--path $PWD/samples/apps/java-maven \
--pull-policy always \
Expand All @@ -66,19 +48,19 @@ You should see:

```
[detector] ======== Results ========
[detector] pass: samples/tree@0.0.1
[detector] pass: samples/vim@0.0.1
[detector] pass: samples/hello-extensions@0.0.1
[detector] Resolving plan... (try #1)
[detector] samples/tree 0.0.1
[detector] samples/vim 0.0.1
[detector] samples/hello-extensions 0.0.1
[detector] Running generate for extension samples/tree@0.0.1
[detector] Running generate for extension samples/vim@0.0.1
...
[extender] Found build Dockerfile for extension 'samples/tree'
[extender] Applying the Dockerfile at /layers/generated/build/samples_tree/Dockerfile...
[extender] Found build Dockerfile for extension 'samples/vim'
[extender] Applying the Dockerfile at /layers/generated/build/samples_vim/Dockerfile...
...
[extender] Running build command
[extender] ---> Hello Extensions Buildpack
[extender] tree v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
[extender] vim v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
...
Successfully built image hello-extensions
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ aliases = [

<!-- test:suite=dockerfiles;weight=3 -->

### Examine `tree` extension
### Examine `vim` extension

<!-- test:exec -->
```bash
tree $PWD/samples/extensions/tree
vim --help
```

(That's right, we're using the very tool we will later be installing!) You should see something akin to the following:
Expand Down Expand Up @@ -44,7 +44,7 @@ tree $PWD/samples/extensions/tree
the [spec](https://github.com/buildpacks/spec/blob/buildpack/main/image_extension.md)
for further details.

We'll take a closer look at the executables for the `tree` extension in the next step.
We'll take a closer look at the executables for the `vim` extension in the next step.

<!--+ if false+-->
---
Expand Down
42 changes: 12 additions & 30 deletions content/docs/extension-guide/create-extension/run-dockerfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,7 @@ Build the run image:
```bash
docker build \
--file $PWD/samples/stacks/alpine/run/curl.Dockerfile \
--tag run-image-curl .
```

### Re-create our builder with `hello-extensions` updated to require `curl`

Edit `$PWD/samples/buildpacks/hello-extensions/bin/detect` to uncomment the second set of lines that output `[[requires]]` to the build plan:

<!-- test:exec -->
```bash
sed -i "14,15s/#//" $PWD/samples/buildpacks/hello-extensions/bin/detect
```

(On Mac, use `sed -i '' "14,15s/#//" $PWD/samples/buildpacks/hello-extensions/bin/detect`)

Re-create the builder:

<!-- test:exec -->
```bash
pack builder create localhost:5000/extensions-builder \
--config $PWD/samples/builders/alpine/builder.toml \
--publish
--tag localhost:5000/run-image-curl .
```

### Re-build the application image
Expand All @@ -74,6 +54,8 @@ pack builder create localhost:5000/extensions-builder \
```bash
pack build hello-extensions \
--builder localhost:5000/extensions-builder \
--env BP_EXT_DEMO=1 \
--env BP_REQUIRES=vim,curl \
--path $PWD/samples/apps/java-maven \
--pull-policy always \
--network host \
Expand All @@ -86,26 +68,26 @@ You should see:

```
[detector] ======== Results ========
[detector] pass: samples/tree@0.0.1
[detector] pass: samples/vim@0.0.1
[detector] pass: samples/curl@0.0.1
[detector] pass: samples/hello-extensions@0.0.1
[detector] Resolving plan... (try #1)
[detector] samples/tree 0.0.1
[detector] samples/vim 0.0.1
[detector] samples/curl 0.0.1
[detector] samples/hello-extensions 0.0.1
[detector] Running generate for extension samples/tree@0.0.1
[detector] Running generate for extension samples/vim@0.0.1
...
[detector] Running generate for extension samples/curl@0.0.1
...
[detector] Checking for new run image
[detector] Found a run.Dockerfile configuring image 'run-image-curl' from extension with id 'samples/curl'
...
[extender] Found build Dockerfile for extension 'samples/tree'
[extender] Applying the Dockerfile at /layers/generated/build/samples_tree/Dockerfile...
[extender] Found build Dockerfile for extension 'samples/vim'
[extender] Applying the Dockerfile at /layers/generated/build/samples_vim/Dockerfile...
...
[extender] Running build command
[extender] ---> Hello Extensions Buildpack
[extender] tree v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
[extender] vim v1.8.0 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro
...
Successfully built image hello-extensions
```
Expand All @@ -123,16 +105,16 @@ You should see something akin to:
curl 7.85.0-DEV (x86_64-pc-linux-musl) ... more stuff here ...
```

What happened: now that `hello-extensions` requires both `tree` and `curl` in its build plan, both extensions are
What happened: now that `hello-extensions` requires both `vim` and `curl` in its build plan, both extensions are
included in the build and provide the needed dependencies for build and launch, respectively
* The `tree` extension installs `tree` at build time, as before
* The `vim` extension installs `vim` at build time, as before
* The `curl` extension switches the run image to `run-image-curl`, which has `curl` installed

Now our `curl` process can succeed!

## What's next?

The `tree` and `curl` examples are very simple, but we can unlock powerful new features with this functionality.
The `vim` and `curl` examples are very simple, but we can unlock powerful new features with this functionality.

Platforms could have several run images available, each tailored to a specific language family, thus limiting the number
of installed dependencies for each image to the minimum necessary to support the targeted language. Image extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Run `pack build` (note that the "source" directory is effectively ignored in our
```
pack build hello-extensions \
--builder localhost:5000/extensions-builder \
--env BP_EXT_DEMO=1 \
--network host \
--path $PWD/samples/apps/java-maven \
--pull-policy always \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ pack inspect-image test-ruby-app
```{{execute}}
You should see the following:
<!-- test:assert=contains -->
<!-- test:assert=contains;ignore-lines=... -->
```text
Run Images:
cnbs/sample-stack-run:jammy
...

Buildpacks:
ID VERSION HOMEPAGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ The `pack build` command takes in your Ruby sample app as the `--path` argument
After running the command, you should see that it failed to detect, as the `detect` script is currently written to simply error out.
<!-- test:assert=contains -->
<!-- test:assert=contains;ignore-lines=... -->
```
===> DETECTING
...
err: examples/ruby@0.0.1 (1)
...
ERROR: No buildpack groups passed detection.
ERROR: failed to detect: buildpack(s) failed with err
```
Expand Down
2 changes: 2 additions & 0 deletions katacoda/scenarios/buildpack-author-guide/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ it will download the gems:
<!-- test:assert=contains;ignore-lines=... -->
```text
===> BUILDING
...
---> Ruby Buildpack
---> Downloading and extracting Ruby
---> Installing gems
Expand All @@ -268,6 +269,7 @@ you will see the new caching logic at work during the `BUILDING` phase:
<!-- test:assert=contains;ignore-lines=... -->
```text
===> BUILDING
...
---> Ruby Buildpack
---> Downloading and extracting Ruby
---> Reusing gems
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ pack build test-ruby-app --path ./ruby-sample-app --buildpack ./ruby-buildpack
You will notice that version of Ruby specified in the app's `.ruby-version` file is downloaded.
<!-- test:assert=contains -->
<!-- test:assert=contains;ignore-lines=... -->
```text
===> BUILDING
...
---> Ruby Buildpack
---> Downloading and extracting Ruby 3.1.0
```
Expand Down

0 comments on commit b954b2a

Please sign in to comment.