Repository navigation
feat: support copy files to container - #730
Conversation
✅ Deploy Preview for testcontainers-rust ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Hi there 👋
Thank you a lot for the contribution 👍
However it would be nice to rationalize the need and discuss the proposal before putting an effort 🙏
So, I guess mountfunctionality doesn't cover your needs? You want a full independent copy of files, right? So we will have both mounting and copy features (like in Java version)
|
Hi, the rational behind is specially when using Docker In Docker environments with the docker-socket mounted. Here, copying files to the container instead of mounting them is way easier and less error prone. This is one of the main reasons why this is needed. |
I actually think it's a useful feature, so I don't mind for sure. That's why I prefer to have at least a short issue to have visibility |
|
Completely understandable. Next time, I'll raise an issue first for discussion. |
|
Just to chime in quickly from a meta Testcontainers perspective: |
|
Thanks for all the help. I realy appreciate your effort. |
## 🤖 New release * `testcontainers`: 0.22.0 -> 0.23.0 (⚠️ API breaking changes) ###⚠️ `testcontainers` breaking changes ``` --- failure enum_variant_added: enum variant added on exhaustive enum --- Description: A publicly-visible enum without #[non_exhaustive] has a new variant. ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.35.0/src/lints/enum_variant_added.ron Failed in: variant ClientError:UploadToContainerError in /tmp/.tmpnaUdoG/testcontainers-rs/testcontainers/src/core/client.rs:92 variant ClientError:CopyToContainerError in /tmp/.tmpnaUdoG/testcontainers-rs/testcontainers/src/core/client.rs:94 --- failure trait_method_added: pub trait method added --- Description: A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.35.0/src/lints/trait_method_added.ron Failed in: trait method testcontainers::core::ImageExt::with_copy_to in file /tmp/.tmpnaUdoG/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:62 trait method testcontainers::ImageExt::with_copy_to in file /tmp/.tmpnaUdoG/testcontainers-rs/testcontainers/src/core/image/image_ext.rs:62 ``` <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.23.0] - 2024-09-25 ### Details #### Bug Fixes - Expose public `copy` types ([#734](#734)) - Typo in an error variant ([#738](#738)) #### Features - Support copy files to container ([#730](#730)) - Support copying directories to container ([#735](#735)) #### Miscellaneous Tasks - Copy-to-container interface improvements ([#732](#732)) #### Refactor - Replace dirs crate with etcetera ([#736](#736)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/MarcoIeni/release-plz/). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR supports copying files into the container before startup time:
```python
DockerContainer("alpine")
.with_command(["cat", "/tmp/copied.txt"])
.with_copy_into_container(src, "/tmp/copied.txt")
```
To support this, I had to change how the container is started: `run` is
not longer used, but instead `create` and `start` are used now, in order
to be able to make the `copy` before the container is actually running.
Inspired by testcontainers/testcontainers-rs#730
where I did exactly the same feature for the rust implementation of
testcontainers :)
----
No tests are failing
```bash
> uv run pytest -v core/tests
...
======================================= 316 passed, 1 skipped in 160.87s (0:02:40) ========================================
```
Co-authored-by: David Ankin <[email protected]>
This PR supports copying files into the container like this: