@@ -3,13 +3,12 @@ package cnab
33import (
44 "context"
55 "fmt"
6- "io/ioutil"
76 "os"
87
9- "github.com/deislabs/cnab-go/bundle"
108 "github.com/docker/app/internal"
119 "github.com/docker/app/internal/log"
1210 "github.com/docker/app/internal/packager"
11+ "github.com/docker/app/internal/relocated"
1312 "github.com/docker/app/internal/store"
1413 appstore "github.com/docker/app/internal/store"
1514 "github.com/docker/cli/cli/command"
@@ -48,30 +47,20 @@ func getAppNameKind(name string) (string, nameKind) {
4847 return name , nameKindReference
4948}
5049
51- func extractAndLoadAppBasedBundle (dockerCli command.Cli , name string ) (* bundle .Bundle , string , error ) {
50+ func extractAndLoadAppBasedBundle (dockerCli command.Cli , name string ) (* relocated .Bundle , string , error ) {
5251 app , err := packager .Extract (name )
5352 if err != nil {
5453 return nil , "" , err
5554 }
5655 defer app .Cleanup ()
5756 bndl , err := packager .MakeBundleFromApp (dockerCli , app , nil )
58- return bndl , "" , err
59- }
60-
61- // LoadBundleFromFile loads a bundle from a file
62- func LoadBundleFromFile (filename string ) (* bundle.Bundle , error ) {
63- b := & bundle.Bundle {}
64- data , err := ioutil .ReadFile (filename )
65- if err != nil {
66- return b , err
67- }
68- return bundle .Unmarshal (data )
57+ return relocated .FromBundle (bndl ), "" , err
6958}
7059
7160// ResolveBundle looks for a CNAB bundle which can be in a Docker App Package format or
7261// a bundle stored locally or in the bundle store. It returns a built or found bundle,
7362// a reference to the bundle if it is found in the bundlestore, and an error.
74- func ResolveBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , name string ) (* bundle .Bundle , string , error ) {
63+ func ResolveBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , name string ) (* relocated .Bundle , string , error ) {
7564 // resolution logic:
7665 // - if there is a docker-app package in working directory or if a directory is given use packager.Extract
7766 // - pull the bundle from the registry and add it to the bundle store
@@ -90,7 +79,7 @@ func ResolveBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name
9079}
9180
9281// GetBundle searches for the bundle locally and tries to pull it if not found
93- func GetBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , name string ) (* bundle .Bundle , reference.Reference , error ) {
82+ func GetBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , name string ) (* relocated .Bundle , reference.Reference , error ) {
9483 bndl , ref , err := getBundleFromStore (bundleStore , name )
9584 if err != nil {
9685 named , err := store .StringToNamedRef (name )
@@ -108,7 +97,7 @@ func GetBundle(dockerCli command.Cli, bundleStore appstore.BundleStore, name str
10897 return bndl , ref , nil
10998}
11099
111- func getBundleFromStore (bundleStore appstore.BundleStore , name string ) (* bundle .Bundle , reference.Reference , error ) {
100+ func getBundleFromStore (bundleStore appstore.BundleStore , name string ) (* relocated .Bundle , reference.Reference , error ) {
112101 ref , err := bundleStore .LookUp (name )
113102 if err != nil {
114103 logrus .Debugf ("Unable to find reference %q in the bundle store" , name )
@@ -123,18 +112,19 @@ func getBundleFromStore(bundleStore appstore.BundleStore, name string) (*bundle.
123112}
124113
125114// PullBundle pulls the bundle and stores it into the bundle store
126- func PullBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , tagRef reference.Named ) (* bundle .Bundle , error ) {
115+ func PullBundle (dockerCli command.Cli , bundleStore appstore.BundleStore , tagRef reference.Named ) (* relocated .Bundle , error ) {
127116 insecureRegistries , err := internal .InsecureRegistriesFromEngine (dockerCli )
128117 if err != nil {
129118 return nil , fmt .Errorf ("could not retrieve insecure registries: %v" , err )
130119 }
131120
132- bndl , _ , err := remotes .Pull (log .WithLogContext (context .Background ()), reference .TagNameOnly (tagRef ), remotes .CreateResolver (dockerCli .ConfigFile (), insecureRegistries ... ))
121+ bndl , relocationMap , err := remotes .Pull (log .WithLogContext (context .Background ()), reference .TagNameOnly (tagRef ), remotes .CreateResolver (dockerCli .ConfigFile (), insecureRegistries ... ))
133122 if err != nil {
134123 return nil , err
135124 }
136- if _ , err := bundleStore .Store (tagRef , bndl ); err != nil {
125+ relocatedBundle := & relocated.Bundle {Bundle : bndl , RelocationMap : relocationMap }
126+ if _ , err := bundleStore .Store (tagRef , relocatedBundle ); err != nil {
137127 return nil , err
138128 }
139- return bndl , nil
129+ return relocatedBundle , nil
140130}
0 commit comments