Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion chi/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import io
import os
import logging
import tarfile
import time
Expand Down Expand Up @@ -202,14 +203,17 @@ def execute(container_ref: "str", command: "str") -> "dict":
def upload(container_ref: "str", source: "str", dest: "str") -> "dict":
"""Upload a file or directory to a running container.

This method requires your running container to include
the GNU tar utility.

Args:
container_ref (str): The name or ID of the container.
source (str): The (local) path to the file or directory to upload.
dest (str): The (container) path to upload the file or directory to.
"""
fd = io.BytesIO()
with tarfile.open(fileobj=fd, mode="w") as tar:
tar.add(source, arcname=".")
tar.add(source, arcname=os.path.basename(source))
fd.seek(0)
data = fd.read()
fd.close()
Expand All @@ -219,6 +223,9 @@ def upload(container_ref: "str", source: "str", dest: "str") -> "dict":
def download(container_ref: "str", source: "str", dest: "str"):
"""Download a file or directory from a running container.

This method requires your running container to include
both the POSIX sh and GNU tar utilities.

Args:
container_ref (str): The name or ID of the container.
source (str): The (container) path of the file or directory.
Expand Down