Skip to content

Commit

Permalink
Improve extensions demo by not requiring the builder to be recreated …
Browse files Browse the repository at this point in the history
…after every failed build

The hello-extensions buildpack can be configured through the environment after buildpacks/samples#142 lands

Signed-off-by: Natalie Arellano <narellano@vmware.com>
  • Loading branch information
natalieparellano committed Mar 3, 2023
1 parent d5c2de2 commit 757f6f1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,16 @@ cat $PWD/samples/extensions/tree/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`
### Configure the `hello-extensions` buildpack 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
```

### Re-build the application image
Set the `BP_REQUIRES` build-time environment variable to configure the `hello-extensions` buildpack to require `tree` (review the `./bin/detect` script to see why this works).

<!-- test:exec -->
```
pack build hello-extensions \
--builder localhost:5000/extensions-builder \
--env BP_EXT_DEMO=1 \
--env BP_REQUIRES=tree \
--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 @@ -45,32 +45,16 @@ docker build \
--tag run-image-curl .
```

### Re-create our builder with `hello-extensions` updated to require `curl`
### Configure the `hello-extensions` buildpack 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
```

### Re-build the application image
Set the `BP_REQUIRES` build-time environment variable to configure the `hello-extensions` buildpack to require both `tree` and `curl` (review the `./bin/detect` script to see why this works).

<!-- test:exec -->
```bash
pack build hello-extensions \
--builder localhost:5000/extensions-builder \
--env BP_EXT_DEMO=1 \
--env BP_REQUIRES=tree,curl \
--path $PWD/samples/apps/java-maven \
--pull-policy always \
--network host \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Let's see a build that requires base image extension in order to succeed.
cat $PWD/samples/buildpacks/hello-extensions/bin/detect
```

The buildpack always detects (because its exit code is `0`) but doesn't require any dependencies (as the output build plan is empty).
The buildpack opts-out of the build (exits with non-zero code) unless the `BP_EXT_DEMO` environment variable is set.

If the `BP_EXT_DEMO` environment variable is set, the buildpack detects (exits with code `0`), but doesn't require any dependencies through a build plan unless the `BP_REQUIRES` environment variable is set.

#### build

Expand Down Expand Up @@ -57,6 +59,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

0 comments on commit 757f6f1

Please sign in to comment.