Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [0.7.1]

### Fixes

- [cli] missing inline override for setting executor and set default for the executor on program config

## [0.7.0]

### Features and Enhancements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ You can find the some of the samples in [examples](./examples/).
| .programs[name].image | | container image that will be loaded, this also will be set as a reference of image name for the build/custom one | `yes` |
| .programs[name].exec | | path of executeable inside container that will be ran as **entrypoint**, this is will be the main one | `yes` |
| .programs[name].extends | `[]` | extending from another program config, ensure the config name is exists | `no` |
| .programs[name].executor | | set the container executor | `no` |
| .programs[name].executor | `default` | set the container executor | `no` |
| .programs[name].aliases | `{}` | the maps of any other executeable inside container, during subcommand **alias** by the argument **--generate**, this will generate alias by pattern "[program_name]-[alias]" | `no` |
| .programs[name].interactive | `True` | interactive mode (**-it** ~> keep STDIN and provide pseudo TTY ) | `no` |
| .programs[name].allow_home_dir | `False` | allow ran in (top of) home directory if auto sandbox mount enabled | `no` |
Expand Down
8 changes: 6 additions & 2 deletions sandock/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from importlib.metadata import metadata
from .config import MainConfig, load_config_file, main_config_finder
from .config.program import Program
from .shared import log, SANDBOX_DEBUG_ENV, CONFIG_PATH_ENV, KV, run_shell
from .shared import log, SANDBOX_DEBUG_ENV, CONFIG_PATH_ENV, KV, run_shell, EXECUTOR_DEFAULT
from .sandbox import SandboxExec
from .volume import VolumeMgr
from .exceptions import SandboxBaseException, SandboxExecConfig, SandboxVolumeExec
Expand Down Expand Up @@ -358,6 +358,10 @@ def overrides_args(self) -> ArgumentParser:
self.override_arg(name="network"), default=None, help="override network"
)

oparser.add_argument(
self.override_arg(name="executor"), default=None, help="override executor"
)

oparser.add_argument(
self.override_arg(name="allow-home-dir"),
action="store_true",
Expand Down Expand Up @@ -459,7 +463,7 @@ def executor_cls(self) -> Type[SandboxExec]:
return sandbox class that will be use
"""
program_exec = self.program_cfg.executor
if not program_exec:
if program_exec == EXECUTOR_DEFAULT:
return SandboxExec

executor = self.config.executors.get(program_exec)
Expand Down
3 changes: 2 additions & 1 deletion sandock/config/program.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass, field
from typing import List, Optional, Dict
from .image import ImageBuild
from ..shared import EXECUTOR_DEFAULT
from ._helpers import build_if_set


Expand Down Expand Up @@ -43,13 +44,13 @@ class Program(object):
interactive: bool = True
allow_home_dir: bool = False
name: Optional[str] = None
executor: Optional[str] = None
network: Optional[str] = None
hostname: Optional[str] = None
build: Optional[ImageBuild] = None
user: Optional[ContainerUser] = None
workdir: Optional[str] = None
platform: Optional[str] = None
executor: str = EXECUTOR_DEFAULT
persist: PersistContainer = field(default_factory=PersistContainer)
sandbox_mount: SandboxMount = field(default_factory=SandboxMount)
env: Dict[str, str] = field(default_factory=dict)
Expand Down
14 changes: 7 additions & 7 deletions sandock/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .config import MainConfig
from .config.program import Program
from .config.image import ImageBuild, DEFAULT_DUMP_IMAGE_STORE
from .shared import log, run_shell, file_hash, ensure_home_dir_special_prefix, KV
from .shared import log, run_shell, file_hash, ensure_home_dir_special_prefix, KV, EXECUTOR_DEFAULT
from .exceptions import SandboxExecution

VOL_LABEL_CREATED_BY = "created_by.sandock"
Expand Down Expand Up @@ -58,15 +58,15 @@ def hook_recreate_img(self, execute: bool=False) -> None:
@property
def docker_bin(self) -> str:
default_bin = self.cfg.execution.docker_bin
custom_executor = self.program.executor
if not custom_executor:
executor = self.program.executor
if executor == EXECUTOR_DEFAULT:
return default_bin

executor = self.cfg.executors.get(custom_executor)
if not executor:
raise SandboxExecution(f"Executor `{custom_executor}` is not defined")
executor_cfg = self.cfg.executors.get(executor)
if not executor_cfg:
raise SandboxExecution(f"Executor `{executor}` is not defined")

return executor.bin_path if executor.bin_path else default_bin
return executor_cfg.bin_path if executor_cfg.bin_path else default_bin

@property
def current_timestamp(self) -> float:
Expand Down
1 change: 1 addition & 0 deletions sandock/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


KV = Dict[str, Any]
EXECUTOR_DEFAULT = "default"
CONFIG_PATH_ENV = "SNDK_CFG"
SANDBOX_DEBUG_ENV = "SNDK_DEBUG"
FETCH_PROP_ENABLE_ENV = "SNDK_FETCH_PROP"
Expand Down
11 changes: 6 additions & 5 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def test_executor_cls_custom_cls(self) -> None:
) as o:
self.assertEqual(o.executor_cls, AppleContainerExec)

# TODO: [x] validation: program is not defined
def test_init_program_not_defined(self) -> None:
"""
the provided program is not listed on configuration
Expand All @@ -220,7 +219,6 @@ def test_init_program_not_defined(self) -> None:
with self.obj(args=Namespace(program="another_app")):
pass

# TODO: [x] validation: name of persist command canot be overrided
def test_apply_overrides_persist_cannot_overrided(self) -> None:
with self.assertRaisesRegex(
SandboxExecConfig, "name of persist program cannot be overrided"
Expand All @@ -232,7 +230,6 @@ def test_apply_overrides_persist_cannot_overrided(self) -> None:
o.apply_overrides()


# TODO: [x] running hook test (recreate_img)
@mock.patch("sandock.cli.SandboxExec")
def test_main_hook_recreate_img(self, sandbox_exec_mock: MagicMock) -> None:
remote = MagicMock()
Expand All @@ -259,21 +256,25 @@ def test_main_overrided_params(self, sandbox_exec_mock: MagicMock) -> None:
"--sandbox-arg-hostname=change_host",
"--sandbox-arg-ports=8080:8080",
"--sandbox-arg-ports=8081:8081",
"--sandbox-arg-executor=podman",
"--version"]
with self.obj(
ns_props=dict(program_args=provided_args),
cfg=dummy_main_cfg(
executors={"podman": {"bin_path": "podman"}}
)
) as o:
o.main()

# TODO: [x] testing override parameters
self.assertEqual(
sandbox_exec_mock.call_args[1]["program"],
dummy_program_cfg(
hostname="change_host",
ports=[
"8080:8080",
"8081:8081"
]
],
executor="podman"
),
)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_defaults(self) -> None:
self.assertTrue(o.interactive, True)
self.assertFalse(o.allow_home_dir)
self.assertIsNone(o.name)
self.assertIsNone(o.executor)
self.assertEqual(o.executor, "default")
self.assertIsNone(o.network)
self.assertIsNone(o.hostname)
self.assertIsNone(o.user)
Expand Down
2 changes: 0 additions & 2 deletions tests/test_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ def obj(self, program_kwargs: dict = {}, **kwargs) -> SandboxExec:

return self.exec_cls(**kwargs)

# TODO: move this to cli test
# TODO: [x] keep to validate directory execution check
def test_init_validations(self) -> None:
with self.assertRaisesRegex(
SandboxExecution,
Expand Down