Skip to content

Commit

Permalink
fix: Check if Dockerfile exists
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Jul 25, 2023
1 parent cbf4773 commit 053a9f5
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Testcontainers/Clients/TestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,22 +319,24 @@ await Task.WhenAll(configuration.ResourceMappings.Values.Select(resourceMapping
/// <inheritdoc />
public async Task<string> BuildAsync(IImageFromDockerfileConfiguration configuration, CancellationToken ct = default)
{
var dockerfileFilePath = Path.Combine(configuration.DockerfileDirectory, configuration.Dockerfile);

var cachedImage = await Image.ByNameAsync(configuration.Image.FullName, ct)
.ConfigureAwait(false);

if (configuration.ImageBuildPolicy(cachedImage))
if (File.Exists(dockerfileFilePath))
{
var pullDependedImageTasks = File.ReadAllLines(Path.Combine(configuration.DockerfileDirectory, configuration.Dockerfile))
await Task.WhenAll(File.ReadAllLines(dockerfileFilePath)
.Select(line => FromLinePattern.Match(line))
.Where(match => match.Success)
.Select(match => match.Groups["image"])
.Select(group => group.Value)
.Select(image => new DockerImage(image))
.Select(image => PullImageAsync(image, ct));

await Task.WhenAll(pullDependedImageTasks)
.ConfigureAwait(false);
.Select(image => PullImageAsync(image, ct)));
}

if (configuration.ImageBuildPolicy(cachedImage))
{
_ = await Image.BuildAsync(configuration, ct)
.ConfigureAwait(false);
}
Expand Down

0 comments on commit 053a9f5

Please sign in to comment.