44 "context"
55 "encoding/json"
66 "fmt"
7+ "github.com/docker/app/internal/packager"
8+ "github.com/sirupsen/logrus"
79 "os"
810 "path/filepath"
911 "strings"
@@ -13,15 +15,13 @@ import (
1315 "github.com/docker/buildx/util/progress"
1416
1517 cnab "github.com/deislabs/cnab-go/driver"
16- "github.com/docker/app/internal"
1718 "github.com/docker/buildx/bake"
1819 "github.com/docker/buildx/build"
1920 _ "github.com/docker/buildx/driver/docker" // required to get default driver registered, see driver/docker/factory.go:14
2021 "github.com/docker/cli/cli"
2122 "github.com/docker/cli/cli/command"
2223 dockerclient "github.com/docker/docker/client"
2324 "github.com/moby/buildkit/util/appcontext"
24- "github.com/pkg/errors"
2525 "github.com/spf13/cobra"
2626)
2727
@@ -54,25 +54,35 @@ func buildCmd(dockerCli command.Cli) *cobra.Command {
5454}
5555
5656func runBuild (dockerCli command.Cli , application string , opt buildOptions ) error {
57- appname := internal .DirNameFromAppName (application )
58- f := "./" + appname + "/" + internal .ComposeFileName
59- if _ , err := os .Stat (f ); err != nil {
60- if os .IsNotExist (errors .Cause (err )) {
61- return fmt .Errorf ("no compose file at %s, did you selected the right docker app folder ?" , f )
62- }
57+ app , err := packager .Extract (application )
58+ if err != nil {
59+ return err
6360 }
61+ defer app .Cleanup ()
62+ appname := app .Name
6463
65- bundle , err := makeBundle (dockerCli , application , nil )
64+ bundle , err := makeBundleFromApp (dockerCli , app , nil )
6665 if err != nil {
6766 return err
6867 }
6968
7069 ctx := appcontext .Context ()
71- targets , err := bake .ReadTargets ( ctx , [] string { f }, [] string { "default" }, nil )
70+ compose , err := bake .ParseCompose ( app . Composes ()[ 0 ]) // Fixme can have > 1 composes ?
7271 if err != nil {
7372 return err
7473 }
7574
75+ targets := map [string ]bake.Target {}
76+ for _ , n := range compose .ResolveGroup ("default" ) {
77+ t , err := compose .ResolveTarget (n )
78+ if err != nil {
79+ return nil
80+ }
81+ if t != nil {
82+ targets [n ] = * t
83+ }
84+ }
85+
7686 for service , t := range targets {
7787 if strings .HasPrefix (* t .Context , "." ) {
7888 // Relative path in compose file under x.dockerapp refers to parent folder
@@ -87,19 +97,35 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) error
8797 }
8898 }
8999
90- // -- debug
91- dt , err := json .MarshalIndent (map [string ]map [string ]bake.Target {"target" : targets }, "" , " " )
92- if err != nil {
93- return err
100+ if logrus .IsLevelEnabled (logrus .DebugLevel ) {
101+ dt , err := json .MarshalIndent (map [string ]map [string ]bake.Target {"target" : targets }, "" , " " )
102+ if err != nil {
103+ return err
104+ }
105+ fmt .Fprintln (dockerCli .Out (), string (dt ))
94106 }
95- fmt .Fprintln (dockerCli .Out (), string (dt ))
96- // -- debug
97107
98108 buildopts , err := bake .TargetsToBuildOpt (targets , opt .noCache , opt .pull )
99109 if err != nil {
100110 return err
101111 }
102112
113+ /**
114+ // FIXME it seems there's no way to setup a build.Options without a plain DockerContext path
115+ buildContext := bytes.NewBuffer(nil)
116+ if err := packager.PackInvocationImageContext(dockerCli, app, buildContext); err != nil {
117+ return err
118+ }
119+
120+ buildopts["invocation-image"] = build.Options{
121+ Inputs: build.Inputs{
122+ InStream: buildContext,
123+ },
124+ Tags: []string{ fmt.Sprintf("%s:%s-%s", bundle.Name, bundle.Version, "-invoc") },
125+ Session: []session.Attachable{authprovider.NewDockerAuthProvider(os.Stderr)},
126+ }
127+ */
128+
103129 d , err := driver .GetDriver (ctx , "buildx_buildkit_default" , nil , dockerCli .Client (), nil , "" , nil )
104130 if err != nil {
105131 return err
@@ -151,7 +177,7 @@ func runBuild(dockerCli command.Cli, application string, opt buildOptions) error
151177 image := bundle .Images [service ]
152178 image .ImageType = cnab .ImageTypeDocker
153179 image .Image = fmt .Sprintf ("%s:%s-%s" , bundle .Name , bundle .Version , service )
154- image .Digest = inspect .ID
180+ image .Digest = inspect .ID // Content Digest
155181 bundle .Images [service ] = image
156182 fmt .Printf (" - %s : %s:%s-%s (%s)\n " , service , bundle .Name , bundle .Version , service , inspect .ID )
157183 }
0 commit comments