Image.PushImagesAsync does not return anything nor does it throw any exceptions if you try to push a non-existent image. Instead we have to monitor the Progress callback for any error messages. The only way i've found to make sure that no errors have occurred is to introduce a private variable, and wait for a while after _client.Images.PushImageAsync returns to make sure the thread that updates the callback has completed.
Is there any better way of doing this? Ideally _client.Images.PushImageAsync would throw an exception itself if something goes wrong.
private bool _pushImageError = false;
public async Task PushImageAsync( string imageName )
{
_pushImageError = false;
Progress<JSONMessage> progress = new(i =>
{
if( i.ErrorMessage != null )
{
_pushImageError = true;
_logger.LogWarning( "Problem when pushing image to registry {ErrorMessage}", i.ErrorMessage );
}
});
await _client.Images.PushImageAsync( imageName, new ImagePushParameters(), new AuthConfig(), progress );
await Task.Delay( 1000 );
if( _pushImageError ) throw new Exception( "Could not push image" );
_logger.LogInformation( "Pushed image {Image} to repository", imageName );
}
Output of
dotnet --info
:What version of Docker.DotNet?:
Image.PushImagesAsync does not return anything nor does it throw any exceptions if you try to push a non-existent image. Instead we have to monitor the Progress callback for any error messages. The only way i've found to make sure that no errors have occurred is to introduce a private variable, and wait for a while after _client.Images.PushImageAsync returns to make sure the thread that updates the callback has completed.
Is there any better way of doing this? Ideally _client.Images.PushImageAsync would throw an exception itself if something goes wrong.