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(core): add mount files when starting a container by Lenormju · Pull Request #677 · testcontainers/testcontainers-python ConversationI have created the issue #665 on which I proposed to implement it. The feature works fine, as you can see by the tests.
Thanks in advance 😃
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
mgorsk1
reviewed
|
|
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.
There was an error while loading. Please reload this page.
|
Found this wishing for copying, related comment in #676 (comment) Agree that mounting isn't copying, so the method shouldn't be called |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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.
There was an error while loading. Please reload this page.
|
@oelhammouchi look at the code I wrote for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@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 # 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.
There was an error while loading. Please reload this page.
| self.volumes[host] = mapping | ||
| return self | ||
|
|
||
| def with_copy_file_to_container( |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Even if this PR moves forward, I'd strongly advise against this name. This is mounting, not copying
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.
I agree. But I seem to recall there were discussions about following the Java conventions (or not).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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.
There was an error while loading. Please reload this page.
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.
There was an error while loading. Please reload this page.
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.