build ui in a separate step (#397)

This commit is contained in:
QP Hou 2025-05-05 09:34:32 -07:00 committed by GitHub
parent 083a31d6cc
commit 0b7c9f8e1f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 38 deletions

View File

@ -44,7 +44,11 @@ jobs:
- uses: taiki-e/install-action@v2
with:
tool: trunk
- name: Build
- name: Build UI first
run: |
cd roapi-ui
trunk build --release
- name: Build ROAPI with UI
run: |
mold -run cargo build --features=ui

View File

@ -52,6 +52,10 @@ jobs:
tool: trunk
- name: Install maturin
run: pip3 install 'maturin<2'
- name: Build UI first
run: |
cd roapi-ui
trunk build --release
- name: Build wheels - x86_64
run: |
maturin build -m roapi/Cargo.toml -b bin --target x86_64-apple-darwin --release --out dist --features=database-sqlite,ui
@ -106,6 +110,10 @@ jobs:
tool: trunk
- name: Install maturin
run: pip3 install 'maturin<2'
- name: Build UI first
run: |
cd roapi-ui
trunk build --release
- name: Build wheels
run: |
maturin build -m roapi/Cargo.toml -b bin --release --out dist --target ${{ matrix.platform.target }} --features=${{ matrix.platform.features }},ui
@ -198,6 +206,10 @@ jobs:
run: |
apt-get update
apt-get install -y libssl-dev
- name: Build UI first
run: |
cd roapi-ui
trunk build --release
- name: Build Wheels
run: |
sudo python3 -m pip install 'maturin<2'

View File

@ -7,6 +7,9 @@ FROM rust:${RUST_VER} AS chef
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall trunk
# Add WebAssembly target for UI build
RUN rustup target add wasm32-unknown-unknown
# We only pay the installation cost once,
# it will be cached from the second build onwards
RUN cargo binstall cargo-chef
@ -27,18 +30,21 @@ WORKDIR /roapi_src
COPY --from=planner /roapi_src/recipe.json recipe.json
RUN cargo chef cook --features ${FEATURES} --release --recipe-path recipe.json
# Step 3: Build the release binary
# Step 3: Build the UI and release binary
FROM chef AS builder
ARG FEATURES
WORKDIR /roapi_src
COPY ./ /roapi_src
COPY --from=cacher /roapi_src/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
# First build the UI
RUN cd roapi-ui && trunk build --release
# Then build the ROAPI binary with the UI embedded
RUN cargo build --release --locked --bin roapi --features ${FEATURES}
# Step 4: Assemble the final image
FROM debian:bookworm-slim
LABEL org.opencontainers.image.source https://github.com/roapi/roapi
LABEL org.opencontainers.image.source=https://github.com/roapi/roapi
RUN apt-get update \
&& apt-get install -y libssl-dev ca-certificates \

View File

@ -1,35 +0,0 @@
use std::env;
use std::process::Command;
fn main() {
if env::var("CARGO_FEATURE_UI").is_ok() {
let manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
let manifest_path = std::path::Path::new(&manifest_dir);
let workspace_root = manifest_path
.parent()
.expect("Failed to extract workspace root");
let ui_crate_path = workspace_root.join("roapi-ui");
for entry in &["src", "Cargo.toml", "assets", "index.html", "trunk.toml"] {
println!(
"cargo:rerun-if-changed={}/{}",
ui_crate_path.display(),
entry
);
}
let output = Command::new("trunk")
.current_dir(ui_crate_path)
.arg("build")
.arg("--release")
.output()
.expect("Failed to run Trunk build command");
if !output.status.success() {
println!("Trunk build failed");
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
std::process::exit(1);
}
}
}

View File

@ -150,6 +150,8 @@ pub fn get_cmd() -> clap::Command {
"snmalloc",
#[cfg(feature = "rustls")]
"rustls",
#[cfg(feature = "ui")]
"ui",
];
clap::Command::new("roapi")