| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
I think it overlaps quite a lot with with_volume_mapping no?
Sorry, something went wrong.
|
the difference between mounting and copying is that one uses the linux file system, and the other uses a dedicated docker api where you can PUT a tar archive and docker engine un-tars for you inside the virtual file system of a running container, i think this addition blurs that distinction. going to leave open while we sort out a solution |
Sorry, something went wrong.
|
Found this wishing for copying, related comment in #676 (comment) Agree that mounting isn't copying, so the method shouldn't be called with_copy_file_to_container - while it could make sense as something like with_mount to make sure it's not confused with copying, since we already have both volume mapping and with_kwargs to use the mount API, I feel it isn't all that hard for a user to do it already without extra API. |
Sorry, something went wrong.
|
Do you still intend to move forward with this? I really need a way of inputting a config file into a test container. |
Sorry, something went wrong.
|
@oelhammouchi look at the code I wrote for with_copy_file_to_container, it is just one method that you can add in your project. |
Sorry, something went wrong.
|
@oelhammouchi If you're asking since you need actual copying instead of mounting, here's my current workaround. Note it relies on the container crashing when the file isn't present, which is probably common (in this case, it crashes while creds.json is being copied. # Roughly based on proposed logic in https://github.com/testcontainers/testcontainers-python/pull/676/files
def copy_file_to_container(container: DockerContainer, host_path: str, container_path: str, mode: int):
data = BytesIO()
def set_mode(tarinfo: tarfile.TarInfo):
tarinfo.mode = mode
return tarinfo
with tarfile.open(fileobj=data, mode='w') as tar:
tar.add(host_path, arcname=container_path, filter=set_mode)
data.seek(0)
if not container._container.put_archive('/', data):
raise Exception('Failed to copy file to container')
def main():
...
with (
DockerContainer('gcr.io/cloud-sql-connectors/cloud-sql-proxy:2.14.3')
.with_command(command)
.with_exposed_ports(5432, 9090)
.with_env(environment_vars.CREDENTIALS, '/creds/creds.json')
# Currently there is no way to copy a file before container starts, so we workaround by allowing the container
# to restart on failure, which will stop when the copy has completed.
# https://github.com/testcontainers/testcontainers-python/pull/676#discussion_r1934888327
.with_kwargs(restart_policy={'Name': 'on-failure', 'MaximumRetryCount': 100})
) as container:
copy_file_to_container(container, creds_path, '/creds/creds.json', 0o644) |
Sorry, something went wrong.
| self.volumes[host] = mapping | ||
| return self | ||
|
|
||
| def with_copy_file_to_container( |
There was a problem hiding this comment.
Even if this PR moves forward, I'd strongly advise against this name. This is mounting, not copying
Sorry, something went wrong.
There was a problem hiding this comment.
I agree. But I seem to recall there were discussions about following the Java conventions (or not).
Sorry, something went wrong.
|
if this is still needed (something is possible with this code and not possible with the version on the main branch) lets open a new pr with required changes |
Sorry, something went wrong.
As discussed in the linked issue (#665), this was not the right approach. Also, there is now a solution to do what I wanted (cf #665 (comment)). |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
I have created the issue #665 on which I proposed to implement it.
I have read the contribution guidelines.
The feature works fine, as you can see by the tests.
But I have some doubts about my solution.
I made some decisions that you may not agree with, so I'd like to have your feedback whether or not it suits you, so that I can fix this PR if required.
Thanks in advance 😃