@@ -3,6 +3,7 @@ package e2e
33import (
44 "fmt"
55 "io/ioutil"
6+ "os"
67 "path/filepath"
78 "regexp"
89 "runtime"
@@ -81,10 +82,10 @@ func testRenderApp(appPath string, env ...string) func(*testing.T) {
8182func TestRenderFormatters (t * testing.T ) {
8283 appPath := filepath .Join ("testdata" , "simple" , "simple.dockerapp" )
8384 result := icmd .RunCommand (dockerApp , "render" , "--formatter" , "json" , appPath ).Assert (t , icmd .Success )
84- assert .Assert (t , golden . String ( result .Stdout (), "expected-json-render.golden" ) )
85+ golden .Assert (t , result .Stdout (), "expected-json-render.golden" )
8586
8687 result = icmd .RunCommand (dockerApp , "render" , "--formatter" , "yaml" , appPath ).Assert (t , icmd .Success )
87- assert .Assert (t , golden . String ( result .Stdout (), "expected-yaml-render.golden" ) )
88+ golden .Assert (t , result .Stdout (), "expected-yaml-render.golden" )
8889}
8990
9091func TestInit (t * testing.T ) {
@@ -155,7 +156,7 @@ maintainers:
155156
156157 appData , err := ioutil .ReadFile (tmpDir .Join ("tac.dockerapp" ))
157158 assert .NilError (t , err )
158- assert .Assert (t , golden . Bytes (appData , "init-singlefile.dockerapp" ) )
159+ golden .Assert (t , string (appData ) , "init-singlefile.dockerapp" )
159160 // Check various commands work on single-file app package
160161 cmd .Command = []string {dockerApp , "inspect" , "tac" }
161162 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
@@ -207,15 +208,15 @@ func TestSplitMerge(t *testing.T) {
207208 // test that inspect works on single-file
208209 cmd .Command = []string {dockerApp , "inspect" , "remerged" }
209210 result := icmd .RunCmd (cmd ).Assert (t , icmd .Success )
210- assert .Assert (t , golden . String ( result .Combined (), "envvariables-inspect.golden" ) )
211+ golden .Assert (t , result .Combined (), "envvariables-inspect.golden" )
211212
212213 // split it
213214 cmd .Command = []string {dockerApp , "split" , "remerged" , "-o" , "split.dockerapp" }
214215 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
215216
216217 cmd .Command = []string {dockerApp , "inspect" , "remerged" }
217218 result = icmd .RunCmd (cmd ).Assert (t , icmd .Success )
218- assert .Assert (t , golden . String ( result .Combined (), "envvariables-inspect.golden" ) )
219+ golden .Assert (t , result .Combined (), "envvariables-inspect.golden" )
219220
220221 // test inplace
221222 cmd .Command = []string {dockerApp , "merge" , "split" }
@@ -228,7 +229,7 @@ func TestSplitMerge(t *testing.T) {
228229func TestURL (t * testing.T ) {
229230 url := "https://raw.githubusercontent.com/docker/app/v0.4.1/examples/hello-world/hello-world.dockerapp"
230231 result := icmd .RunCommand (dockerApp , "inspect" , url ).Assert (t , icmd .Success )
231- assert .Assert (t , golden . String ( result .Combined (), "helloworld-inspect.golden" ) )
232+ golden .Assert (t , result .Combined (), "helloworld-inspect.golden" )
232233}
233234
234235func TestWithRegistry (t * testing.T ) {
@@ -275,7 +276,59 @@ func TestAttachmentsWithRegistry(t *testing.T) {
275276 assert .Assert (t , strings .Contains (resultOutput , "nesteddir/nested2/nested3/config3.cfg" ))
276277}
277278
278- func TestDeployDockerApp (t * testing.T ) {
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+
331+ func TestDockerAppLifecycle (t * testing.T ) {
279332 tmpDir := fs .NewDir (t , t .Name ())
280333 defer tmpDir .Remove ()
281334
@@ -315,8 +368,7 @@ func TestDeployDockerApp(t *testing.T) {
315368 // The workaround is to create a context with an empty host.
316369 // This host will default to the unix socket inside the
317370 // invocation image
318- host := ""
319- cmd .Command = []string {dockerCli , "context" , "create" , "swarm-target-context" , "--docker" , fmt .Sprintf ("host=%s" , host ), "--default-stack-orchestrator" , "swarm" }
371+ cmd .Command = []string {dockerCli , "context" , "create" , "swarm-target-context" , "--docker" , "host=" , "--default-stack-orchestrator" , "swarm" }
320372 icmd .RunCmd (cmd ).Assert (t , icmd .Success )
321373
322374 // Initialize the swarm
@@ -348,6 +400,19 @@ func TestDeployDockerApp(t *testing.T) {
348400 fmt .Sprintf ("[[:alnum:]]+ %s_api replicated [0-1]/1 python:3.6" , t .Name ()),
349401 })
350402
403+ // Upgrade the application, changing the port
404+ cmd .Command = []string {dockerApp , "upgrade" , t .Name (), "--set" , "web_port=8081" }
405+ checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
406+ []string {
407+ fmt .Sprintf ("Updating service %s_db" , t .Name ()),
408+ fmt .Sprintf ("Updating service %s_api" , t .Name ()),
409+ fmt .Sprintf ("Updating service %s_web" , t .Name ()),
410+ })
411+
412+ // Query the application status again, the port should have change
413+ cmd .Command = []string {dockerApp , "status" , t .Name ()}
414+ icmd .RunCmd (cmd ).Assert (t , icmd.Expected {ExitCode : 0 , Out : "8081" })
415+
351416 // Uninstall the application
352417 cmd .Command = []string {dockerApp , "uninstall" , t .Name ()}
353418 checkContains (t , icmd .RunCmd (cmd ).Assert (t , icmd .Success ).Combined (),
0 commit comments