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

Delete image for current task only. #650

Merged
merged 7 commits into from
Apr 26, 2024
Merged

Delete image for current task only. #650

merged 7 commits into from
Apr 26, 2024

Conversation

jsaun
Copy link
Contributor

@jsaun jsaun commented Mar 21, 2024

Fixes: #688

@MattMcL4475
Copy link
Collaborator

Team conclusion: just delete the task's Docker image (instead of listing all and deleting just that one)

@jsaun jsaun marked this pull request as ready for review April 25, 2024 22:36
@jsaun jsaun requested review from MattMcL4475 and BMurri April 25, 2024 22:36
throw;
}
}
await dockerClient.Images.DeleteImageAsync(imageName, new ImageDeleteParameters { Force = true });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work as expected? I thought it needed the image.ID, which I didn't think was the same as imageName

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it works, the trick was to get the container object and then use that to get the image name. The delete api will accept either the image sha or an image name with tag, however if you try executionOptions.ImageName it won't work sometimes for images with a "latest" tag. When you pull it dcoker does the substitution from ubuntu:latest to ubuntu:22.04 so you can't delete by calling delete on ubuntu:latest. (I would think it should keep both tags, but it doesn't seem to via the api at least)

}
catch (Exception e)
{
logger.LogError(e, "Exception in DeleteAllImagesAsync");
throw;
logger.LogWarning(@"Failed to delete image {ImageName}. Error: {ErrorMessage}", imageName, e.Message);
Copy link
Collaborator

@MattMcL4475 MattMcL4475 Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked the logs to ensure this is not written? How did you test to see if the image was actually deleted? (or checked to see if the Informational log above was written)

Copy link
Contributor Author

@jsaun jsaun Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I downloaded the tes runner logs and confirmed it printed " Deleted Docker image ". Since we're only deleting the task image, actually I should probably add the throw back in.

@jsaun jsaun changed the title Don't throw image deletion exception Delete image for current task only. Apr 26, 2024
@MattMcL4475 MattMcL4475 self-requested a review April 26, 2024 23:01
@jsaun jsaun merged commit dc5bff2 into main Apr 26, 2024
9 checks passed
@jsaun jsaun deleted the jsaun/fix-image-delete branch April 26, 2024 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Only delete task docker image
2 participants