From b4ff2e4e35160c695725306f9d729a21293911e6 Mon Sep 17 00:00:00 2001 From: Jeff MAURY Date: Fri, 28 Jun 2024 11:43:59 +0200 Subject: [PATCH] fix: check if image is present before pulling (#1302) Fixes #1007 Signed-off-by: Jeff MAURY --- packages/backend/src/utils/inferenceUtils.ts | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/utils/inferenceUtils.ts b/packages/backend/src/utils/inferenceUtils.ts index 486a61026..94b631e38 100644 --- a/packages/backend/src/utils/inferenceUtils.ts +++ b/packages/backend/src/utils/inferenceUtils.ts @@ -70,18 +70,26 @@ export async function getImageInfo( callback: (event: PullEvent) => void, ): Promise { let imageInfo: ImageInfo | undefined; - try { - // Pull image - await containerEngine.pullImage(connection, image, callback); - // Get image inspect - imageInfo = ( - await containerEngine.listImages({ - provider: connection, - } as ListImagesOptions) - ).find(imageInfo => imageInfo.RepoTags?.some(tag => tag === image)); - } catch (err: unknown) { - console.warn('Something went wrong while trying to get image inspect', err); - throw err; + // Get image inspect + imageInfo = ( + await containerEngine.listImages({ + provider: connection, + } as ListImagesOptions) + ).find(imageInfo => imageInfo.RepoTags?.some(tag => tag === image)); + if (!imageInfo) { + try { + // Pull image + await containerEngine.pullImage(connection, image, callback); + // Get image inspect + imageInfo = ( + await containerEngine.listImages({ + provider: connection, + } as ListImagesOptions) + ).find(imageInfo => imageInfo.RepoTags?.some(tag => tag === image)); + } catch (err: unknown) { + console.warn('Something went wrong while trying to get image inspect', err); + throw err; + } } if (imageInfo === undefined) throw new Error(`image ${image} not found.`);