Skip to content

Commit

Permalink
fix(#610): Do not deny all files in the Docker image tarball when a .…
Browse files Browse the repository at this point in the history
…dockerignore entry ends with /*
  • Loading branch information
HofmeisterAn committed Oct 20, 2022
1 parent 480fc82 commit 54db492
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
- 525 Read ServerURL, Username and Secret field from CredsStore response to pull private Docker images
- 595 Implement `TestcontainersContainer.DisposeAsync` thread safe (rename `TestcontainersState` to `TestcontainersStates`)
- 604 Do not deny all files in the Docker image tarball when a `.dockerignore` entry ends with `/`
- 610 Do not deny all files in the Docker image tarball when a `.dockerignore` entry ends with `/*`

## [2.1.0]

Expand Down
10 changes: 10 additions & 0 deletions src/Testcontainers/Images/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public IgnoreFile(IEnumerable<string> patterns, ILogger logger)
// Trim each line.
.Select(line => line.Trim())

// Exclude files and directories.
.Select(line => line.TrimEnd('/'))

// Exclude files and directories.
.Select(line =>
{
const string filesAndDirectories = "/*";
return line.EndsWith(filesAndDirectories, StringComparison.InvariantCulture) ? line.Substring(0, line.Length - filesAndDirectories.Length) : line;
})

// Remove empty line.
.Where(line => !string.IsNullOrEmpty(line))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public sealed class IgnoreFileFixture : TheoryData<IgnoreFile, string, bool>
public IgnoreFileFixture()
{
var logger = TestcontainersSettings.Logger;
var ignoreDirectory = new IgnoreFile(new[] { "bin/", "obj/" }, logger);
var ignoreFilesAndDirectories = new IgnoreFile(new[] { "bin/", "obj/*" }, logger);
var ignoreNonRecursiveFiles = new IgnoreFile(new[] { "*/temp*" }, logger);
var ignoreNonRecursiveNestedFiles = new IgnoreFile(new[] { "*/*/temp*" }, logger);
var ignoreRecursiveFiles = new IgnoreFile(new[] { "**/*.txt" }, logger);
var ignoreSingleCharacterFiles = new IgnoreFile(new[] { "temp?" }, logger);
var ignoreExceptionFiles = new IgnoreFile(new[] { "*.md", "!README*.md", "README-secret.md" }, logger);
this.Add(ignoreDirectory, "Testcontainers.sln", true);
this.Add(ignoreDirectory, "bin/Debug/net6.0", false);
this.Add(ignoreDirectory, "obj/Debug/net6.0", false);
this.Add(ignoreFilesAndDirectories, "bin/Debug/net6.0", false);
this.Add(ignoreFilesAndDirectories, "obj/Debug/net6.0", false);
this.Add(ignoreFilesAndDirectories, "Testcontainers.sln", true);
this.Add(ignoreNonRecursiveFiles, "lipsum/temp", false);
this.Add(ignoreNonRecursiveFiles, "lipsum/temp.txt", false);
this.Add(ignoreNonRecursiveFiles, "lipsum/lorem/temp", true);
Expand Down

0 comments on commit 54db492

Please sign in to comment.