-
-
Notifications
You must be signed in to change notification settings - Fork 341
fix: Compute correct relative Dockerfile file path #1558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Compute correct relative Dockerfile file path #1558
Conversation
✅ Deploy Preview for testcontainers-dotnet ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Summary by CodeRabbit
WalkthroughBumps 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
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. Comment |
There was a problem hiding this 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
dockerfileDirectoryPathstores a length value, not a path. For consistency with the existing pattern on line 186 (baseDirectoryLength), consider renaming todockerfileDirectoryLengthordockerfileDirectoryBaseLength.- 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
📒 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/Dockerfileinstead of justDockerfileat 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.
What does this PR do?
This PR fixes a regression. The Docker image build may fail on some builder configurations. The
DockerfileArchiveimplementation fails to copy the Dockerfile to the correct path in the tarball, which results in a failed image build. Developers might see something like:Instead of copying the Dockerfile to the correct subdirectory, the
DockerfileArchiveimplementation 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
ImageFromDockerfileBuilderbreaking change in4.8.0#1557