Copy a path on the local filesystem to a running container.
(path, container, container_path, archive_path=None)
| 99 | |
| 100 | |
| 101 | def copy_file_to_container(path, container, container_path, archive_path=None): |
| 102 | """Copy a path on the local filesystem to a running container.""" |
| 103 | buf = io.BytesIO() |
| 104 | tf = tarfile.open("irrelevant", "w", buf) |
| 105 | |
| 106 | dest_path = archive_path or path.name |
| 107 | tf.add(str(path), dest_path) |
| 108 | tf.close() |
| 109 | |
| 110 | log("copying %s to container:%s/%s" % (path, container_path, dest_path)) |
| 111 | container.put_archive(container_path, buf.getvalue()) |
| 112 | |
| 113 | |
| 114 | @contextlib.contextmanager |