11package bundle
22
33import (
4+ "context"
5+ "github.com/operator-framework/operator-registry/pkg/image"
6+ "github.com/operator-framework/operator-registry/pkg/image/execregistry"
47 "io/ioutil"
58 "os"
69 "path/filepath"
@@ -9,6 +12,7 @@ import (
912 "github.com/sirupsen/logrus"
1013
1114 "github.com/operator-framework/operator-registry/pkg/containertools"
15+ "github.com/operator-framework/operator-registry/pkg/image/containerdregistry"
1216)
1317
1418// BundleExporter exports the manifests of a bundle image into a directory
@@ -18,11 +22,11 @@ type BundleExporter struct {
1822 containerTool containertools.ContainerTool
1923}
2024
21- func NewSQLExporterForBundle (image , directory , containerTool string ) * BundleExporter {
25+ func NewSQLExporterForBundle (image , directory string , containerTool containertools. ContainerTool ) * BundleExporter {
2226 return & BundleExporter {
2327 image : image ,
2428 directory : directory ,
25- containerTool : containertools . NewContainerTool ( containerTool , containertools . NoneTool ) ,
29+ containerTool : containerTool ,
2630 }
2731}
2832
@@ -36,13 +40,33 @@ func (i *BundleExporter) Export() error {
3640 }
3741 defer os .RemoveAll (tmpDir )
3842
39- // Pull the image and get the manifests
40- reader := containertools .NewImageReader (i .containerTool , log )
43+ var reg image.Registry
44+ var rerr error
45+ switch i .containerTool {
46+ case containertools .NoneTool :
47+ reg , rerr = containerdregistry .NewRegistry (containerdregistry .WithLog (log ))
48+ case containertools .PodmanTool :
49+ fallthrough
50+ case containertools .DockerTool :
51+ reg , rerr = execregistry .NewRegistry (i .containerTool , log )
52+ }
53+ if rerr != nil {
54+ return rerr
55+ }
56+ defer func () {
57+ if err := reg .Destroy (); err != nil {
58+ log .WithError (err ).Warn ("error destroying local cache" )
59+ }
60+ }()
4161
42- err = reader .GetImageData (i .image , tmpDir )
43- if err != nil {
62+ if err := reg .Pull (context .TODO (), image .SimpleReference (i .image )); err != nil {
4463 return err
4564 }
65+
66+ if err := reg .Unpack (context .TODO (), image .SimpleReference (i .image ), tmpDir ); err != nil {
67+ return err
68+ }
69+
4670 if err := os .MkdirAll (i .directory , 0777 ); err != nil {
4771 return err
4872 }
0 commit comments