diff --git a/Dockerfile b/Dockerfile index 53fc9cb..96358ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ ENV HYPERGLASS_DEBUG=false ENV HYPERGLASS_DEV_MODE=false ENV HYPERGLASS_REDIS_HOST=redis ENV HYPEGLASS_DISABLE_UI=true +ENV HYPERGLASS_CONTAINER=true COPY . . FROM base as ui diff --git a/compose.yaml b/compose.yaml index 5efe4e9..74a6ff6 100644 --- a/compose.yaml +++ b/compose.yaml @@ -12,6 +12,8 @@ services: - HYPERGLASS_DEV_MODE=${HYPERGLASS_DEV_MODE-false} - HYPERGLASS_REDIS_HOST=${HYPERGLASS_REDIS_HOST-redis} - HYPEGLASS_DISABLE_UI=${HYPEGLASS_DISABLE_UI-false} + - HYPERGLASS_CONTAINER=${HYPERGLASS_CONTAINER-true} + - HYPERGLASS_ORIGINAL_APP_PATH=${HYPERGLASS_APP_PATH} build: . ports: - "${HYPERGLASS_PORT-8001}:${HYPERGLASS_PORT-8001}" diff --git a/hyperglass/models/main.py b/hyperglass/models/main.py index 22078aa..65b8670 100644 --- a/hyperglass/models/main.py +++ b/hyperglass/models/main.py @@ -18,6 +18,8 @@ from hyperglass.types import Series MultiModelT = t.TypeVar("MultiModelT", bound=BaseModel) +PathTypeT = t.TypeVar("PathTypeT") + def alias_generator(field: str) -> str: """Remove unsupported characters from field names. @@ -44,26 +46,28 @@ class HyperglassModel(BaseModel): alias_generator=alias_generator, ) - def convert_paths(self, value: t.Any): - """Change path to relative to app_path.""" + def convert_paths(self, value: t.Type[PathTypeT]) -> PathTypeT: + """Change path to relative to app_path. + + This is required when running hyperglass in a container so that + the original app_path on the host system is not passed through + to the container. + """ # Project from hyperglass.settings import Settings if isinstance(value, Path): if Settings.container: - return str( - Settings.default_app_path.joinpath( - *(p for p in value.parts if p not in Settings.app_path.parts) - ) + return Settings.default_app_path.joinpath( + *(p for p in value.parts if p not in Settings.original_app_path.parts) ) if isinstance(value, str): - path = Path(value) - if path.exists() and Settings.container: - # if path.exists(): + if Settings.container: + path = Path(value) return str( Settings.default_app_path.joinpath( - *(p for p in path.parts if p not in Settings.app_path.parts) + *(p for p in path.parts if p not in Settings.original_app_path.parts) ) ) diff --git a/hyperglass/models/system.py b/hyperglass/models/system.py index 300e0eb..0494526 100644 --- a/hyperglass/models/system.py +++ b/hyperglass/models/system.py @@ -36,7 +36,7 @@ class HyperglassSettings(BaseSettings): config_file_names: t.ClassVar[t.Tuple[str, ...]] = ("config", "devices", "directives") default_app_path: t.ClassVar[Path] = _default_app_path - _original_app_path: DirectoryPath = _default_app_path + original_app_path: Path = _default_app_path debug: bool = False dev_mode: bool = False