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

feat: allow javascript caching in docker environment #276

Closed
Closed
Show file tree
Hide file tree
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
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ __pycache__/
.Python
env/
build/
# keep hyperglass ui/build
!**/ui/build/
develop-eggs/
dist/
downloads/
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
Empty file added hyperglass/ui/build/.gitkeep
Empty file.
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
Loading