Skip to content

Commit d21528e

Browse files
committed
Auto-generate katacoda docs
Signed-off-by: Sambhav Kothari <[email protected]>
1 parent dd013ff commit d21528e

File tree

13 files changed

+240
-9
lines changed

13 files changed

+240
-9
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ jobs:
3434
- name: Check links
3535
run: |
3636
make check-links
37+
- name: Check katacoda
38+
run: |
39+
make check-katacoda
3740
- name: Upload public folder
3841
uses: actions/[email protected]
3942
env:

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,17 @@ prepare-for-pr: check-links test tools-tidy
157157
@echo "========"
158158
@echo "It looks good! :)"
159159
@echo "Make sure to commit all changes!"
160-
@echo "========"
160+
@echo "========"
161+
162+
.PHONY: katacoda
163+
katacoda:
164+
@echo "========"
165+
@echo "Generating Katacoda docs..."
166+
@go run katacoda/main.go
167+
@echo "All done!"
168+
@echo "========"
169+
170+
.PHONY: check-katacoda
171+
check-katacoda: katacoda
172+
@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)

content/docs/app-journey.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ getting-started=true
77
## Pack for the journey
88

99
In this tutorial, we'll explain how to use `pack` and **buildpacks** to create a runnable app image from source code.
10-
10+
<!--+if false+-->
1111
{{< katacoda-button href="https://katacoda.com/buildpacks/scenarios/app-journey" color="green" >}} Learn on Katacoda {{</>}}
1212

1313
In order to run the build process in an isolated fashion, `pack` uses **Docker**. That means you'll need to make sure you have both `docker` and `pack` installed:
1414

1515
{{< download-button href="https://store.docker.com/search?type=edition&offering=community" color="blue" >}} Install Docker {{</>}}
1616

1717
{{< download-button href="/docs/install-pack" color="pink" >}} Install pack {{</>}}
18-
18+
<!--+end+-->
1919
> **NOTE:** `pack` is only one implementation of the [Cloud Native Buildpacks Platform Specification][cnb-platform-spec]. Additionally, not all Cloud Native Buildpacks Platforms require Docker.
2020
2121
[cnb-platform-spec]: https://github.com/buildpacks/spec/blob/main/platform.md
@@ -42,24 +42,32 @@ instance, an **NPM buildpack** might look for a `package.json`, and a **Go build
4242

4343
### What is a [builder][builder]?
4444

45-
{{< summary "/docs/concepts/components/builder" >}}
45+
A builder is an image that contains all the components necessary to execute a build. A builder image is created by taking a build image and adding a lifecycle, buildpacks, and files that configure aspects of the build including the buildpack detection order and the location(s) of the run image.
4646

4747
## Next stop, the end
4848

4949
Let's see all this in action using `pack build`.
5050

5151
Run the following commands in a shell to clone and build this [simple Java app][samples-java-maven].
5252

53-
```bash
54-
# clone the repo
53+
1. Clone the samples repo.
54+
```
5555
git clone https://github.com/buildpacks/samples
56+
```
57+
<!--+- "{{execute}}"+-->
5658

57-
# go to the app directory
59+
2. Go to the Java apps sub-directory
60+
```
5861
cd samples/apps/java-maven
62+
```
63+
<!--+- "{{execute}}"+-->
5964

60-
# build the app
65+
3. Build the app using [`pack`][pack-docs]
66+
```
6167
pack build myapp --builder cnbs/sample-builder:bionic
6268
```
69+
<!--+- "{{execute}}"+-->
70+
6371

6472
> **NOTE:** This is your first time running `pack build` for `myapp`, so you'll notice that
6573
> **the build might take longer than usual.** Subsequent builds will take advantage of various forms of caching.
@@ -77,8 +85,15 @@ To test out your new app image locally, you can run it with Docker:
7785
```bash
7886
docker run --rm -p 8080:8080 myapp
7987
```
80-
88+
<!--+- "{{execute}}"+-->
89+
<!--+- if false+-->
8190
Now hit [`localhost:8080`](http://localhost:8080) in your favorite browser and take a minute to enjoy the view.
91+
<!--+- end+-->
92+
<!--+ `
93+
Now hit open the port "8080" of your host in your favorite browser and take a minute to enjoy the view.
94+
95+
On Katacoda you can do this by [clicking here](https://[[HOST_SUBDOMAIN]]-8080-[[KATACODA_HOST]].environments.katacoda.com)
96+
` +-->
8297

8398
### Take your image to the skies
8499

@@ -92,9 +107,17 @@ deploying your new image to your favorite cloud!
92107

93108
Windows image builds are now supported!
94109

110+
<!--+- if false+-->
95111
<a href="/docs/app-developer-guide/build-a-windows-app" class="button bg-blue">Windows build guide</a>
96112

97113
[builder]: /docs/concepts/components/builder/
98114
[buildpack]: /docs/concepts/components/buildpack/
99115
[samples-java-maven]: https://github.com/buildpacks/samples/tree/main/apps/java-maven
100116
[pack-docs]: /docs/tools/pack/
117+
<!--+end+-->
118+
119+
<!--+ `[builder]: https://buildpacks.io/docs/concepts/components/builder/
120+
[buildpack]: https://buildpacks.io/docs/concepts/components/buildpack/
121+
[samples-java-maven]: https://buildpacks.iohttps://github.com/buildpacks/samples/tree/main/apps/java-maven
122+
[pack-docs]: https://buildpacks.io/docs/tools/pack/
123+
` +-->

katacoda.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
scenario_root : katacoda/scenarios

katacoda/files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content/docs/app-journey.md,katacoda/scenarios/app-journey/step1.md

katacoda/main.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"encoding/csv"
5+
"log"
6+
"os"
7+
"regexp"
8+
"strings"
9+
"text/template"
10+
)
11+
12+
func getMappings() ([][]string, error) {
13+
file, err := os.Open("katacoda/files.txt")
14+
defer file.Close()
15+
if err != nil {
16+
return nil, err
17+
}
18+
return csv.NewReader(file).ReadAll()
19+
}
20+
21+
func main() {
22+
files, err := getMappings()
23+
if err != nil {
24+
log.Fatalf("unable to read input files: %w", err)
25+
}
26+
frontMatter := regexp.MustCompile(`(?s)\+\+\+.*\+\+\+`)
27+
for _, mapping := range files {
28+
i := mapping[0]
29+
o := mapping[1]
30+
out, err := os.ReadFile(i)
31+
out = frontMatter.ReplaceAll(out, []byte(""))
32+
if err != nil {
33+
log.Fatalf("unable to read input file %s: %s", i, err)
34+
}
35+
t, err := template.New("example").Delims("<!--+", "+-->").Parse(strings.TrimSpace(string(out)))
36+
if err != nil {
37+
log.Fatalf("unable to parse file %s: %s", i, err)
38+
}
39+
f, err := os.Create(o)
40+
if err != nil {
41+
log.Fatalf("create file: ", err)
42+
}
43+
if err := t.Execute(f, []string{}); err != nil {
44+
log.Fatalf("unable to execute template: %s", err)
45+
}
46+
}
47+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
(curl -sSL "https://github.com/buildpacks/pack/releases/download/v0.18.1/pack-v0.18.1-linux.tgz" | sudo tar -C /usr/local/bin/ --no-same-owner -xzv pack)
3+
docker pull cnbs/sample-builder:bionic
4+
docker pull buildpacksio/lifecycle
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## All done
2+
3+
Congratulations! You have successfully created your first app using buildpacks!
4+
5+
### Take your image to the skies
6+
7+
`pack` uses **buildpacks** to help you easily create OCI images that you can run just about anywhere. Try
8+
deploying your new image to your favorite cloud!
9+
10+
> In case you need it, `pack build` has a handy flag called `--publish` that will build your image directly onto a Docker
11+
> registry. You can learn more about `pack` features in the [documentation][pack-docs].
12+
13+
14+
[builder]: https://buildpacks.io/docs/concepts/components/builder/
15+
[buildpack]: https://buildpacks.io/docs/concepts/components/buildpack/
16+
[samples-java-maven]: https://github.com/buildpacks/samples/tree/main/apps/java-maven
17+
[pack-docs]: https://buildpacks.io/docs/tools/pack/
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
echo "Waiting for environment to be set up"; while [ ! -f /usr/local/bin/pack ] ; do sleep 1; done; echo "Done"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"title": "An App’s Brief Journey from Source to Image",
3+
"description": "Create an application container image using Cloud Native Buildpacks",
4+
"difficulty": "Beginner",
5+
"time": "10",
6+
"details": {
7+
"steps": [
8+
{
9+
"title": "Step 1",
10+
"text": "step1.md"
11+
}
12+
],
13+
"intro": {
14+
"courseData": "background.sh",
15+
"code": "foreground.sh",
16+
"text": "intro.md"
17+
},
18+
"finish": {
19+
"text": "finish.md"
20+
}
21+
},
22+
"environment": {
23+
"uilayout": "terminal"
24+
},
25+
"backend": {
26+
"imageid": "ubuntu:2004"
27+
}
28+
}

0 commit comments

Comments
 (0)