Skip to content

Commit

Permalink
chore: own context for checking images in local registry (#1839)
Browse files Browse the repository at this point in the history
## Description:
own context for checking images in local registry 

## Is this change user facing?
NO

## References (if applicable):
This is related to this ticket:
#1768
  • Loading branch information
leoporoli authored Nov 22, 2023
1 parent 43ff1c5 commit a95383d
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ func (manager *DockerManager) FetchImageIfMissing(ctx context.Context, dockerIma
dockerImage = dockerImage + dockerTagSeparatorChar + dockerDefaultTag
}
logrus.Tracef("Checking if image '%v' is available locally...", dockerImage)
doesImageExistLocally, err := manager.isImageAvailableLocally(ctx, dockerImage)
doesImageExistLocally, err := manager.isImageAvailableLocally(dockerImage)
if err != nil {
return false, stacktrace.Propagate(err, "An error occurred checking for local availability of Docker image '%v'", dockerImage)
}
Expand Down Expand Up @@ -1223,7 +1223,7 @@ func (manager *DockerManager) FetchLatestImage(ctx context.Context, dockerImage
dockerImage = dockerImage + dockerTagSeparatorChar + dockerDefaultTag
}
logrus.Tracef("Checking if image '%v' is available locally...", dockerImage)
doesImageExistLocally, err := manager.isImageAvailableLocally(ctx, dockerImage)
doesImageExistLocally, err := manager.isImageAvailableLocally(dockerImage)
if err != nil {
return stacktrace.Propagate(err, "An error occurred checking for local availability of Docker image '%v'", dockerImage)
}
Expand Down Expand Up @@ -1344,11 +1344,14 @@ func (manager *DockerManager) GetAvailableCPUAndMemory(ctx context.Context) (com
// INSTANCE HELPER FUNCTIONS
//
// =================================================================================================================
func (manager *DockerManager) isImageAvailableLocally(ctx context.Context, imageName string) (bool, error) {
func (manager *DockerManager) isImageAvailableLocally(imageName string) (bool, error) {
// Own context for checking if the image is locally available because we do not want to cancel this works in case the main context in the request is cancelled
// if the first request fails the image will be ready for following request making the process faster
checkImageAvailabilityCtx := context.Background()
referenceArg := filters.Arg("reference", imageName)
filterArgs := filters.NewArgs(referenceArg)
images, err := manager.dockerClient.ImageList(
ctx,
checkImageAvailabilityCtx,
types.ImageListOptions{
All: true,
Filters: filterArgs,
Expand Down

0 comments on commit a95383d

Please sign in to comment.