Skip to content

Commit 94d095b

Browse files
author
Natalie Arellano
committed
Add ugo tests
Signed-off-by: Natalie Arellano <[email protected]>
1 parent 65f83e5 commit 94d095b

File tree

5 files changed

+148
-62
lines changed

5 files changed

+148
-62
lines changed

content/docs/extension-author-guide/create-extension/build-dockerfile.md

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,59 @@ title="Generating a build.Dockerfile"
33
weight=404
44
+++
55

6+
<!-- test:suite=dockerfiles;weight=4 -->
7+
68
### Examine `tree` extension
79

810
#### detect
911

10-
`cat $workspace/samples/extensions/tree/bin/detect` - the extension always detects (because its exit code is `0`) and provides a dependency
11-
called `tree` by writing to the build plan
12+
<!-- test:exec -->
13+
```bash
14+
cat $workspace/samples/extensions/tree/bin/detect
15+
```
16+
17+
The extension always detects (because its exit code is `0`) and provides a dependency called `tree` by writing to the build plan.
1218

1319
#### generate
1420

15-
`cat $workspace/samples/extensions/tree/bin/generate` - the extension generates a `build.Dockerfile` that installs `tree` on the builder
16-
image
21+
<!-- test:exec -->
22+
```bash
23+
cat $workspace/samples/extensions/tree/bin/generate
24+
```
25+
26+
The extension generates a `build.Dockerfile` that installs `tree` on the builder image.
1727

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

20-
1. Edit `$workspace/samples/buildpacks/hello-extensions/bin/detect` to uncomment the first set of lines that
21-
output `[[requires]]` to the build plan
30+
Edit `$workspace/samples/buildpacks/hello-extensions/bin/detect` to uncomment the first set of lines that output `[[requires]]` to the build plan:
2231

23-
2. Create the builder:
32+
<!-- test:exec -->
33+
```bash
34+
sed -i '' "10,11s/#//" $workspace/samples/buildpacks/hello-extensions/bin/detect
35+
```
36+
37+
Re-create the builder:
2438

39+
<!-- test:exec -->
2540
```
2641
pack builder create $registry_namespace/extensions-builder \
2742
--config $workspace/samples/builders/alpine/builder.toml \
2843
--publish
2944
```
3045

31-
### Build the application image
46+
### Re-build the application image
3247

48+
<!-- test:exec -->
3349
```
3450
pack build hello-extensions \
3551
--builder $registry_namespace/extensions-builder \
36-
--lifecycle-image $LIFECYCLE_IMAGE \
52+
--network host \
53+
--path $workspace/samples/apps/java-maven \
3754
--verbose
3855
```
3956

57+
Note that `--network host` is necessary when using `registry_namespace=localhost:5000`.
58+
4059
You should see:
4160

4261
```
@@ -60,7 +79,9 @@ Successfully built image hello-extensions
6079

6180
### See the image fail to run
6281

63-
`docker run hello-extensions`
82+
```
83+
docker run hello-extensions
84+
```
6485

6586
You should see:
6687

content/docs/extension-author-guide/create-extension/building-blocks-extension.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ title="Building blocks of a CNB Image Extension"
33
weight=403
44
+++
55

6+
<!-- test:suite=dockerfiles;weight=3 -->
7+
68
### Examine `tree` extension
79

8-
`tree $workspace/samples/extensions/tree`
10+
<!-- test:exec -->
11+
```bash
12+
tree $workspace/samples/extensions/tree
13+
```
914

1015
(That's right, we're using the very tool we will later be installing!) You should see something akin to the following:
1116

content/docs/extension-author-guide/create-extension/run-dockerfile.md

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,79 @@ title="Generating a run.Dockerfile"
33
weight=405
44
+++
55

6+
<!-- test:suite=dockerfiles;weight=5 -->
7+
68
### Examine `curl` extension
79

810
#### detect
911

10-
`cat $workspace/samples/extensions/curl/bin/detect` - the extension always detects and provides a dependency
11-
called `curl`
12+
<!-- test:exec -->
13+
```bash
14+
cat $workspace/samples/extensions/curl/bin/detect
15+
```
16+
17+
The extension always detects (because its exit code is `0`) and provides a dependency called `curl`.
1218

1319
#### generate
1420

15-
`cat $workspace/samples/extensions/curl/bin/generate` - the extension generates a `run.Dockerfile` that switches the run image to
16-
reference `run-image-curl`
21+
<!-- test:exec -->
22+
```bash
23+
cat $workspace/samples/extensions/curl/bin/generate
24+
```
25+
26+
The extension generates a `run.Dockerfile` that switches the run image to reference `run-image-curl`.
1727

1828
### Build a run image for `curl` extension to use
1929

20-
1. `cat $workspace/samples/stacks/alpine/run/curl.Dockerfile` - this is a simple Dockerfile that creates a CNB run image
21-
from the `curl` base image by adding the required CNB user configuration and `io.buildpacks.stack.id` label
22-
* The Dockerfile could come from anywhere, but we include it in the `stacks` directory for convenience
30+
<!-- test:exec -->
31+
```bash
32+
cat $workspace/samples/stacks/alpine/run/curl.Dockerfile
33+
```
34+
35+
This is a simple Dockerfile that creates a CNB run image from the `curl` base image by adding the required CNB user configuration and `io.buildpacks.stack.id` label.
2336

24-
2. Build the image:
37+
The Dockerfile could come from anywhere, but we include it in the `stacks` directory for convenience.
2538

26-
```
39+
Build the run image:
40+
41+
<!-- test:exec -->
42+
```bash
2743
docker build \
2844
--file $workspace/samples/stacks/alpine/run/curl.Dockerfile \
2945
--tag run-image-curl .
3046
```
3147

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

34-
1. Edit `$workspace/samples/buildpacks/hello-extensions/bin/detect` to uncomment the second set of lines that
35-
output `[[requires]]` to the build plan
36-
37-
2. Create the builder:
50+
Edit `$workspace/samples/buildpacks/hello-extensions/bin/detect` to uncomment the second set of lines that output `[[requires]]` to the build plan:
3851

52+
<!-- test:exec -->
53+
```bash
54+
sed -i '' "14,15s/#//" $workspace/samples/buildpacks/hello-extensions/bin/detect
3955
```
56+
57+
Re-create the builder:
58+
59+
<!-- test:exec -->
60+
```bash
4061
pack builder create $registry_namespace/extensions-builder \
4162
--config $workspace/samples/builders/alpine/builder.toml \
4263
--publish
4364
```
4465

45-
### Build the application image
66+
### Re-build the application image
4667

47-
```
68+
<!-- test:exec -->
69+
```bash
4870
pack build hello-extensions \
4971
--builder $registry_namespace/extensions-builder \
50-
--lifecycle-image $LIFECYCLE_IMAGE \
72+
--path $workspace/samples/apps/java-maven \
73+
--network host \
5174
--verbose
5275
```
5376

77+
Note that `--network host` is necessary when using `registry_namespace=localhost:5000`.
78+
5479
You should see:
5580

5681
```
@@ -81,7 +106,10 @@ Successfully built image hello-extensions
81106

82107
### See the image run successfully
83108

84-
`docker run hello-extensions`
109+
<!-- test:exec -->
110+
```bash
111+
docker run hello-extensions
112+
```
85113

86114
You should see something akin to:
87115

content/docs/extension-author-guide/create-extension/setup-local-environment.md

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ title="Set up your local environment"
33
weight=401
44
+++
55

6+
<!-- test:suite=dockerfiles;weight=1 -->
7+
68
Let's walk through a build that uses extensions, step by step. We will see an image extension that installs `curl` on
79
the builder image, and switches the run image to an image that has `curl` installed.
810

911
### Ensure Docker is running
1012

11-
`docker version`
13+
<!-- test:exec -->
14+
```bash
15+
docker version
16+
```
1217

1318
If you see output similar to the following, you're good to go! Otherwise, start Docker and check again.
1419

@@ -36,19 +41,35 @@ Server: Docker Engine - Community
3641

3742
### Setup workspace directory
3843

39-
`workspace=<your preferred workspace directory>`
44+
<!-- test:exec -->
45+
```bash
46+
workspace=$PWD # or your preferred workspace directory
47+
```
4048

4149
### Ensure pack version supports image extensions
4250

43-
`pack version` - should be at least `0.28.0`
51+
<!-- test:exec -->
52+
```bash
53+
pack version
54+
```
4455

45-
### Clone the samples repo
56+
The version should be at least `0.28.0`
4657

47-
`cd $workspace`
58+
### Enable experimental features in pack
4859

49-
`git clone https://github.com/buildpacks/samples.git`
60+
<!-- test:exec -->
61+
```bash
62+
pack config experimental true
63+
```
64+
65+
### Clone the samples repo
5066

51-
`cd samples`
67+
<!-- test:exec -->
68+
```bash
69+
cd $workspace
70+
git clone https://github.com/buildpacks/samples.git
71+
cd samples
72+
```
5273

5374
<!--+ if false +-->
5475
---

content/docs/extension-author-guide/create-extension/why-dockerfiles.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,75 @@ title="Why Dockerfiles"
33
weight=402
44
+++
55

6+
<!-- test:suite=dockerfiles;weight=2 -->
7+
68
Let's see a build that requires base image extension in order to succeed.
79

810
### Examine `hello-extensions` buildpack
911

1012
#### detect
1113

12-
`cat $workspace/samples/buildpacks/hello-extensions/bin/detect` - the buildpack always detects (because its exit code is `0`)
13-
but doesn't require any dependencies (as the output build plan is empty)
14+
<!-- test:exec -->
15+
```bash
16+
cat $workspace/samples/buildpacks/hello-extensions/bin/detect
17+
```
18+
19+
The buildpack always detects (because its exit code is `0`) but doesn't require any dependencies (as the output build plan is empty).
1420

1521
#### build
1622

17-
`cat $workspace/samples/buildpacks/hello-extensions/bin/build` - the buildpack tries to use `tree` during the build
18-
phase, and defines a launch process called `curl` that runs `curl --version` at runtime
23+
<!-- test:exec -->
24+
```bash
25+
cat $workspace/samples/buildpacks/hello-extensions/bin/build
26+
```
1927

20-
### Create a builder with extensions and publish it
28+
The buildpack tries to use `tree` at build-time, and defines a launch process called `curl` that runs `curl --version` at runtime.
2129

22-
1. Ensure experimental features are enabled: `pack config experimental true`
30+
### Create a builder with extensions and publish it
2331

24-
2. Download the latest lifecycle tarball from the GitHub [release page](https://github.com/buildpacks/lifecycle/releases/tag/v0.15.1)
25-
* For linux containers on x86 architectures: `wget https://github.com/buildpacks/lifecycle/releases/download/v0.15.1/lifecycle-v0.15.1+linux.x86-64.tgz`
32+
Ensure you are authenticated with an OCI registry: `docker login` should succeed
2633

27-
3. Edit `$workspace/samples/builders/alpine/builder.toml` to add the following at the end of the file:
34+
For test purposes, you can launch a local unauthenticated registry:
2835

29-
```
30-
[lifecycle]
31-
uri = <path to lifecycle tarball in previous step>
36+
<!-- test:exec -->
37+
```bash
38+
docker run -d --rm -p 5000:5000 registry:2
3239
```
3340

34-
4. Ensure you are authenticated with an OCI registry: `docker login` should succeed
41+
Set your preferred registry namespace (typically your username if using Docker Hub): `registry_namespace=<your preferred registry namespace>`
42+
* For now, it is necessary for the builder to be pushed to a registry for builds with image extensions to succeed
3543

36-
5. Set your preferred registry namespace (typically your username): `registry_namespace=<your preferred registry namespace>`
37-
* For now, it is necessary for the builder to be pushed to a registry for builds with image extensions to succeed
38-
39-
6. Create the builder:
44+
If using a test registry:
4045

46+
<!-- test:exec -->
47+
```bash
48+
registry_namespace=localhost:5000
4149
```
50+
51+
Create the builder:
52+
53+
<!-- test:exec -->
54+
```bash
4255
pack builder create $registry_namespace/extensions-builder \
4356
--config $workspace/samples/builders/alpine/builder.toml \
4457
--publish
4558
```
4659

4760
### Build the application image
4861

49-
1. Ensure experimental features are enabled: `pack config experimental true`
50-
51-
2. Set the lifecycle image for `pack` to use in the untrusted builder workflow (as the trusted workflow that uses
52-
the `creator` is not currently supported): `LIFECYCLE_IMAGE=buildpacksio/lifecycle:0.15.1`
53-
54-
3. Build the application image (note that the "source" directory is effectively ignored in our example):
62+
Run `pack build` (note that the "source" directory is effectively ignored in our example):
5563

5664
```
5765
pack build hello-extensions \
5866
--builder $registry_namespace/extensions-builder \
59-
--lifecycle-image $LIFECYCLE_IMAGE \
67+
--network host \
68+
--path $workspace/samples/apps/java-maven \
6069
--pull-policy always \
6170
--verbose
6271
```
6372

73+
Note that `--network host` is necessary when using `registry_namespace=localhost:5000`.
74+
6475
You should see:
6576

6677
```
@@ -81,9 +92,9 @@ You should see:
8192
What happened: our builder doesn't have `tree` installed, so the `hello-extensions` buildpack failed to build (as it
8293
tries to run `tree --version` in its `./bin/build` script).
8394

84-
* Even though there is a `samples/tree` extension that passed detection (`pass: samples/[email protected]`), because
85-
the `hello-extensions` buildpack didn't require `tree` in the build plan, the extension was omitted from the detected
86-
group (`skip: samples/[email protected] provides unused tree`).
95+
Even though there is a `samples/tree` extension that passed detection (`pass: samples/[email protected]`), because
96+
the `hello-extensions` buildpack didn't require `tree` in the build plan, the extension was omitted from the detected
97+
group (`skip: samples/[email protected] provides unused tree`).
8798

8899
Let's take a look at how the `samples/tree` extension installs `tree` on the builder image...
89100

0 commit comments

Comments
 (0)