Skip to content

Commit 8a349c5

Browse files
committed
WebUI CI build.
Add a second mode for building the WebUI which just points to a static dir. Helps with caching & speeds up build in earthly as not all rust builds with different configs have to build the website.
1 parent 7316935 commit 8a349c5

4 files changed

Lines changed: 66 additions & 119 deletions

File tree

.github/workflows/webui.yml

Lines changed: 0 additions & 96 deletions
This file was deleted.

Earthfile

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,31 @@ install-rust:
4646
RUN cargo --version
4747
RUN rustc --version
4848

49+
build-webui-deps:
50+
FROM +install-deps
51+
COPY web-ui/package.json ./web-ui/package.json
52+
COPY web-ui/yarn.lock ./web-ui/yarn.lock
53+
54+
RUN cd web-ui && yarn install
55+
56+
build-webui:
57+
FROM +build-webui-deps
58+
COPY --dir web-ui/public web-ui/public
59+
COPY --dir web-ui/src web-ui/src
60+
COPY --dir web-ui/styles web-ui/styles
61+
COPY web-ui/.editorconfig web-ui/
62+
COPY web-ui/.eslintrc.json web-ui/
63+
COPY web-ui/.prettierrc.js web-ui/
64+
COPY web-ui/next-env.d.ts ./web-ui/next-env.d.ts
65+
COPY web-ui/next.config.js ./web-ui/next.config.js
66+
COPY web-ui/next.d.ts ./web-ui/next.d.ts
67+
COPY web-ui/tsconfig.json ./web-ui/tsconfig.json
68+
69+
RUN cd web-ui && yarn format:check
70+
RUN cd web-ui && yarn build
71+
RUN cd web-ui && yarn export
72+
SAVE ARTIFACT ./web-ui/out
73+
4974
prepare-cache:
5075
# We download and pre-build dependencies to cache it using cargo-chef.
5176
# See also (on why this is so complicated :/):
@@ -170,10 +195,12 @@ build-manager:
170195
ARG RUST_BUILD_PROFILE=$RUST_BUILD_MODE
171196

172197
FROM +build-adapters --RUST_TOOLCHAIN=$RUST_TOOLCHAIN --RUST_BUILD_PROFILE=$RUST_BUILD_PROFILE
198+
# For some reason if this ENV before the FROM line it gets invalidated
199+
ENV WEBUI_BUILD_DIR=/dbsp/web-ui/out
200+
COPY ( +build-webui/out ) ./web-ui/out
173201

174202
RUN rm -rf crates/pipeline_manager
175203
COPY --keep-ts --dir crates/pipeline_manager crates/pipeline_manager
176-
COPY --keep-ts --dir web-ui web-ui
177204
COPY --keep-ts python python
178205

179206
RUN cargo +$RUST_TOOLCHAIN build $RUST_BUILD_PROFILE --package dbsp_pipeline_manager

crates/pipeline_manager/Makefile.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description = "Dump OpenAPI specification of the REST API to 'openapi.json'"
1010
dependencies = ["build"]
1111
script = '''
1212
cd ../../
13-
cargo run @@remove-empty(RUST_BUILD_PROFILE) --package dbsp_pipeline_manager -- --dump-openapi
13+
cargo run --package dbsp_pipeline_manager -- --dump-openapi
1414
'''
1515

1616
[tasks.openapi_python]

crates/pipeline_manager/build.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use change_detection::ChangeDetection;
2-
use static_files::NpmBuild;
3-
use std::{env, path::Path};
2+
use static_files::{resource_dir, NpmBuild};
3+
use std::env;
4+
use std::path::Path;
45

56
// These are touched during the build, so it would re-build every time if we
67
// don't exclude them from change detection:
@@ -10,30 +11,45 @@ const EXCLUDE_LIST: [&str; 3] = [
1011
"../../web-ui/.next",
1112
];
1213

14+
/// The build script has two modes:
15+
///
16+
/// - if `WEBUI_BUILD_DIR` we use that to serve in the manager
17+
/// - otherwise we build the web-ui from web-ui and serve it from the manager
18+
///
19+
/// The first mode is useful in CI builds to cache the website build so it
20+
/// doesn't get built many times due to changing rustc flags.
1321
fn main() {
14-
ChangeDetection::exclude(|path: &Path| {
15-
EXCLUDE_LIST
22+
if let Ok(webui_out_folder) = env::var("WEBUI_BUILD_DIR") {
23+
ChangeDetection::path(&webui_out_folder).path("build.rs").generate();
24+
println!("cargo:rerun-if-changed=build.rs");
25+
resource_dir(webui_out_folder)
26+
.build()
27+
.expect("Could not use WEBUI_BUILD_DIR as a website location")
28+
} else {
29+
ChangeDetection::exclude(|path: &Path| {
30+
EXCLUDE_LIST
1631
.iter()
1732
.any(|exclude| path.to_str().unwrap().starts_with(exclude))
1833
// Also exclude web-ui folder itself because we mutate things inside
1934
// of it
2035
|| path.to_str().unwrap() == "../../web-ui/"
21-
})
22-
.path("../../web-ui/")
23-
.path("build.rs")
24-
.generate();
25-
println!("cargo:rerun-if-env-changed=NEXT_PUBLIC_MUIX_PRO_KEY");
36+
})
37+
.path("../../web-ui/")
38+
.path("build.rs")
39+
.generate();
40+
println!("cargo:rerun-if-env-changed=NEXT_PUBLIC_MUIX_PRO_KEY");
2641

27-
NpmBuild::new("../../web-ui")
28-
.executable("yarn")
29-
.install()
30-
.expect("Could not run `yarn install`. Follow set-up instructions in web-ui/README.md")
31-
.run("build")
32-
.expect("Could not run `yarn build`. Run it manually in web-ui/ to debug.")
33-
.run("export-to-out")
34-
.expect("Could not run `yarn export-to-out`. Run it manually in web-ui/ to debug.")
35-
.target(env::var("OUT_DIR").unwrap())
36-
.to_resource_dir()
37-
.build()
38-
.unwrap();
42+
NpmBuild::new("../../web-ui")
43+
.executable("yarn")
44+
.install()
45+
.expect("Could not run `yarn install`. Follow set-up instructions in web-ui/README.md")
46+
.run("build")
47+
.expect("Could not run `yarn build`. Run it manually in web-ui/ to debug.")
48+
.run("export-to-out")
49+
.expect("Could not run `yarn export-to-out`. Run it manually in web-ui/ to debug.")
50+
.target(env::var("OUT_DIR").unwrap())
51+
.to_resource_dir()
52+
.build()
53+
.unwrap();
54+
}
3955
}

0 commit comments

Comments
 (0)