Created
December 24, 2018 08:17
-
-
Save Pvlerick/0bc6c762733d40bad7138b1a4d9dc3a2 to your computer and use it in GitHub Desktop.
DockerClientExtensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text.RegularExpressions; | |
using System.Threading.Tasks; | |
using Docker.DotNet; | |
using Docker.DotNet.Models; | |
public static class DockerClientExtensions | |
{ | |
public static async Task WaitForLogMessage(this DockerClient client, string containerId, string pattern, TimeSpan readDelay) | |
{ | |
var buffer = new byte[1024]; | |
for (int i = 0; i < 120; i++) | |
{ | |
var stream = await client.Containers.GetContainerLogsAsync(containerId, new ContainerLogsParameters { ShowStdout = true, ShowStderr = true }); | |
var count = await stream.ReadAsync(buffer); | |
var logs = System.Text.Encoding.UTF8.GetString(buffer, 0, count); | |
if (count > 0 && Regex.IsMatch(logs, pattern)) | |
break; | |
await Task.Delay(readDelay); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment