forked from mirrors/thatmattlove-hyperglass
fix container file handling
This commit is contained in:
parent
58b51b7c8e
commit
594d2e90f8
4 changed files with 18 additions and 11 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}"
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
if Settings.container:
|
||||
path = Path(value)
|
||||
if path.exists() and Settings.container:
|
||||
# if path.exists():
|
||||
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)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue