Create a file with given content on a Docker container. Uses a temporary file on the local filesystem for the transfer.
(
container: DockerEnvironment,
*,
content: str,
dest_path: str | Path,
)
| 162 | |
| 163 | |
| 164 | def create_file_in_container( |
| 165 | container: DockerEnvironment, |
| 166 | *, |
| 167 | content: str, |
| 168 | dest_path: str | Path, |
| 169 | ): |
| 170 | """ |
| 171 | Create a file with given content on a Docker container. |
| 172 | Uses a temporary file on the local filesystem for the transfer. |
| 173 | """ |
| 174 | with tempfile.NamedTemporaryFile(mode="w", delete=True, suffix=".tmp", dir=_scratch_dir()) as tmp_file: |
| 175 | tmp_file.write(content) |
| 176 | tmp_file.flush() # Ensure content is written to disk |
| 177 | tmp_file_path = Path(tmp_file.name) |
| 178 | copy_to_container(container, tmp_file_path, dest_path) |
no test coverage detected