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

Make container commit optional #4

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion llm_sandbox/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(
dockerfile: Optional[str] = None,
lang: str = SupportedLanguage.PYTHON,
keep_template: bool = False,
commit_container: bool = True,
verbose: bool = False,
mounts: Optional[list[Mount]] = None,
):
Expand All @@ -41,6 +42,7 @@ def __init__(
:param dockerfile: Path to the Dockerfile, if image is not provided
:param lang: Language of the code
:param keep_template: if True, the image and container will not be removed after the session ends
:param commit_container: if True, the Docker container will be commited after the session ends
:param verbose: if True, print messages
"""
super().__init__(lang, verbose)
Expand Down Expand Up @@ -71,6 +73,7 @@ def __init__(
self.container: Optional[Container] = None
self.path = None
self.keep_template = keep_template
self.commit_container = commit_container
self.is_create_template: bool = False
self.verbose = verbose
self.mounts = mounts
Expand Down Expand Up @@ -114,7 +117,7 @@ def open(self):

def close(self):
if self.container:
if isinstance(self.image, Image):
if self.commit_container and isinstance(self.image, Image):
self.container.commit(self.image.tags[-1])

self.container.remove(force=True)
Expand Down
3 changes: 3 additions & 0 deletions llm_sandbox/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __new__(
dockerfile: Optional[str] = None,
lang: str = SupportedLanguage.PYTHON,
keep_template: bool = False,
commit_container: bool = True,
verbose: bool = False,
use_kubernetes: bool = False,
kube_namespace: Optional[str] = "default",
Expand All @@ -25,6 +26,7 @@ def __new__(
:param dockerfile: Path to the Dockerfile, if image is not provided
:param lang: Language of the code
:param keep_template: if True, the image and container will not be removed after the session ends
:param commit_container: if True, the Docker container will be commited after the session ends
:param verbose: if True, print messages (default is True)
:param use_kubernetes: if True, use Kubernetes instead of Docker (default is False)
:param kube_namespace: Kubernetes namespace to use (only if 'use_kubernetes' is True), default is 'default'
Expand All @@ -46,5 +48,6 @@ def __new__(
dockerfile=dockerfile,
lang=lang,
keep_template=keep_template,
commit_container=commit_container,
verbose=verbose,
)
Loading