@@ -41,11 +41,12 @@ type buildOptions struct {
4141func Cmd (dockerCli command.Cli ) * cobra.Command {
4242 var opts buildOptions
4343 cmd := & cobra.Command {
44- Use : "build [APPLICATION]" ,
44+ Use : "build [APPLICATION] [TAG] " ,
4545 Short : "Build service images for the application" ,
4646 Example : `$ docker app build myapp.dockerapp` ,
47- Args : cli .ExactArgs (1 ),
47+ Args : cli .ExactArgs (2 ),
4848 RunE : func (cmd * cobra.Command , args []string ) error {
49+ opts .tag = args [1 ]
4950 tag , err := runBuild (dockerCli , args [0 ], opts )
5051 if err == nil {
5152 fmt .Printf ("Successfully build %s\n " , tag .String ())
@@ -58,8 +59,10 @@ func Cmd(dockerCli command.Cli) *cobra.Command {
5859 flags .BoolVar (& opts .noCache , "no-cache" , false , "Do not use cache when building the image" )
5960 flags .StringVar (& opts .progress , "progress" , "auto" , "Set type of progress output (auto, plain, tty). Use plain to show container output" )
6061 flags .BoolVar (& opts .pull , "pull" , false , "Always attempt to pull a newer version of the image" )
62+
63+ // For diagnostic and testing only
6164 flags .StringVarP (& opts .out , "output" , "o" , "" , "Dump generated bundle into a file" )
62- flags .StringVarP ( & opts . tag , "tag" , "t" , "" , "Name and optionally a tag in the 'name:tag' format" )
65+ flags .MarkHidden ( "output" ) //nolint:errcheck
6366
6467 return cmd
6568}
@@ -70,6 +73,11 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
7073 return nil , err
7174 }
7275
76+ if opt .tag == "" {
77+ // FIXME temporary, until we get support for Digest in bundleStore and other commands
78+ return nil , fmt .Errorf ("A tag is required to run docker app build" )
79+ }
80+
7381 var ref reference.Named
7482 ref , err = packager .GetNamedTagged (opt .tag )
7583 if err != nil {
@@ -82,17 +90,12 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
8290 }
8391 defer app .Cleanup ()
8492
85- bundle , err := packager .MakeBundleFromApp (dockerCli , app , nil )
86- if err != nil {
87- return nil , err
88- }
89-
9093 buildopts , err := parseCompose (app , opt )
9194 if err != nil {
9295 return nil , err
9396 }
9497
95- buildopts ["invocation-image" ], err = createInvocationImageBuildOptions (dockerCli , app )
98+ buildopts ["com.docker.app. invocation-image" ], err = createInvocationImageBuildOptions (dockerCli , app )
9699 if err != nil {
97100 return nil , err
98101 }
@@ -114,13 +117,17 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) (refe
114117
115118 pw := progress .NewPrinter (ctx , os .Stderr , opt .progress )
116119
117- // We rely on buildx "docker" builder integrated in docker engine, so don't nee a DockerAPI here
120+ // We rely on buildx "docker" builder integrated in docker engine, so don't need a DockerAPI here
118121 resp , err := build .Build (ctx , driverInfo , buildopts , nil , dockerCli .ConfigFile (), pw )
119122 if err != nil {
120123 return nil , err
121124 }
125+ fmt .Fprintln (dockerCli .Out (), "Successfully built service images" ) //nolint:errcheck
122126
123- fmt .Println ("Successfully built service images" )
127+ bundle , err := packager .MakeBundleFromApp (dockerCli , app , nil )
128+ if err != nil {
129+ return nil , err
130+ }
124131 updateBundle (bundle , resp )
125132
126133 if ref == nil {
@@ -140,7 +147,7 @@ func checkMinimalEngineVersion(dockerCli command.Cli) error {
140147 if err != nil {
141148 return err
142149 }
143- majorVersion , err := strconv .Atoi (info . ServerVersion [: strings .IndexRune (info .ServerVersion , '.' ) ])
150+ majorVersion , err := strconv .Atoi (strings .SplitN (info .ServerVersion , "." , 2 )[ 0 ])
144151 if err != nil {
145152 return err
146153 }
@@ -154,7 +161,7 @@ func updateBundle(bundle *bundle.Bundle, resp map[string]*client.SolveResponse)
154161 debugSolveResponses (resp )
155162 for service , r := range resp {
156163 digest := r .ExporterResponse ["containerimage.digest" ]
157- if service == "invocation-image" {
164+ if service == "com.docker.app. invocation-image" {
158165 bundle .InvocationImages [0 ].Digest = digest
159166 } else {
160167 image := bundle .Images [service ]
@@ -175,21 +182,11 @@ func persistBundle(opt buildOptions, bndl *bundle.Bundle, ref reference.Named) e
175182 }
176183 if opt .out == "-" {
177184 _ , err = os .Stdout .Write (b )
178- if err != nil {
179- return err
180- }
181- } else {
182- err = ioutil .WriteFile (opt .out , b , 0644 )
183- if err != nil {
184- return err
185- }
186- }
187- } else {
188- if err := packager .PersistInBundleStore (ref , bndl ); err != nil {
189185 return err
190186 }
187+ return ioutil .WriteFile (opt .out , b , 0644 )
191188 }
192- return nil
189+ return packager . PersistInBundleStore ( ref , bndl )
193190}
194191
195192func createInvocationImageBuildOptions (dockerCli command.Cli , app * types.App ) (build.Options , error ) {
0 commit comments