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

Commit 62b6a2f

Browse files
Add an e2e on the bundle command using a docker in docker
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
1 parent 197029b commit 62b6a2f

2 files changed

Lines changed: 170 additions & 0 deletions

File tree

e2e/commands_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,58 @@ func TestAttachmentsWithRegistry(t *testing.T) {
276276
assert.Assert(t, strings.Contains(resultOutput, "nesteddir/nested2/nested3/config3.cfg"))
277277
}
278278

279+
func TestBundle(t *testing.T) {
280+
tmpDir := fs.NewDir(t, t.Name())
281+
defer tmpDir.Remove()
282+
// Using a custom DOCKER_CONFIG to store contexts in a temporary directory
283+
cmd := icmd.Cmd{Env: append(os.Environ(), "DOCKER_CONFIG="+tmpDir.Path())}
284+
285+
// Running a docker in docker to bundle the application
286+
dind := NewContainer("docker:18.09-dind", 2375)
287+
dind.Start(t)
288+
defer dind.Stop(t)
289+
290+
// Create a build context
291+
cmd.Command = []string{dockerCli, "context", "create", "build-context", "--docker", fmt.Sprintf(`"host=tcp://%s"`, dind.GetAddress(t))}
292+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
293+
294+
// The dind doesn't have the cnab-app-base image so we save it in order to load it later
295+
cmd.Command = []string{dockerCli, "save", fmt.Sprintf("docker/cnab-app-base:%s", internal.Version), "-o", tmpDir.Join("cnab-app-base.tar.gz")}
296+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
297+
298+
cmd.Env = append(cmd.Env, "DOCKER_CONTEXT=build-context")
299+
cmd.Command = []string{dockerCli, "load", "-i", tmpDir.Join("cnab-app-base.tar.gz")}
300+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
301+
302+
// Bundle the docker application package to a CNAB bundle, using the build-context.
303+
cmd.Command = []string{dockerApp, "bundle", filepath.Join("testdata", "simple", "simple.dockerapp"), "--out", tmpDir.Join("bundle.json")}
304+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
305+
306+
// Check the resulting CNAB bundle.json
307+
golden.Assert(t, string(golden.Get(t, tmpDir.Join("bundle.json"))), "simple-bundle.json.golden")
308+
309+
// List the images on the build context daemon and checks the invocation image is there
310+
cmd.Command = []string{dockerCli, "image", "ls", "--format", "{{.Repository}}:{{.Tag}}"}
311+
icmd.RunCmd(cmd).Assert(t, icmd.Expected{ExitCode: 0, Out: "acmecorp/simple:1.1.0-beta1-invoc"})
312+
313+
// Copy all the files from the invocation image and check them
314+
cmd.Command = []string{dockerCli, "create", "--name", "invocation", "acmecorp/simple:1.1.0-beta1-invoc"}
315+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
316+
cmd.Command = []string{dockerCli, "cp", "invocation:/cnab/app/simple.dockerapp", tmpDir.Join("simple.dockerapp")}
317+
icmd.RunCmd(cmd).Assert(t, icmd.Success)
318+
319+
appDir := filepath.Join("testdata", "simple", "simple.dockerapp")
320+
manifest := fs.Expected(
321+
t,
322+
fs.WithMode(0755),
323+
fs.WithFile(internal.MetadataFileName, readFile(t, filepath.Join(appDir, internal.MetadataFileName)), fs.WithMode(0644)),
324+
fs.WithFile(internal.ComposeFileName, readFile(t, filepath.Join(appDir, internal.ComposeFileName)), fs.WithMode(0644)),
325+
fs.WithFile(internal.ParametersFileName, readFile(t, filepath.Join(appDir, internal.ParametersFileName)), fs.WithMode(0644)),
326+
)
327+
328+
assert.Assert(t, fs.Equal(tmpDir.Join("simple.dockerapp"), manifest))
329+
}
330+
279331
func TestDeployDockerApp(t *testing.T) {
280332
tmpDir := fs.NewDir(t, t.Name())
281333
defer tmpDir.Remove()
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"name": "acmecorp/simple",
3+
"version": "1.1.0-beta1",
4+
"description": "new fancy webapp with microservices",
5+
"maintainers": [
6+
{
7+
"name": "John Developer",
8+
"email": "john.dev@acmecorp.cool",
9+
"url": ""
10+
},
11+
{
12+
"name": "Jane Developer",
13+
"email": "jane.dev@acmecorp.cool",
14+
"url": ""
15+
}
16+
],
17+
"invocationImages": [
18+
{
19+
"imageType": "docker",
20+
"image": "acmecorp/simple:1.1.0-beta1-invoc"
21+
}
22+
],
23+
"images": {
24+
"api": {
25+
"imageType": "docker",
26+
"image": "python:3.6",
27+
"description": "python:3.6",
28+
"refs": null
29+
},
30+
"db": {
31+
"imageType": "docker",
32+
"image": "postgres:9.3",
33+
"description": "postgres:9.3",
34+
"refs": null
35+
},
36+
"web": {
37+
"imageType": "docker",
38+
"image": "nginx:latest",
39+
"description": "nginx:latest",
40+
"refs": null
41+
}
42+
},
43+
"actions": {
44+
"inspect": {
45+
"Modifies": false
46+
},
47+
"status": {
48+
"Modifies": false
49+
}
50+
},
51+
"parameters": {
52+
"api_host": {
53+
"type": "string",
54+
"defaultValue": "coolapp.com",
55+
"required": false,
56+
"metadata": {},
57+
"destination": {
58+
"path": "",
59+
"env": "docker_param1"
60+
}
61+
},
62+
"docker.kubernetes-namespace": {
63+
"type": "string",
64+
"defaultValue": "",
65+
"required": false,
66+
"metadata": {
67+
"description": "Namespace in which to deploy"
68+
},
69+
"destination": {
70+
"path": "",
71+
"env": "DOCKER_KUBERNETES_NAMESPACE"
72+
}
73+
},
74+
"docker.orchestrator": {
75+
"type": "string",
76+
"defaultValue": "",
77+
"allowedValues": [
78+
"",
79+
"swarm",
80+
"kubernetes"
81+
],
82+
"required": false,
83+
"metadata": {
84+
"description": "Orchestrator on which to deploy"
85+
},
86+
"destination": {
87+
"path": "",
88+
"env": "DOCKER_STACK_ORCHESTRATOR"
89+
}
90+
},
91+
"static_subdir": {
92+
"type": "string",
93+
"defaultValue": "data/static",
94+
"required": false,
95+
"metadata": {},
96+
"destination": {
97+
"path": "",
98+
"env": "docker_param2"
99+
}
100+
},
101+
"web_port": {
102+
"type": "string",
103+
"defaultValue": "8082",
104+
"required": false,
105+
"metadata": {},
106+
"destination": {
107+
"path": "",
108+
"env": "docker_param3"
109+
}
110+
}
111+
},
112+
"credentials": {
113+
"docker.context": {
114+
"path": "/cnab/app/context.dockercontext",
115+
"env": ""
116+
}
117+
}
118+
}

0 commit comments

Comments
 (0)