diff --git a/hyperglass/frontend/__init__.py b/hyperglass/frontend/__init__.py index bbd7acea..0186c2e6 100644 --- a/hyperglass/frontend/__init__.py +++ b/hyperglass/frontend/__init__.py @@ -273,6 +273,8 @@ async def build_frontend( # noqa: C901 # Create temporary file. json file extension is added for easy # webpack JSON parsing. dot_env_file = Path(__file__).parent.parent / "ui" / ".env" + build_id_dot_env_dir = app_path / "static" + build_id_dot_env_file = build_id_dot_env_dir / ".env" env_config = {} ui_config_file = Path(__file__).parent.parent / "ui" / "hyperglass.json" @@ -320,7 +322,7 @@ async def build_frontend( # noqa: C901 write_favicon_formats(favicons.formats()) build_data = { - "params": params.export_dict(), + "params": sorted(params.export_dict()), "version": __version__, "package_json": package_json, } @@ -333,8 +335,10 @@ async def build_frontend( # noqa: C901 # Read hard-coded environment file from last build. If build ID # matches this build's ID, don't run a new build. - if dot_env_file.exists() and not force: - env_data = dotenv_to_dict(dot_env_file) + if not build_id_dot_env_dir.exists(): + build_id_dot_env_dir.mkdir() + if build_id_dot_env_file.exists() and not force: + env_data = dotenv_to_dict(build_id_dot_env_file) env_build_id = env_data.get("HYPERGLASS_BUILD_ID", "None") log.bind(id=env_build_id).debug("Previous build detected") @@ -342,8 +346,6 @@ async def build_frontend( # noqa: C901 log.debug("UI parameters unchanged since last build, skipping UI build...") return True - env_config.update({"HYPERGLASS_BUILD_ID": build_id}) - dot_env_file.write_text("\n".join(f"{k}={v}" for k, v in env_config.items())) log.bind(path=str(dot_env_file)).debug("Wrote UI environment file") @@ -375,4 +377,7 @@ async def build_frontend( # noqa: C901 params.web.theme.colors.black, ) + build_id_dot_env_file.write_text(f"HYPERGLASS_BUILD_ID={build_id}") + log.bind(path=str(build_id_dot_env_file)).debug("Wrote UI build environment file") + return True