@@ -14,7 +14,7 @@ import (
14
14
15
15
"github.com/stacklok/toolhive/pkg/config"
16
16
"github.com/stacklok/toolhive/pkg/container"
17
- "github.com/stacklok/toolhive/pkg/container/runtime "
17
+ "github.com/stacklok/toolhive/pkg/container/images "
18
18
"github.com/stacklok/toolhive/pkg/container/verifier"
19
19
"github.com/stacklok/toolhive/pkg/logger"
20
20
"github.com/stacklok/toolhive/pkg/permissions"
@@ -268,12 +268,13 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
268
268
269
269
var server * registry.Server
270
270
271
+ imageManager := images .NewImageManager (ctx )
271
272
// Check if the serverOrImage is a protocol scheme, e.g., uvx://, npx://, or go://
272
273
if runner .IsImageProtocolScheme (serverOrImage ) {
273
274
logger .Debugf ("Detected protocol scheme: %s" , serverOrImage )
274
275
// Process the protocol scheme and build the image
275
276
caCertPath := resolveCACertPath (runCACertPath )
276
- generatedImage , err := runner .HandleProtocolScheme (ctx , rt , serverOrImage , caCertPath )
277
+ generatedImage , err := runner .HandleProtocolScheme (ctx , imageManager , serverOrImage , caCertPath )
277
278
if err != nil {
278
279
return fmt .Errorf ("failed to process protocol scheme: %v" , err )
279
280
}
@@ -302,7 +303,7 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
302
303
}
303
304
304
305
// Pull the image if necessary
305
- if err := pullImage (ctx , runConfig .Image , rt ); err != nil {
306
+ if err := pullImage (ctx , runConfig .Image , imageManager ); err != nil {
306
307
return fmt .Errorf ("failed to retrieve or pull image: %v" , err )
307
308
}
308
309
@@ -320,18 +321,18 @@ func runCmdFunc(cmd *cobra.Command, args []string) error {
320
321
// If the image has the latest tag, it will be pulled to ensure we have the most recent version.
321
322
// however, if there is a failure in pulling the "latest" tag, it will check if the image exists locally
322
323
// as it is possible that the image was locally built.
323
- func pullImage (ctx context.Context , image string , rt runtime. Runtime ) error {
324
+ func pullImage (ctx context.Context , image string , imageManager images. ImageManager ) error {
324
325
// Check if the image has the "latest" tag
325
326
isLatestTag := hasLatestTag (image )
326
327
327
328
if isLatestTag {
328
329
// For "latest" tag, try to pull first
329
330
logger .Infof ("Image %s has 'latest' tag, pulling to ensure we have the most recent version..." , image )
330
- err := rt .PullImage (ctx , image )
331
+ err := imageManager .PullImage (ctx , image )
331
332
if err != nil {
332
333
// Pull failed, check if it exists locally
333
334
logger .Infof ("Pull failed, checking if image exists locally: %s" , image )
334
- imageExists , checkErr := rt .ImageExists (ctx , image )
335
+ imageExists , checkErr := imageManager .ImageExists (ctx , image )
335
336
if checkErr != nil {
336
337
return fmt .Errorf ("failed to check if image exists: %v" , checkErr )
337
338
}
@@ -347,7 +348,7 @@ func pullImage(ctx context.Context, image string, rt runtime.Runtime) error {
347
348
} else {
348
349
// For non-latest tags, check locally first
349
350
logger .Debugf ("Checking if image exists locally: %s" , image )
350
- imageExists , err := rt .ImageExists (ctx , image )
351
+ imageExists , err := imageManager .ImageExists (ctx , image )
351
352
logger .Debugf ("ImageExists locally: %t" , imageExists )
352
353
if err != nil {
353
354
return fmt .Errorf ("failed to check if image exists locally: %v" , err )
@@ -358,7 +359,7 @@ func pullImage(ctx context.Context, image string, rt runtime.Runtime) error {
358
359
} else {
359
360
// Image doesn't exist locally, try to pull
360
361
logger .Infof ("Image %s not found locally, pulling..." , image )
361
- if err := rt .PullImage (ctx , image ); err != nil {
362
+ if err := imageManager .PullImage (ctx , image ); err != nil {
362
363
return fmt .Errorf ("failed to pull image: %v" , err )
363
364
}
364
365
logger .Infof ("Successfully pulled image: %s" , image )
0 commit comments