Closed Hogedal closed 4 months ago
Removing the 5 exception lines at the bottom resolves the issue, but that may not be a viable solution in all cases.
I do not understand why you do not want to exclude the entire Git from your .dockerignore
. Can you please change !.git/refs/heads/**
to !.git/refs/heads/
and try it again? According to the Glob Tool, this line matches everything, which is how the implementation works.
I do not understand why you do not want to exclude the entire Git from your
.dockerignore
.
I don't really have a specific need to do so, but that's part of the .dockerignore
file that visual studio generates when you add docker support to a project. It took a fair bit of time to track down the cause of this error, in large part because we expected that the library aught to play nicely with the "default" .dockerignore
.
Can you please change
!.git/refs/heads/**
to!.git/refs/heads/
and try it again? According to the [Glob Tool], this line matches everything, which is how the implementation works.
It does appear to work with just this change, thank you.
I looked into it, and it is not difficult to reproduce. It appears that the globstar (**
) at the end of the negate pattern (!.git/refs/heads/**
) adds ^([\\\/]?((.+)\b|$))
to the regex cache (which matches everything) and overrides (negates) the previous configurations (1, 2).
[Theory]
[ClassData(typeof(DockerignoreTestData))]
public void Issue1119(IEnumerable<string> patterns)
{
// Given
const string file = "src/.vs/Andel.Energi.GSOF/v17/TestStore/0/002.testlog";
var ignoreFile = new IgnoreFile(patterns, NullLogger.Instance);
// When
var denies = ignoreFile.Denies(file);
// Then
Assert.True(denies);
}
private sealed class DockerignoreTestData : TheoryData<IEnumerable<string>>
{
public DockerignoreTestData()
{
Add(["**/.vs"]);
Add(["**/.vs", "!.git/refs/heads/**"]);
}
}
I believe I have found the root cause of the issue. It appears we split paths (directory separators) too eager and add too many regular expressions to the cache. Thanks for shareing. I need to do a few more tests, but I think I can create a PR soon.
Testcontainers version
3.7.0
Using the latest Testcontainers version?
Yes
Host OS
windows
Host arch
x64
.NET version
8.0.0
Docker version
Docker info
What happened?
I am attempting to build a new container image on the fly as such:
And I have a visual studio generated .dockerignore which looks like this
If I try to run this container with that dockerignore I get an error relating to a file in the .vs folder already being in use, despite **/.vs being in the ignore list. Removing the 5 exception lines at the bottom resolves the issue, but that may not be a viable solution in all cases.
Relevant log output
Additional information
No response