Skip to content
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

feat: copy directory to container #517

Merged
merged 13 commits into from
Sep 9, 2022

Conversation

mdelapenya
Copy link
Member

@mdelapenya mdelapenya commented Sep 5, 2022

What does this PR do?

It adds the CopyDirToContainer method to the container interface, implementing it for Docker.

This new method uses the standard library to tar the source directory and copy it to the container.

We have updated the existing CopyFileToContainer method to check if the host path passed is a directory, calling the new method if/when needed.

We have added unit tests for both the tar directory code and for the copy dir, updating the existing tests.

Finally the docs have been updated.

Why is it important?

First, feature parity with the tc-java project, which supports copying directories to containers.

Second, we detected this feature was missing while contributing to a demo where it needed to upload an entire directory to a place it does not exist in the target container, because the underlying Docker image did not have it on its file system. While trying to find the workaround to it, we identified that this could be a quick win for tc-go, so instead of doing the following workarounds:

  • creating a Dockerfile that, using the same Docker image, added the parent directory in a RUN instruction
  • rearrange the demo project to upload just one file

it would be much more simple to just upload the directory to its parent.

Examples

See the changes in the docs ar even the new tests to understand how to use it.

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner September 5, 2022 12:56
@mdelapenya mdelapenya added the feature New functionality or new behaviors on the existing one label Sep 5, 2022
@mdelapenya mdelapenya self-assigned this Sep 5, 2022
@codecov
Copy link

codecov bot commented Sep 5, 2022

Codecov Report

Merging #517 (09eb66e) into main (097f9af) will decrease coverage by 0.55%.
The diff coverage is 57.27%.

@@            Coverage Diff             @@
##             main     #517      +/-   ##
==========================================
- Coverage   69.67%   69.12%   -0.56%     
==========================================
  Files          21       22       +1     
  Lines        2048     2144      +96     
==========================================
+ Hits         1427     1482      +55     
- Misses        497      525      +28     
- Partials      124      137      +13     
Impacted Files Coverage Δ
container.go 80.72% <ø> (ø)
file.go 52.94% <52.94%> (ø)
docker.go 71.35% <72.00%> (+0.22%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

docker.go Show resolved Hide resolved
docs/features/copy_file.md Outdated Show resolved Hide resolved
docs/features/copy_file.md Outdated Show resolved Hide resolved
tar.go Outdated Show resolved Hide resolved
mdelapenya and others added 2 commits September 6, 2022 06:20
Co-authored-by: Eddú Meléndez Gonzales <[email protected]>
docker_test.go Outdated Show resolved Hide resolved
@mdelapenya mdelapenya merged commit cb9d7c8 into testcontainers:main Sep 9, 2022
@agaudreault
Copy link

@eddumelendez @kiview any plan to cut a release soon?

@mdelapenya
Copy link
Member Author

@eddumelendez @kiview any plan to cut a release soon?

Yes, we are very close to it 🙏 , sorry for the inconvenience 😞

We are closing just some bits for the internal ceremonies to release it to the public, so it will eventually happen really soon

@mdelapenya mdelapenya deleted the copy-dir-to-container branch October 3, 2022 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: support copying directories and files in the CopyToContainer method
3 participants