Skip to content

Commit

Permalink
Auto-persist configs for sandboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
polyaxon-ci committed Oct 26, 2023
1 parent c3af053 commit 2588cc2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion haupt/haupt/cli/runners/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def start(
uds: Optional[str] = None,
):
os.environ[ENV_KEYS_SERVICE] = PolyaxonServices.API
settings.set_sandbox_config(path=ctx_paths.CONTEXT_ARTIFACTS_ROOT)
settings.set_sandbox_config(path=ctx_paths.CONTEXT_ARTIFACTS_ROOT, persist=True)
host = host or settings.SANDBOX_CONFIG.host
port = port or settings.SANDBOX_CONFIG.port
start_app(
Expand Down
14 changes: 9 additions & 5 deletions haupt/haupt/common/settings/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ def set_core(context, config: PlatformConfig, use_db: bool = True):
context["DEFAULT_DB_ENGINE"] = db_engine
db_name = config.db_name
if not db_name:
db_name = (
f"{settings.SANDBOX_CONFIG.path}/plxdb"
if config.is_sqlite_db_engine
else "polyaxon"
)
if config.is_sqlite_db_engine:
db_path = (
settings.SANDBOX_CONFIG.path
if settings.SANDBOX_CONFIG and settings.SANDBOX_CONFIG.path
else "/tmp"
)
db_name = f"{db_path}/plx.db"
else:
db_name = "polyaxon"
db_definition = {
"ENGINE": db_engine,
"NAME": db_name,
Expand Down
2 changes: 1 addition & 1 deletion haupt/haupt/schemas/platform_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PlatformConfig(BaseSchemaModel):
logs_root: Optional[str] = Field(
alias=ENV_KEYS_LOGS_ROOT, default=DEFAULT_LOGS_ROOT
)
log_level: Optional[str] = Field(alias=ENV_KEYS_LOG_LEVEL, default="WARNING")
log_level: Optional[str] = Field(alias=ENV_KEYS_LOG_LEVEL, default="INFO")
timezone: Optional[str] = Field(alias=ENV_KEYS_TIME_ZONE, default="UTC")
scheduler_enabled: Optional[bool] = Field(
alias="POLYAXON_SCHEDULER_ENABLED", default=False
Expand Down
10 changes: 10 additions & 0 deletions haupt/haupt/schemas/sandbox_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging

from typing import Optional

from clipped.compact.pydantic import Field, StrictInt, StrictStr, root_validator
from clipped.utils.http import clean_host
from clipped.utils.paths import check_or_create_path

from polyaxon._env_vars.keys import (
ENV_KEYS_K8S_NAMESPACE,
Expand All @@ -16,6 +19,8 @@
)
from polyaxon._schemas.agent import AgentConfig

_logger = logging.getLogger("sandbox.config")


class SandboxConfig(AgentConfig):
_IDENTIFIER = "sandbox"
Expand Down Expand Up @@ -68,3 +73,8 @@ def mount_sandbox(self, path: Optional[str] = None):
from polyaxon._contexts.paths import mount_sandbox

self.path = mount_sandbox(path=self.path or path)
try:
check_or_create_path(self.path, is_dir=True)
except Exception as e:
_logger.error("Could not create sandbox path `%s`.", self.path)
raise e
7 changes: 5 additions & 2 deletions haupt/haupt/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def set_proxies_config():
PROXIES_CONFIG = ProxiesManager.get_config_from_env()


def set_sandbox_config(path: Optional[str] = None):
def set_sandbox_config(path: Optional[str] = None, persist: bool = False):
from haupt.managers.sandbox import SandboxConfigManager
from polyaxon.settings import HOME_CONFIG, set_agent_config

Expand All @@ -32,7 +32,10 @@ def set_sandbox_config(path: Optional[str] = None):
SANDBOX_CONFIG = SandboxConfigManager.get_config_or_default()
SANDBOX_CONFIG.mount_sandbox(path=path)
SANDBOX_CONFIG.set_default_artifacts_store()
set_agent_config(SANDBOX_CONFIG)
if persist:
SandboxConfigManager.set_config(SANDBOX_CONFIG)
set_agent_config(SANDBOX_CONFIG, persist=True)

except (TypeError, ValidationError):
SandboxConfigManager.purge()
Printer.warning("Your sandbox configuration was purged!")

0 comments on commit 2588cc2

Please sign in to comment.