Skip to content

Commit

Permalink
fix: Trim relative path indicators from Dockerfile path (#1203)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Jun 22, 2024
1 parent 7ecd79e commit a0f1f76
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Testcontainers/Builders/ImageFromDockerfileBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace DotNet.Testcontainers.Builders
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Docker.DotNet.Models;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Images;
Expand Down Expand Up @@ -65,7 +66,8 @@ public ImageFromDockerfileBuilder WithName(IImage name)
/// <inheritdoc />
public ImageFromDockerfileBuilder WithDockerfile(string dockerfile)
{
return Merge(DockerResourceConfiguration, new ImageFromDockerfileConfiguration(dockerfile: dockerfile));
var dockerfileFilePath = Regex.Replace(dockerfile, "^\\.(\\/|\\\\)", string.Empty, RegexOptions.None, TimeSpan.FromSeconds(1));
return Merge(DockerResourceConfiguration, new ImageFromDockerfileConfiguration(dockerfile: dockerfileFilePath));
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ public async Task ThrowsDockerfileDirectoryDoesNotExist()
Assert.Equal($"Directory '{Path.GetFullPath(dockerfileDirectory)}' does not exist.", exception.Message);
}

[Fact]
public async Task BuildsDockerImage()
[Theory]
[InlineData("Dockerfile")]
[InlineData("./Dockerfile")]
[InlineData(".\\Dockerfile")]
public async Task BuildsDockerImage(string dockerfile)
{
// Given
IImage tag1 = new DockerImage("localhost/testcontainers", Guid.NewGuid().ToString("D"), string.Empty);
Expand All @@ -110,7 +113,7 @@ public async Task BuildsDockerImage()

var imageFromDockerfileBuilder = new ImageFromDockerfileBuilder()
.WithName(tag1)
.WithDockerfile("Dockerfile")
.WithDockerfile(dockerfile)
.WithDockerfileDirectory("Assets/")
.WithDeleteIfExists(true)
.WithCreateParameterModifier(parameterModifier => parameterModifier.Tags.Add(tag2.FullName))
Expand Down

0 comments on commit a0f1f76

Please sign in to comment.