Skip to content

Commit 37ec8d1

Browse files
committed
Add app dev guide for katacoda
Signed-off-by: Sambhav Kothari <[email protected]>
1 parent d21528e commit 37ec8d1

24 files changed

+883
-98
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,5 @@ katacoda:
170170
.PHONY: check-katacoda
171171
check-katacoda: katacoda
172172
@echo "Checking if Katacoda docs are up-to-date..."
173-
@git diff --quiet HEAD -- katacoda/scenarios || ( echo "Katacoda docs are not up-to-date! Please run 'make katacoda' and commit the katacoda/scenarios folder" && exit 1)
173+
@git diff --quiet HEAD -- katacoda/scenarios || ( echo "Katacoda docs are not up-to-date! Please run 'make katacoda' and commit the katacoda/scenarios folder" && exit 1)
174+
@echo "All katacoda docs are up-to-date"

content/docs/app-developer-guide/build-an-app.md

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ aliases=[
66
"/docs/using-pack/building-app/"
77
]
88
+++
9-
9+
<!--+- if false+-->
1010
<div class="quote mb-4">
1111
{{< summary "docs/concepts/operations/build.md" >}}
1212
<div class="author"><a href="/docs/concepts/operations/build">build</a></div>
1313
</div>
14+
<!--+- end+-->
15+
<!--+- `
16+
# Build an app
17+
`+-->
1418

1519
Building an app using Cloud Native Buildpacks is as easy as `1`, `2`, `3`...
1620

@@ -22,9 +26,10 @@ app.
2226

2327
When using `pack`, you can run `pack builder suggest` for a list of suggested builders.
2428

25-
```bash
29+
```
2630
pack builder suggest
2731
```
32+
<!--+- "{{execute}}"+-->
2833

2934
For this guide we're actually going to use a sample builder, `cnbs/sample-builder:bionic`, which is not listed
3035
as a suggested builder for good reason. It's a sample.
@@ -34,38 +39,62 @@ as a suggested builder for good reason. It's a sample.
3439
Now that you've decided on what builder to use, we can build our app. For this example we'll use our [samples][samples]
3540
repo for simplicity.
3641

37-
```bash
38-
# clone the repo
39-
git clone https://github.com/buildpacks/samples
42+
1. Check that the samples repo exists and if not - we clone it
43+
```
44+
ls samples || git clone https://github.com/buildpacks/samples
45+
```
46+
<!--+- "{{execute}}"+-->
4047

41-
# build the app
48+
2. Build the app
49+
```
4250
pack build sample-app --path samples/apps/java-maven --builder cnbs/sample-builder:bionic
4351
```
52+
<!--+- "{{execute}}"+-->
4453

4554
> **TIP:** If you don't want to keep specifying a builder every time you build, you can set it as your default
46-
> builder by running `pack config default-builder <BUILDER>`.
55+
> builder by running `pack config default-builder <BUILDER>` for example `pack config default-builder cnbs/sample-builder:bionic`
56+
<!--+- "{{execute}}"+-->
4757
4858
### 3. Run it
4959

50-
```bash
60+
```
5161
docker run --rm -p 8080:8080 sample-app
5262
```
63+
<!--+- "{{execute}}"+-->
5364

5465
**Congratulations!**
5566

67+
<!--+- if false+-->
5668
The app should now be running and accessible via [localhost:8080](http://localhost:8080).
69+
<!--+end+-->
70+
71+
<!--+ `
72+
Now open your favorite browser and point it to port "8080" of your host and take a minute to enjoy the view.
73+
74+
On Katacoda you can do this by [clicking here](https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com)
75+
` +-->
5776

5877
## What about ARM apps?
5978

6079
Linux ARM image builds are now supported!
6180

81+
<!--+- if false+-->
6282
<a href="/docs/app-developer-guide/build-an-arm-app" class="button bg-blue">Linux ARM build guide</a>
83+
<!--+end+-->
6384

85+
<!--+ `
86+
Check out the [Linux ARM build guide](https://buildpacks.io//docs/app-developer-guide/build-an-arm-app).
87+
` +-->
6488
## What about Windows apps?
6589

6690
Windows image builds are now supported!
6791

92+
<!--+- if false+-->
6893
<a href="/docs/app-developer-guide/build-a-windows-app" class="button bg-blue">Windows build guide</a>
94+
<!--+end+-->
95+
<!--+ `
96+
Check out the [Windows build guide](https://buildpacks.io/docs/app-developer-guide/build-a-windows-app/).
97+
` +-->
6998

7099
[build]: /docs/concepts/operations/build
71100
[builder]: /docs/concepts/components/builder

content/docs/app-developer-guide/environment-variables.md

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ title="Environment variables"
33
weight=3
44
summary="Environment variables are a common way to configure various buildpacks at build-time."
55
+++
6-
6+
<!--+- `
7+
# Environment variables
8+
`+-->
79
Environment variables are a common way to configure various buildpacks at build-time.
810

911
Below are a few ways you can do so. All of them will use our [samples][samples] repo for simplicity.
@@ -16,25 +18,30 @@ The `--env` parameter must be one of the following:
1618
- `VARIABLE`, where the value of `VARIABLE` will be taken from the local environment
1719

1820
##### Example:
19-
```bash
20-
# clone the repo
21-
git clone https://github.com/buildpacks/samples
2221

23-
# set an environment variable
22+
1. Set an environment variable
23+
```
2424
export FOO=BAR
25+
```
26+
<!--+- "{{execute}}"+-->
2527

26-
# build the app
28+
2. Build the app
29+
```
2730
pack build sample-app \
2831
--env "HELLO=WORLD" \
2932
--env "FOO" \
3033
--builder cnbs/sample-builder:bionic \
3134
--buildpack samples/buildpacks/hello-world/ \
3235
--buildpack samples/apps/bash-script/bash-script-buildpack/ \
3336
--path samples/apps/bash-script/
37+
```
38+
<!--+- "{{execute}}"+-->
3439

35-
# run the app
40+
3. Run the app
41+
```
3642
docker run sample-app
3743
```
44+
<!--+- "{{execute}}"+-->
3845

3946
The following environment variables were set and available to buildpacks at build-time:
4047

@@ -52,27 +59,35 @@ The `--env-file` parameter must be a path to a file where each line is one of th
5259
- `VARIABLE`, where the value of `VARIABLE` will be taken from the current environment
5360

5461
##### Example:
55-
```bash
56-
# clone the repo
57-
git clone https://github.com/buildpacks/samples
5862

59-
# set an environment variable
63+
1. Set an environment variable
64+
```
6065
export FOO=BAR
66+
```
67+
<!--+- "{{execute}}"+-->
6168

62-
# create an env file
69+
2. Create an env file
70+
```
6371
echo -en "HELLO=WORLD\nFOO" > ./envfile
72+
```
73+
<!--+- "{{execute}}"+-->
6474

65-
# build the app
75+
3. Build the app
76+
```
6677
pack build sample-app \
6778
--env-file ./envfile \
6879
--builder cnbs/sample-builder:bionic \
6980
--buildpack samples/buildpacks/hello-world/ \
7081
--buildpack samples/apps/bash-script/bash-script-buildpack/ \
7182
--path samples/apps/bash-script/
83+
```
84+
<!--+- "{{execute}}"+-->
7285

73-
# run the app
86+
4. Run the app
87+
```
7488
docker run sample-app
7589
```
90+
<!--+- "{{execute}}"+-->
7691

7792
The following environment variables were set and available to buildpacks at build-time:
7893

@@ -81,7 +96,7 @@ The following environment variables were set and available to buildpacks at buil
8196
| `HELLO` | `WORLD` | _hard-coded value in file_ |
8297
| `FOO` | `BAR` | _current environment_ |
8398

84-
<p class="spacer"></p>
99+
85100

86101
> **NOTE:** Variables defined using `--env` take precedence over variables defined in `--env-file`.
87102
@@ -91,40 +106,46 @@ Without the `--descriptor` flag, `pack build` will use the `project.toml` file i
91106
You can define environment variables in an `env` table in the file, and pass those into the application.
92107

93108
##### Example:
94-
```bash
95-
# clone the repo
96-
git clone https://github.com/buildpacks/samples
97109

98-
# Add an environment variable to the project.toml
110+
1. Add an environment variable to the project.toml
111+
112+
```
99113
cat >> samples/apps/bash-script/project.toml <<EOL
114+
100115
[[build.env]]
101116
name="HELLO"
102117
value="WORLD"
103118
EOL
119+
```
120+
<!--+- "{{execute}}"+-->
104121

105-
# build the app
122+
2. Build the app
123+
```
106124
pack build sample-app \
107125
--builder cnbs/sample-builder:bionic \
108126
--buildpack samples/buildpacks/hello-world/ \
109127
--buildpack samples/apps/bash-script/bash-script-buildpack/ \
110128
--path samples/apps/bash-script/
129+
```
130+
<!--+- "{{execute}}"+-->
111131

112-
# run the app
132+
3. Run the app
133+
```
113134
docker run sample-app
114135
```
136+
<!--+- "{{execute}}"+-->
115137

116138
The following environment variables were set and available to buildpacks at build-time:
117139

118140
| Name | Value | _Source_ |
119141
|---------|---------|----------------------------|
120142
| `HELLO` | `WORLD` | _hard-coded value in file_ |
121143

122-
<p class="spacer"></p>
123144

124145
> **NOTE:** Variables defined using `--env` or `--env-file` take precedence over variables defined in the `project.toml`.
125146
126147
> **NOTE:** `project.toml` can't detect environment variables (so, for instance, if one ran `export FOO=BAR` and added
127148
>`name=FOO` to the `project.toml`, it wouldn't detect any value set for `FOO`).
128149
129150
[descriptor-schema]: /docs/reference/project-descriptor/
130-
[samples]: https://github.com/buildpacks/samples
151+
[samples]: https://github.com/buildpacks/samples
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
+++
2+
title="Mounting Volumes"
3+
weight=4
4+
summary="Volumes are a mechanism for both supplying and persisting data generated by build containers."
5+
+++
6+
<!--+if false+-->
7+
{{< param "summary" >}}
8+
<!--+end+-->
9+
<!--+- `
10+
# Mounting Volumes
11+
12+
Volumes are a mechanism for both supplying and persisting data generated by build containers.
13+
`+-->
14+
15+
## Mounting Volumes (`--volume`)
16+
17+
The `--volume` parameter must be one of the following:
18+
19+
- A volume mount.
20+
- A comma separated list of volume mounts.
21+
22+
Each volume mount has the following format:
23+
```
24+
<host path>:<target path>[:<mode>]
25+
```
26+
27+
##### `<host path>`
28+
This is the name of the volume, it is unique on a given host machine.
29+
30+
##### `<target path>`
31+
The path where the file or directory is available in the container.
32+
33+
##### `[:<mode>]`
34+
An optional comma separated list of mount options. If no options are provided, the read-only option will be used.
35+
A mount option must be one of the following:
36+
- `ro`, volume contents are read-only.
37+
- `rw`, volume contents are readable and writeable.
38+
- `volume-opt=key=value`, can be specified more than once, takes a key-value pair consisting of the option name and its value.
39+
40+
41+
### Examples
42+
For the following examples we will use our [samples][samples] repo for simplicity.
43+
44+
Here we bind mount a local folder into our container and display its contents during
45+
a `pack build`.
46+
47+
#### Linux container example
48+
49+
<!-- test:suite=volumes:linux -->
50+
51+
<!-- test:setup:exec -->
52+
<!--
53+
```
54+
git clone https://github.com/buildpack/samples
55+
```
56+
-->
57+
58+
<!-- test:teardown:exec -->
59+
<!--
60+
```
61+
docker volume rm test-volume
62+
```
63+
-->
64+
65+
We'll create a new docker volume:
66+
67+
<!-- test:exec -->
68+
```bash
69+
docker volume create test-volume
70+
```
71+
<!--+- "{{execute}}"+-->
72+
73+
Next, we'll create a text file on the volume:
74+
75+
<!-- test:exec -->
76+
```bash
77+
docker run --rm \
78+
--volume test-volume:/tmp/volume:rw \
79+
bash \
80+
bash -c 'echo "Hello from a volume!" > /tmp/volume/volume_contents.txt'
81+
```
82+
<!--+- "{{execute}}"+-->
83+
84+
Now, we can mount this volume during `pack build`:
85+
86+
<!-- test:exec -->
87+
```bash
88+
ls -al
89+
pack build volume-example \
90+
--builder cnbs/sample-builder:bionic \
91+
--buildpack samples/buildpacks/hello-world \
92+
--path samples/apps/bash-script \
93+
--volume test-volume:/platform/volume:ro
94+
```
95+
<!--+- "{{execute}}"+-->
96+
97+
The above `pack build ...` command will mount the `test-volume` volume in the `/platform` directory of the container.
98+
99+
Since we are using the `samples/hello-world` buildpack, we should see the `/platform` directory files listed:
100+
101+
```text
102+
[builder] platform_dir files:
103+
...
104+
[builder] /platform/volume:
105+
[builder] total 12
106+
[builder] drwxr-xr-x 2 root root 4096 Sep 17 20:17 .
107+
[builder] drwxr-xr-x 1 root root 4096 Sep 17 20:18 ..
108+
[builder] -rw-r--r-- 1 root root 21 Sep 17 20:18 volume_contents.txt
109+
```
110+
111+
[samples]: https://github.com/buildpack/samples

0 commit comments

Comments
 (0)