dotnet / docker-tools

This is a repo to house some common tools for our various docker repos.
MIT License
124 stars 46 forks source link

generateEolAnnotationData: handle missing image info files #1442

Closed mthalman closed 1 month ago

mthalman commented 1 month ago

There can be scenarios where the pipeline ends up not publishing any images. This is true in the case of PR builds, for example, where all the images are cached (see example build). This means that no image info files are output by the publishImageInfo command. This then causes a failure in the generateEolAnnotationData because these image info files are expected to exist:

Unhandled exception: System.IO.FileNotFoundException: Could not find file '/artifacts/eol-annotation-data/image-info-old.json'.
File name: '/artifacts/eol-annotation-data/image-info-old.json'
   at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirError)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, UnixFileMode openPermissions, Int64& fileLength, UnixFileMode& filePermissions, Boolean failForSymlink, Boolean& wasSymlink, Func`4 createOpenException)
   at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
   at System.IO.StreamReader.ValidateArgsAndOpenPath(String path, Encoding encoding, Int32 bufferSize)
   at System.IO.File.ReadAllText(String path, Encoding encoding)
   at Microsoft.DotNet.ImageBuilder.ImageInfoHelper.DeserializeImageArtifactDetails(String path) in /image-builder/src/ImageInfoHelper.cs:line 117
   at Microsoft.DotNet.ImageBuilder.Commands.GenerateEolAnnotationDataCommand.GetDigestsToAnnotate() in /image-builder/src/Commands/GenerateEolAnnotationDataCommand.cs:line 78
   at Microsoft.DotNet.ImageBuilder.Commands.GenerateEolAnnotationDataCommand.<ExecuteAsync>b__11_0() in /image-builder/src/Commands/GenerateEolAnnotationDataCommand.cs:line 59
   at Microsoft.DotNet.ImageBuilder.RegistryCredentialsProviderExtensions.ExecuteWithCredentialsAsync(IRegistryCredentialsProvider credsProvider, Boolean isDryRun, Func`1 action, RegistryCredentialsOptions credentialsOptions, String registryName, String ownedAcr) in /image-builder/src/RegistryCredentialsProviderExtensions.cs:line 30
   at Microsoft.DotNet.ImageBuilder.Commands.GenerateEolAnnotationDataCommand.ExecuteAsync() in /image-builder/src/Commands/GenerateEolAnnotationDataCommand.cs:line 57

This is fixed by specifically checking whether the files exist, and skipping the processing if they do not. A message is logged in this case for diagnostics. I also added some more logging to the command.

dotnet-issue-labeler[bot] commented 1 month ago

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 1 month ago

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.