@@ -55,9 +55,9 @@ type errResponse struct {
5555 Message string
5656}
5757
58- func (p podmanClient ) imageInspect (imageName string ) (api.ImageInspect , error ) {
58+ func (p podmanClient ) imageInspect (ctx context. Context , imageName string ) (api.ImageInspect , error ) {
5959 url := fmt .Sprintf (inspectURL , imageName )
60- resp , err := p .c . Get ( url )
60+ resp , err := p .get ( ctx , url )
6161 if err != nil {
6262 return api.ImageInspect {}, xerrors .Errorf ("http error: %w" , err )
6363 }
@@ -78,9 +78,9 @@ func (p podmanClient) imageInspect(imageName string) (api.ImageInspect, error) {
7878 return inspect , nil
7979}
8080
81- func (p podmanClient ) imageHistoryInspect (imageName string ) ([]dimage.HistoryResponseItem , error ) {
81+ func (p podmanClient ) imageHistoryInspect (ctx context. Context , imageName string ) ([]dimage.HistoryResponseItem , error ) {
8282 url := fmt .Sprintf (historyURL , imageName )
83- resp , err := p .c . Get ( url )
83+ resp , err := p .get ( ctx , url )
8484 if err != nil {
8585 return []dimage.HistoryResponseItem {}, xerrors .Errorf ("http error: %w" , err )
8686 }
@@ -101,33 +101,42 @@ func (p podmanClient) imageHistoryInspect(imageName string) ([]dimage.HistoryRes
101101 return history , nil
102102}
103103
104- func (p podmanClient ) imageSave (_ context.Context , imageNames []string , _ ... client.ImageSaveOption ) (io.ReadCloser , error ) {
104+ func (p podmanClient ) imageSave (ctx context.Context , imageNames []string , _ ... client.ImageSaveOption ) (io.ReadCloser , error ) {
105105 if len (imageNames ) < 1 {
106106 return nil , xerrors .Errorf ("no specified image" )
107107 }
108108 url := fmt .Sprintf (saveURL , imageNames [0 ])
109- resp , err := p .c . Get ( url )
109+ resp , err := p .get ( ctx , url )
110110 if err != nil {
111111 return nil , xerrors .Errorf ("http error: %w" , err )
112112 }
113113 return resp .Body , nil
114114}
115115
116+ func (p podmanClient ) get (ctx context.Context , url string ) (* http.Response , error ) {
117+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , url , http .NoBody )
118+ if err != nil {
119+ return nil , err
120+ }
121+
122+ return p .c .Do (req )
123+ }
124+
116125// PodmanImage implements v1.Image by extending daemon.Image.
117126// The caller must call cleanup() to remove a temporary file.
118- func PodmanImage (ref , host string ) (Image , func (), error ) {
127+ func PodmanImage (ctx context. Context , ref , host string ) (Image , func (), error ) {
119128 cleanup := func () {}
120129
121130 c , err := newPodmanClient (host )
122131 if err != nil {
123132 return nil , cleanup , xerrors .Errorf ("unable to initialize Podman client: %w" , err )
124133 }
125- inspect , err := c .imageInspect (ref )
134+ inspect , err := c .imageInspect (ctx , ref )
126135 if err != nil {
127136 return nil , cleanup , xerrors .Errorf ("unable to inspect the image (%s): %w" , ref , err )
128137 }
129138
130- history , err := c .imageHistoryInspect (ref )
139+ history , err := c .imageHistoryInspect (ctx , ref )
131140 if err != nil {
132141 return nil , cleanup , xerrors .Errorf ("unable to inspect the image (%s): %w" , ref , err )
133142 }
@@ -143,7 +152,7 @@ func PodmanImage(ref, host string) (Image, func(), error) {
143152 }
144153
145154 return & image {
146- opener : imageOpener (context . Background () , ref , f , c .imageSave ),
155+ opener : imageOpener (ctx , ref , f , c .imageSave ),
147156 inspect : inspect ,
148157 history : configHistory (history ),
149158 }, cleanup , nil
0 commit comments