@@ -12,6 +12,11 @@ import (
1212 "strconv"
1313 "strings"
1414
15+ errors2 "github.com/pkg/errors"
16+
17+ "github.com/docker/app/internal"
18+ "github.com/docker/cnab-to-oci/remotes"
19+
1520 "github.com/deislabs/cnab-go/bundle"
1621 cnab "github.com/deislabs/cnab-go/driver"
1722 "github.com/docker/app/internal/packager"
@@ -130,7 +135,7 @@ func runBuild(dockerCli command.Cli, contextPath string, opt buildOptions) error
130135}
131136
132137func buildImageUsingBuildx (app * types.App , contextPath string , opt buildOptions , dockerCli command.Cli ) (* bundle.Bundle , error ) {
133- buildopts , err := parseCompose (app , contextPath , opt )
138+ buildopts , pulledServices , err := parseCompose (app , contextPath , opt )
134139 if err != nil {
135140 return nil , err
136141 }
@@ -178,9 +183,42 @@ func buildImageUsingBuildx(app *types.App, contextPath string, opt buildOptions,
178183 if err != nil {
179184 return nil , err
180185 }
186+
187+ if ! opt .noResolveImage {
188+ if err = fixServiceImageReferences (ctx , dockerCli , bundle , pulledServices ); err != nil {
189+ return nil , err
190+ }
191+ }
192+
181193 return bundle , nil
182194}
183195
196+ func fixServiceImageReferences (ctx context.Context , dockerCli command.Cli , bundle * bundle.Bundle , pulledServices []ServiceConfig ) error {
197+ insecureRegistries , err := internal .InsecureRegistriesFromEngine (dockerCli )
198+ if err != nil {
199+ return errors2 .Wrapf (err , "could not retrieve insecure registries" )
200+ }
201+ resolver := remotes .CreateResolver (dockerCli .ConfigFile (), insecureRegistries ... )
202+ for _ , service := range pulledServices {
203+ image := bundle .Images [service .Name ]
204+ ref , err := reference .ParseNormalizedNamed (* service .Image )
205+ if err != nil {
206+ return errors2 .Wrapf (err , "could not resolve image %s" , * service .Image )
207+ }
208+ _ , desc , err := resolver .Resolve (ctx , ref .String ())
209+ if err != nil {
210+ return errors2 .Wrapf (err , "could not resolve image %s" , ref .Name ())
211+ }
212+ canonical , err := reference .WithDigest (ref , desc .Digest )
213+ if err != nil {
214+ return errors2 .Wrapf (err , "could not resolve image %s" , ref .Name ())
215+ }
216+ image .Image = canonical .String ()
217+ bundle .Images [service .Name ] = image
218+ }
219+ return nil
220+ }
221+
184222func getAppFolder (opt buildOptions , contextPath string ) (string , error ) {
185223 application := opt .folder
186224 if application == "" {
0 commit comments