testcontainers / testcontainers-rs

A library for integration-testing against docker containers from within Rust.
https://rust.testcontainers.org
Apache License 2.0
745 stars 142 forks source link

feat: support copy files to container #730

Closed guenhter closed 1 month ago

guenhter commented 1 month ago

This PR supports copying files into the container like this:

let container = GenericImage::new("alpine", "latest")
        .with_wait_for(WaitFor::seconds(2))
        .with_copy_to("/tmp/somefile", "foobar".to_string().into_bytes())
        .start()
        .await?;
netlify[bot] commented 1 month ago

Deploy Preview for testcontainers-rust ready!

Name Link
Latest commit 424902902d756426299dbb2e327cc561b4f16580
Latest deploy log https://app.netlify.com/sites/testcontainers-rust/deploys/66e2922e737ec80008eade49
Deploy Preview https://deploy-preview-730--testcontainers-rust.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 site configuration.

guenhter commented 1 month ago

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.

DDtKey commented 1 month ago

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. It's just always a shame and sad that a person has made a lot of effort, but the PR is not accepted for some other reason

That's why I prefer to have at least a short issue to have visibility

guenhter commented 1 month ago

Completely understandable. Next time, I'll raise an issue first for discussion.

kiview commented 1 month ago

Just to chime in quickly from a meta Testcontainers perspective: Copy file is indeed preferred over mounting (and available as an API in other languages as well, in Java we even deprecated the mounting API, in favor of the copy API), exactly because of the reasons outlined by @guenhter. The copy approach is extremely portable across all kind of different Docker setup (e.g. socket mounting, or remote Docker daemon).

guenhter commented 1 month ago

Thanks for all the help. I realy appreciate your effort.