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 | Be extremely careful with trailing slashes in src_path and dest_path, the behavior |
| 163 | of docker cp is also different depending on whether the destination exists. |
| 164 | """ |
| 165 | cmd = [ |
| 166 | "docker", |
| 167 | "cp", |
| 168 | f"{container.container_id}:{src_path}", |
| 169 | str(dest_path), |
| 170 | ] |
| 171 | print(f"Copy from container: cmd={cmd}") |
| 172 | Path(dest_path).parent.mkdir(parents=True, exist_ok=True) |
| 173 | result = subprocess.run(cmd, check=False, capture_output=True, text=True) |
| 174 | if result.returncode != 0: |
| 175 | raise RuntimeError( |
| 176 | f"Failed to copy {container.container_id}:{src_path} to {dest_path}: {result.stdout}{result.stderr}" |
| 177 | ) |
| 178 | return result |
| 179 | |
| 180 | |
| 181 | def create_file_in_container( |
no test coverage detected