Skip to content

Conversation

@HofmeisterAn
Copy link
Collaborator

@HofmeisterAn HofmeisterAn commented Oct 21, 2025

What does this PR do?

This PR fixes a regression. The Docker image build may fail on some builder configurations. The DockerfileArchive implementation fails to copy the Dockerfile to the correct path in the tarball, which results in a failed image build. Developers might see something like:

Cannot locate specified Dockerfile: <path-to-dockerfile>

Instead of copying the Dockerfile to the correct subdirectory, the DockerfileArchive implementation mistakenly copied it to the root of the tarball. This happened because the relative path for the Dockerfile inside the tarball was computed incorrectly.

Why is it important?

This change is necessary to fix the Docker image build.

Related issues

@HofmeisterAn HofmeisterAn added the bug Something isn't working label Oct 21, 2025
@netlify
Copy link

netlify bot commented Oct 21, 2025

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit eb97a08
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/68f85c29fc0bd900085cf312
😎 Deploy Preview https://deploy-preview-1558--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Oct 21, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Fixed Dockerfile path handling to correctly preserve subdirectory paths in tar archives, ensuring Docker images build properly when Dockerfiles are located in non-root directories.

Walkthrough

Bumps package version to 4.8.1 and fixes Dockerfile path handling when creating tar archives by computing a Unix-style relative path for Dockerfile entries. Adds a unit test to verify subdirectory Dockerfile paths are preserved in the tarball.

Changes

Cohort / File(s) Summary
Version Update
Directory.Build.props
Bumped package Version from 4.8.0 to 4.8.1.
Dockerfile Tar Creation
src/Testcontainers/Images/DockerfileArchive.cs
Compute Dockerfile's relative path (relative to its directory), normalize to Unix separators, and use that as the TarEntry name when writing the Dockerfile into the tarball.
Unit Test
tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs
Added IgnoredDockerfileIsCopiedToTarball() to assert Dockerfiles in subdirectories are archived with their subdirectory path (e.g., target/Dockerfile) and not placed at the tar root.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Unit Test
    participant Archive as DockerfileArchive
    participant Tar as TarWriter

    Note over Test,Archive: Create DockerfileArchive with Dockerfile in subdir
    Test->>Archive: Request tar creation
    Archive->>Archive: Collect files\nCompute Dockerfile directory\nCompute relative path\nNormalize to Unix separators
    Archive->>Tar: Write TarEntry with normalized relative path
    Tar-->>Archive: Tar entry written
    Archive-->>Test: Return tar stream
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Hop hop, paths aligned and neat,
Dockerfiles march in orderly feet,
Slashes Unix‑true, no rootless roam,
Safely nested, each finds its home.
Version raised — four-point-eight-point-one, hooray! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title "fix: Compute correct relative Dockerfile file path" is fully related to the main change in the changeset. It accurately and specifically describes the primary fix implemented in DockerfileArchive.cs, where the relative path for the Dockerfile inside the tarball is now computed correctly. The title is concise and clear enough for teammates scanning history to understand that this PR addresses a path computation bug without being overly vague or broad.
Description Check ✅ Passed The PR description successfully includes both mandatory sections from the template. "What does this PR do?" clearly explains the regression and the specific problem—the Dockerfile being copied to the root of the tarball instead of the correct subdirectory due to incorrect relative path computation. "Why is it important?" explains the necessity of fixing the Docker image build. The description also includes the recommended "Related issues" section with issue #1557 linked. While the optional "How to test this PR" and "Follow-ups" sections are not provided, the mandatory and recommended sections contain sufficient detail for reviewers to understand the changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/use-correct-relative-dockerfile-file-path

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cfe690a and eb97a08.

📒 Files selected for processing (1)
  • src/Testcontainers/Images/DockerfileArchive.cs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Testcontainers/Images/DockerfileArchive.cs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (60)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Bigtable, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Cassandra, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ActiveMq, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.BigQuery, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Azurite, ubuntu-24.04)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@HofmeisterAn HofmeisterAn changed the title Bugfix/use correct relative dockerfile file path fix: Compute correct relative Dockerfile file path Oct 21, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Testcontainers/Images/DockerfileArchive.cs (1)

216-217: Consider renaming for clarity and consistency.

The variable dockerfileDirectoryPath stores a length value, not a path. For consistency with the existing pattern on line 186 (baseDirectoryLength), consider renaming to dockerfileDirectoryLength or dockerfileDirectoryBaseLength.

-          var dockerfileDirectoryPath = _dockerfileDirectory.FullName
+          var dockerfileDirectoryLength = _dockerfileDirectory.FullName
             .TrimEnd(Path.DirectorySeparatorChar).Length + 1;

           var dockerfileRelativeFilePath = _dockerfile.FullName
-            .Substring(dockerfileDirectoryPath);
+            .Substring(dockerfileDirectoryLength);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cfac50 and cfe690a.

📒 Files selected for processing (3)
  • Directory.Build.props (1 hunks)
  • src/Testcontainers/Images/DockerfileArchive.cs (1 hunks)
  • tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/Testcontainers/Images/DockerfileArchive.cs (1)
src/Testcontainers/Configurations/Unix.cs (2)
  • Unix (67-69)
  • NormalizePath (120-123)
tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs (1)
src/Testcontainers/Images/DockerfileArchive.cs (3)
  • DockerfileArchive (19-327)
  • DockerfileArchive (51-70)
  • DockerfileArchive (83-109)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (98)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MsSql, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MsSql, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ArangoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Ollama, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Ollama, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CouchDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Ollama, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CouchDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CockroachDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.CosmosDb, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Couchbase, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.ClickHouse, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Consul, ubuntu-24.04)
  • GitHub Check: analyze (csharp)
  • GitHub Check: ci (Testcontainers.Neo4j, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Ollama, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.Nats, ubuntu-24.04)
  • GitHub Check: ci (Testcontainers.MongoDb, ubuntu-24.04)
🔇 Additional comments (3)
Directory.Build.props (1)

5-5: LGTM! Version bump aligns with bugfix release.

The version increment from 4.8.0 to 4.8.1 is appropriate for a bugfix release addressing the Dockerfile path regression.

src/Testcontainers/Images/DockerfileArchive.cs (1)

216-225: Excellent fix for the Dockerfile path regression!

The logic correctly computes the relative path from the Dockerfile directory to the Dockerfile file, ensuring subdirectory structure is preserved in the tar archive (e.g., target/Dockerfile instead of just Dockerfile at root). The Unix path normalization ensures cross-platform compatibility.

tests/Testcontainers.Tests/Unit/Images/ImageFromDockerfileTest.cs (1)

81-113: Well-structured regression test!

The test effectively verifies that Dockerfiles in subdirectories are preserved at their correct relative paths in the tarball. The assertions clearly validate the fix, and the issue reference provides good context. The required test asset file exists at tests/Testcontainers.Tests/Assets/target/Dockerfile.

@HofmeisterAn HofmeisterAn merged commit 2e32476 into develop Oct 22, 2025
140 checks passed
@HofmeisterAn HofmeisterAn deleted the bugfix/use-correct-relative-dockerfile-file-path branch October 22, 2025 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ImageFromDockerfileBuilder breaking change in 4.8.0

2 participants