Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: own context for checking images in local registry #1839

Merged
merged 11 commits into from
Nov 22, 2023
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
leoporoli marked this conversation as resolved.
Show resolved Hide resolved
// 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