Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: docker frontend build system #279

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
15 changes: 10 additions & 5 deletions hyperglass/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}
Expand All @@ -333,17 +335,17 @@ 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")

if env_build_id == build_id:
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")

Expand Down Expand Up @@ -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
Loading