Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to container.upload()'s behavior to match its doc #48

Merged
merged 1 commit into from
Feb 13, 2024
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
Loading