Skip to content

Commit

Permalink
feat: allow javascript caching in docker environment
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Ortega <ludovic.ortega@adminafk.fr>
  • Loading branch information
M0NsTeRRR committed Jul 19, 2024
1 parent 0b2fbb1 commit e002594
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hyperglass/ui/.env*
hyperglass.json
custom.*[js, html]
.next
out/
fonts/
__pycache__
.python-version
Expand Down
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"node_modules",
"dist",
".next/",
"out/",
"build/",
"favicon-formats.ts",
"custom.*[js, html]",
"hyperglass.json"
Expand Down
13 changes: 7 additions & 6 deletions hyperglass/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def build_ui(app_path: Path):

ui_dir = Path(__file__).parent.parent / "ui"
build_dir = app_path / "static" / "ui"
out_dir = ui_dir / "out"
out_dir = ui_dir / "build" / "out"

build_command = "node_modules/.bin/next build"

Expand Down Expand Up @@ -273,6 +273,7 @@ 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_file = Path(__file__).parent.parent / "ui" / "build" / ".env"
env_config = {}

ui_config_file = Path(__file__).parent.parent / "ui" / "hyperglass.json"
Expand Down Expand Up @@ -320,7 +321,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,19 +334,19 @@ 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 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")
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")

# Initiate Next.JS export process.
if any((not dev_mode, force, full)):
Expand Down
1 change: 1 addition & 0 deletions hyperglass/ui/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const nextConfig = {
},
swcMinify: true,
productionBrowserSourceMaps: true,
distDir: "build/out",
};

if (process.env.NODE_ENV === 'production') {
Expand Down

0 comments on commit e002594

Please sign in to comment.