Browse Source

DockerImagePuller checks the installed images first (#281)

* DockerImagePuller checks if the images is already installed before pull it

* Use --filter and --format options to filter and format the output docker images command

* Optimize usings

* Remove unused variable

* Improve PullContainerAsync implementation and also throws CommandException if docker images command failed

* Improve the approach to determine if it's installed and print the output of this command images in case of failure
davidfowl/build-earlier
Igr Alexánder Fernández Saúco 7 years ago
committed by GitHub
parent
commit
ce95d1b8ba
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/Microsoft.Tye.Hosting/DockerImagePuller.cs

31
src/Microsoft.Tye.Hosting/DockerImagePuller.cs

@ -2,9 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Tye.Hosting.Model;
@ -66,16 +64,33 @@ namespace Microsoft.Tye.Hosting
{
await Task.Yield();
var result = await ProcessUtil.RunAsync(
"docker",
$"images --filter \"reference={image}\" --format \"{{{{.ID}}}}\"",
throwOnError: false);
if (result.ExitCode != 0)
{
_logger.LogInformation("{Image}: " + result.StandardError, image);
throw new CommandException("Docker images command failed");
}
if (!string.IsNullOrWhiteSpace(result.StandardOutput))
{
_logger.LogInformation("Docker image {image} already installed", image);
return;
}
var command = $"pull {image}";
_logger.LogInformation("Running docker command {command}", command);
var result = await ProcessUtil.RunAsync(
"docker",
command,
outputDataReceived: data => _logger.LogInformation("{Image}: " + data, image),
errorDataReceived: data => _logger.LogInformation("{Image}: " + data, image),
throwOnError: false);
result = await ProcessUtil.RunAsync(
"docker",
command,
outputDataReceived: data => _logger.LogInformation("{Image}: " + data, image),
errorDataReceived: data => _logger.LogInformation("{Image}: " + data, image),
throwOnError: false);
if (result.ExitCode != 0)
{

Loading…
Cancel
Save