GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: add copying files to/from container by mgorsk1 · Pull Request #676 · testcontainers/testcontainers-python Conversation
Contributor
solves #665
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Member
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
do we need it to be 1:1 with java implementation though? any binary object now can be passed here using tempfile.NamedTemporaryObject: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
we dont need to be 1-1 but what if instead of a file you had a string? i think it is beneficial to not force people to create temporary files. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
refactored for Transferable although creating temp files cannot be avoided, now instead of asking users for 3 extra lines we add some complexity to codebase here. working example input: output |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@mgorsk1 I have opened #677 to solve the same issue (I did not see you already had opened one 😓).
Are our two approaches complementary ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think copying before can already be solved by with_volume_mapping 😅 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
e5a2325 to
a2f6094
Compare
Signed-off-by: mgorsk1 <[email protected]>
Signed-off-by: mgorsk1 <[email protected]>
|
committed some code here - main...feat/665-with-copy-file-to-container |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
rebased here https://github.com/testcontainers/testcontainers-python/compare/feat/665-with-copy-file-to-container_rebased |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
since this is not a high priority feature this can probably wait for 1) more api refinement - feedback welcomed on my suggestions above 2) more of my free time, as I'm not sure ill be able to spend too much more time on this this week (just spent my entire week's time budget on this today). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| logger.info("Container started: %s", self._container.short_id) | ||
|
|
||
| for transferable in self._files: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I found this PR noticing that copying files isn't supported, a bit surprising since it's a pretty important one and found in at least many of the other languages.
I noticed this implementation doesn't seem to match others, though this is probably because of how the general docker running is implemented. Generally, the container is created, then files copied, then the container started, so the files are present when the command runs.
Here, the files are just copied after startup so can't be used by the entrypoint - perhaps there's some use case for this but I don't know how common it is. Note that volume mounting is an alternative but doesn't always work due to e.g. permission mode issues - copying is generally more robust.
Given the behavior would be so different from other implementations of testcontainers, I think this PR can cause a lot of confusion so probably needs to rework the lifecycle like that.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Making this happen during start doesn't feel like the right interface here. While there's definitely good reasons to copy in files just after it starts, as proposed here that is the only time we can copy files into the container.
I'd propose instead creating a copy_file_into_container, which would basically be the inverse of copy_file_from_container proposed above. It could be implemented by simply calling get_archive, but provide an interface which used os.PathLike.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| data = io.BytesIO() | ||
|
|
||
| with transferable as f, tarfile.open(fileobj=data, mode="w") as tar: | ||
| tar.add(f.input_path, arcname=f.output_path) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
IIUC, the temporary file could be avoided if using tar.addfile - it is somewhat more tedious to set up a TarInfo but maybe worth it to skip the temp file
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Also, I think all the copy_file APIs in testcontainers accept a file mode. With the current pattern, it can be something like filter=lambda tarinfo: tarinfo.mode = foo, but if switching to addfile it could be set directly to the TarInfo
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In #676 for copying to/from `DockerContainer`, it was suggested that we should clarify the interface & usage a bit before proceeding. This PR aims to push that conversation forward with some test cases illustrating proposed usages. Although here I created a `Transferable` object, in most cases there's no need for the caller to explicitly construct a Transferable, just pass the `bytes | Path` **Proposed use cases:** 1. Copy into a container by passing a `TransferSpec` into the initializer: ``` DockerContainer(... transferrables=[TransferSpec(source, destination_in_container), ...) ``` 2. Copy into the container via the builder pattern, prior to starting the container: ``` DockerContainer(...) .with_copy_into_container(b"some_bytes", destination_in_container) .with_copy_into_container(some_path, destination_in_container) ``` 3. Copy into the container at runtime: ``` with DockerContainer(...) as container: container.copy_into_container(b"some_bytes", destination_in_container) container.copy_into_container(some_path, destination_in_container) ``` --------- Co-authored-by: Roy Moore <[email protected]>
|
Hi, just a quick checkup, is this still relevant now that we have |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
At least 1 approving review is required to merge this pull request.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.