-
Notifications
You must be signed in to change notification settings - Fork 30
feat: add a debug mode for bentoctl #174
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from bentoctl.console import console | ||
from bentoctl.deployment_config import DeploymentConfig | ||
from bentoctl.exceptions import BentoctlDockerException | ||
from bentoctl.utils import get_debug_mode | ||
from bentoctl.utils.temp_dir import TempDirectory | ||
|
||
# default location were dockerfile can be found | ||
|
@@ -51,9 +52,13 @@ def __rich_console__(self, *_): | |
|
||
|
||
def generate_deployable_container( | ||
tag: str, deployment_config: DeploymentConfig, cleanup: bool | ||
tag: str, deployment_config: DeploymentConfig | ||
) -> None: | ||
with TempDirectory(cleanup=cleanup) as dist_dir: | ||
""" | ||
Calls the operator and generates the deployable. If in debug more the generated | ||
deployable will be moved to the current directory for easier debugging. | ||
""" | ||
with TempDirectory(debug=get_debug_mode()) as dist_dir: | ||
Comment on lines
+57
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving directory is a bit unnatural for debugging. Maybe preserving and printing the temp directory during debug should be sufficient? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the behavior that we have now (except printing which folder it is). I prefer to have |
||
env = {"DOCKER_BUILDKIT": "1", "DOCKER_SCAN_SUGGEST": "false"} | ||
buildx_args = { | ||
"subprocess_env": env, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,14 @@ class TempDirectory(object): | |
def __init__( | ||
self, | ||
cleanup=True, | ||
debug=False, | ||
prefix="temp", | ||
): | ||
|
||
self._cleanup = cleanup | ||
self._prefix = prefix | ||
self.path = None | ||
self.debug = debug | ||
|
||
def __repr__(self): | ||
return "<{} {!r}>".format(self.__class__.__name__, self.path) | ||
|
@@ -29,6 +31,8 @@ def __enter__(self) -> Path: | |
return Path(self.create()) | ||
|
||
def __exit__(self, exc_type, exc_val, exc_tb): | ||
if self.debug: | ||
self.move_to_curdir() | ||
if self._cleanup: | ||
self.cleanup() | ||
|
||
|
@@ -46,4 +50,10 @@ def cleanup(self, ignore_errors=False): | |
""" | ||
if self.path is not None and os.path.exists(self.path): | ||
shutil.rmtree(self.path, ignore_errors=ignore_errors) | ||
Comment on lines
50
to
52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If in debug mode, maybe we can print the temp dir instead of removing. |
||
self.path = None | ||
|
||
def move_to_curdir(self): | ||
deployable_path = os.path.join(os.curdir, "bentoctl_deployable") | ||
if os.path.exists(deployable_path): | ||
shutil.rmtree(deployable_path) | ||
|
||
shutil.copytree(self.path, deployable_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we clean up when not in debug mode? :)