Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 520a7b1

Browse files
chris-cronesilvin-lubecki
authored andcommitted
Add CNAB examples
*Fix running docker-app validate only on application package examples and skip CNAB examples. Signed-off-by: Christopher Crone <christopher.crone@docker.com>
1 parent d17548a commit 520a7b1

21 files changed

Lines changed: 394 additions & 2 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ An *experimental* utility to help make Compose files more reusable and sharable.
66

77
You can find some preview binaries of `docker-app` with CNAB support [here](https://github.com/docker/app/releases/tag/cnab-dockercon-preview).
88

9-
There is a [simple example](https://github.com/docker/app/tree/cnab-preview/examples/cnab-simple) and an [example of how to deploy a Helm Chart](https://github.com/docker/app/tree/cnab-preview/examples/cnab-helm).
9+
There is a [simple example](./examples/cnab-simple) and an [example of how to deploy a Helm Chart](./examples/cnab-helm).
1010

1111
## The problem application packages solve
1212

e2e/example_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ import (
1212

1313
func TestExamplesAreValid(t *testing.T) {
1414
err := filepath.Walk("../examples", func(p string, info os.FileInfo, err error) error {
15+
appPath := filepath.Join(p, filepath.Base(p)+".dockerapp")
16+
_, statErr := os.Stat(appPath)
1517
switch {
1618
case strings.HasSuffix(p, "examples"):
1719
return nil
1820
case strings.HasSuffix(p, ".resources"):
1921
return filepath.SkipDir
2022
case !info.IsDir():
2123
return nil
24+
case os.IsNotExist(statErr):
25+
return nil
2226
default:
23-
result := icmd.RunCommand(dockerApp, "validate", filepath.Join(p, filepath.Base(p)+".dockerapp"))
27+
result := icmd.RunCommand(dockerApp, "validate", appPath)
2428
result.Assert(t, icmd.Success)
2529
return filepath.SkipDir
2630
}

examples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,11 @@ To learn how to create the Docker voting app from [Docker samples](https://githu
1919
To learn how to create a basic WordPress with a database.
2020

2121
![WordPress app screenshot](.resources/wordpress.png "WordPress app screenshot")
22+
23+
### [CNAB simple application](cnab-simple)
24+
25+
Inspect and bundle a simple application as a [CNAB](https://cnab.io).
26+
27+
### [Deploy a Helm Chart using docker-app](cnab-helm)
28+
29+
As `docker-app` is a [CNAB](https://cnab.io) compliant client, you can deploy any CNAB.

examples/cnab-helm/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
## Requirements
2+
3+
* Working Docker Desktop install with Kubernetes enabled
4+
* [`docker-app` with CNAB support](https://github.com/docker/app/releases/tag/cnab-dockercon-preview) installed
5+
* Source code from this directory
6+
* Create a context with `docker-app context`
7+
* Set the `DOCKER_TARGET_CONTEXT` environment variable
8+
* Helm configured for your Kubernetes cluster
9+
* A `duffle` credential set created
10+
11+
## Examples
12+
13+
14+
Install the Helm chart example using `docker-app`
15+
16+
17+
```
18+
$ docker-app install -c local bundle.json
19+
Do install for hellohelm
20+
helm install --namespace hellohelm -n hellohelm /cnab/app/charts/alpine
21+
NAME: hellohelm
22+
LAST DEPLOYED: Wed Nov 28 13:58:22 2018
23+
NAMESPACE: hellohelm
24+
STATUS: DEPLOYED
25+
26+
RESOURCES:
27+
==> v1/Pod
28+
NAME AGE
29+
hellohelm-alpine 0s
30+
```
31+
32+
33+
Check the status of the Helm-based application:
34+
35+
```console
36+
$ docker-app status -c local hellohelm
37+
Do Status
38+
helm status hellohelm
39+
LAST DEPLOYED: Wed Nov 28 13:58:22 2018
40+
NAMESPACE: hellohelm
41+
STATUS: DEPLOYED
42+
43+
RESOURCES:
44+
==> v1/Pod
45+
NAME AGE
46+
hellohelm-alpine 2m
47+
```
48+
49+
Uninstall the Helm-based application:
50+
51+
```console
52+
docker-app uninstall -c local hellohelm
53+
Do Uninstall
54+
helm delete --purge hellohelm
55+
release "hellohelm" deleted
56+
```

examples/cnab-helm/bundle.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "hellohelm",
3+
"version": "0.1.0",
4+
"invocationImages": [
5+
{
6+
"imageType": "docker",
7+
"image": "cnab/hellohelm:latest"
8+
}
9+
],
10+
"images": [
11+
{
12+
"description": "alpine",
13+
"image": "technosophos/demo2alpine:0.1.0",
14+
"imageType": "docker",
15+
"refs": [
16+
{
17+
"path": "cnab/app/charts/alpine/values.yaml",
18+
"field": "image.repository"
19+
}
20+
]
21+
}
22+
],
23+
"parameters": {
24+
"port": {
25+
"defaultValue": 8080,
26+
"type": "int"
27+
}
28+
},
29+
"credentials": {
30+
"kubeconfig": {
31+
"path": "/root/.kube/config"
32+
}
33+
}
34+
}

examples/cnab-helm/cnab/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM cnab/k8sbase:latest
2+
3+
COPY app/Makefile /cnab/app/Makefile
4+
COPY app/charts /cnab/app/charts
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
KUBECONFIG=/root/.kube/config
2+
3+
CNAB_ACTION ?= status
4+
CNAB_INSTALLATION_NAME ?= helmtest
5+
6+
CNAB_P_HELM_OPTIONS ?= --dry-run --debug
7+
CNAB_P_NAMESPACE ?= hellohelm
8+
9+
CHART=/cnab/app/charts/alpine
10+
11+
install:
12+
@echo "Do $(CNAB_ACTION) for $(CNAB_INSTALLATION_NAME)"
13+
helm install --namespace $(CNAB_P_NAMESPACE) -n $(CNAB_INSTALLATION_NAME) $(CHART)
14+
15+
uninstall:
16+
@echo "Do Uninstall"
17+
helm delete --purge $(CNAB_INSTALLATION_NAME)
18+
19+
upgrade:
20+
@echo "Do Upgrade"
21+
helm upgrade --namespace $(CNAB_P_NAMESPACE) $(CNAB_INSTALLATION_NAME) $(CHART)
22+
23+
status:
24+
@echo "Do Status"
25+
helm status $(CNAB_INSTALLATION_NAME)
26+
27+
.PHONY: install uninstall upgrade status
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: alpine
2+
description: Deploy a basic Alpine Linux pod
3+
version: 0.1.0
4+
home: https://github.com/kubernetes/helm
5+
sources:
6+
- https://github.com/kubernetes/helm
7+
appVersion: 3.3
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM alpine:3.7
2+
3+
CMD ["sleep", "9000"]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Alpine: A simple Helm chart
2+
3+
Run a single pod of Alpine Linux.
4+
5+
The `templates/` directory contains a very simple pod resource with a
6+
couple of parameters.
7+
8+
The `values.yaml` file contains the default values for the
9+
`alpine-pod.yaml` template.
10+
11+
You can install this example using `helm install docs/examples/alpine`.

0 commit comments

Comments
 (0)