@@ -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+
279331func TestDeployDockerApp (t * testing.T ) {
280332 tmpDir := fs .NewDir (t , t .Name ())
281333 defer tmpDir .Remove ()
0 commit comments