dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
MIT License
181 stars 39 forks source link

Registry push failed; received status code 'PreconditionFailed' #582

Open Varorbc opened 4 months ago

Varorbc commented 4 months ago

When I push multiple images, I receive a PreconditionFailederror. Can you add--skip-duplicateoption like nuget to treat the error as a warning so that other image packages can push successfully

baronfel commented 1 month ago

@Varorbc if you can reproduce this, could you add more error logging and/or a binlog so we can get a sense of how the pushes are failing specifically?

Varorbc commented 1 month ago

@baronfel

/dotnet/sdk/8.0.300/Containers/build/Microsoft.NET.Build.Containers.targets(242,5): error : Containerize: error CONTAINER004: CONTAINER1005: Registry push failed; received status code 'PreconditionFailed'. 
/dotnet/sdk/8.0.300/Containers/build/Microsoft.NET.Build.Containers.targets(242,5): error : URI: https://***/manifests/*** 
/dotnet/sdk/8.0.300/Containers/build/Microsoft.NET.Build.Containers.targets(242,5): error :    at Microsoft.NET.Build.Containers.DefaultManifestOperations.PutAsync(String repositoryName, String reference, ManifestV2 manifest, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/Registry/DefaultManifestOperations.cs:line 52 
/dotnet/sdk/8.0.300/Containers/build/Microsoft.NET.Build.Containers.targets(242,5): error :    at Microsoft.NET.Build.Containers.Registry.PushAsync(BuiltImage builtImage, SourceImageReference source, DestinationImageReference destination, Boolean pushTags, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/Registry/Registry.cs:line 491 
/dotnet/sdk/8.0.300/Containers/build/Microsoft.NET.Build.Containers.targets(242,5): error :    at Microsoft.NET.Build.Containers.Tasks.CreateNewImage.PushToRemoteRegistryAsync(BuiltImage builtImage, SourceImageReference sourceImageReference, DestinationImageReference destinationImageReference, CancellationToken cancellationToken) in /_/src/Containers/Microsoft.NET.Build.Containers/Tasks/CreateNewImage.cs:line 227 
baronfel commented 1 month ago

Sorry, another question - when you are pushing multiple images, are you pushing

My suspicion is that because the publish is done on a per-project basis there's the possibility that multiple projects have shared layers and pushing the same layer to the registry simultaneously is what's causing the failure.

If that's the case, then for multi-project publishes (i.e. at solution level or Traversal props level) we'd need a more sophisticated system than we have today. We'd have to create all of the specific layers and report them back to some central process that could deduplicate and push each layer at most once.

Varorbc commented 1 month ago

I'm pushing a bunch of app images that all have the same base image to the registry. Sometimes, things don't go perfectly smooth, and I end up only getting some of them pushed successfully while others fail. Now, when I try again, I get an error saying it failed because I've set up rules in Harbor to stop duplicate pushes. That's why I'm thinking it'd be sweet if we could add an option like --skip-duplicate that they use with NuGet pushes.