Skip to content

Commit eaaed3e

Browse files
authored
feat: move admin ui into sub crate (#91)
1 parent 8167359 commit eaaed3e

132 files changed

Lines changed: 135 additions & 97 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yaml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Build
22

33
on:
44
push:
5-
branches: ["main"]
5+
branches: [ "main" ]
66
pull_request:
7-
branches: ["main"]
7+
branches: [ "main" ]
88

99
env:
1010
CARGO_TERM_COLOR: always
@@ -27,7 +27,7 @@ jobs:
2727
with:
2828
node-version: lts/*
2929
cache: "pnpm"
30-
cache-dependency-path: ui/pnpm-lock.yaml
30+
cache-dependency-path: crates/admin-ui/ui/pnpm-lock.yaml
3131

3232
- name: Setup Rust toolchain
3333
run: rustup toolchain install stable --profile minimal
@@ -42,23 +42,27 @@ jobs:
4242
id: ui-cache
4343
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # 5.0.4
4444
with:
45-
path: ui/dist
46-
key: ui-dist-${{ hashFiles('ui/src/**', 'ui/index.html', 'ui/vite.config.ts', 'ui/tsconfig*.json', 'ui/package.json', 'ui/pnpm-lock.yaml') }}
45+
path: crates/admin-ui/ui-dist
46+
key: ui-dist-${{ hashFiles('crates/admin-ui/ui/src/**',
47+
'crates/admin-ui/ui/index.html',
48+
'crates/admin-ui/ui/vite.config.ts',
49+
'crates/admin-ui/ui/tsconfig*.json',
50+
'crates/admin-ui/ui/package.json',
51+
'crates/admin-ui/ui/pnpm-lock.yaml', 'crates/admin-ui/build.rs',
52+
'crates/admin-ui/Cargo.toml') }}
4753

4854
- name: Build UI
4955
if: steps.ui-cache.outputs.cache-hit != 'true'
50-
run: |
51-
pnpm -C ui install --frozen-lockfile
52-
pnpm -C ui build
56+
run: cargo build -p aisix-admin-ui --features build-ui -vv
5357

5458
- name: Run Lint
55-
run: cargo clippy --all-targets --locked -- -D warnings
59+
run: cargo clippy --workspace --all-targets --locked -- -D warnings
5660

5761
- name: Build
5862
run: cargo build --locked
5963

6064
- name: Run Test
61-
run: cargo test --locked
65+
run: cargo test --workspace --locked
6266

6367
- name: Run E2E Test
6468
run: |

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
# Node.js/TypeScript/Vite
99
node_modules/
10-
ui/node_modules/
11-
ui/dist/
10+
ui-dist/
1211
ui/.vite/
1312
ui/.cache/
1413
*.tsbuildinfo

Cargo.lock

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["crates/aisix-llm"]
2+
members = ["crates/aisix-llm", "crates/admin-ui"]
33
resolver = "3"
44

55
[workspace.package]
@@ -8,6 +8,7 @@ edition = "2024"
88
rust-version = "1.85"
99

1010
[workspace.dependencies]
11+
anyhow = "1"
1112
async-trait = "0.1"
1213
assert_matches = "1.5"
1314
aws-credential-types = "1.2.14"
@@ -51,35 +52,42 @@ edition = "2024"
5152
rust-version = "1.85"
5253

5354
[features]
54-
build-ui = []
55+
build-ui = ["aisix-admin-ui/build-ui"]
5556

5657
[dependencies]
5758
aisix-llm = { path = "crates/aisix-llm" }
59+
aisix-admin-ui = { path = "crates/admin-ui" }
60+
anyhow.workspace = true
61+
tokio.workspace = true
62+
reqwest.workspace = true
63+
http.workspace = true
64+
axum.workspace = true
65+
serde.workspace = true
66+
serde_json.workspace = true
67+
async-trait.workspace = true
68+
aws-credential-types.workspace = true
69+
aws-sigv4.workspace = true
70+
aws-smithy-eventstream.workspace = true
71+
aws-smithy-runtime-api.workspace = true
72+
aws-smithy-types.workspace = true
73+
futures.workspace = true
74+
bytes.workspace = true
75+
fastrace.workspace = true
76+
pin-project.workspace = true
77+
thiserror.workspace = true
78+
uuid.workspace = true
79+
utoipa.workspace = true
80+
percent-encoding.workspace = true
81+
5882
log = { version = "0.4.29", features = ["kv", "kv_serde"] }
59-
tokio = { workspace = true }
60-
reqwest = { workspace = true }
6183
openssl = { version = "0.10.77" }
6284
tokio-openssl = "0.6"
6385
clap = { version = "4.6.0", features = ["derive"] }
6486
config = "0.15"
65-
http = { workspace = true }
6687
http-body = "1.0.1"
6788
http-body-util = "0.1.3"
68-
axum = { workspace = true }
69-
serde = { workspace = true }
70-
serde_json = { workspace = true }
7189
etcd-client = { version = "0.18.0", features = ["tls-openssl"] }
72-
async-trait = { workspace = true }
73-
aws-credential-types = { workspace = true }
74-
aws-sigv4 = { workspace = true }
75-
aws-smithy-eventstream = { workspace = true }
76-
aws-smithy-runtime-api = { workspace = true }
77-
aws-smithy-types = { workspace = true }
78-
futures = { workspace = true }
79-
bytes = { workspace = true }
8090
arc-swap = "1"
81-
anyhow = "1"
82-
fastrace = { workspace = true }
8391
fastrace-axum = "0.2.0"
8492
fastrace-opentelemetry = "0.17.0"
8593
opentelemetry = "0.31.0"
@@ -109,23 +117,18 @@ opentelemetry-semantic-conventions = { version = "0.31.0", features = [
109117
] }
110118
metrics = "0.24.2"
111119
metrics-exporter-otel = "0.3.0"
112-
pin-project = { workspace = true }
113120
dashmap = "6.1.0"
114-
thiserror = { workspace = true }
115121
skp-ratelimit = { git = "https://github.com/bzp2010/skp-ratelimit.git", branch = "bzp/feat-custom-cost", default-features = false, features = [
116122
"memory",
117123
] }
118124
rand = "0.10.1"
119125
jsonschema = { version = "0.46.0", default-features = false }
120-
uuid = { workspace = true }
121-
utoipa = { workspace = true }
122126
utoipa-scalar = { version = "0.3", features = ["axum"] }
123127
rust-embed = { version = "8.11.0", default-features = false, features = [
124128
"axum-ex",
125129
"debug-embed",
126130
"deterministic-timestamps",
127131
] }
128-
mime_guess = "2.0.5"
129132
tower = { version = "0.5.3", default-features = false, features = ["util"] }
130133
validator = { version = "0.20", features = ["derive"] }
131134
axum-server = { version = "0.8.0", default-features = false, features = [
@@ -134,16 +137,15 @@ axum-server = { version = "0.8.0", default-features = false, features = [
134137
backon = { version = "1.6.0", default-features = false, features = [
135138
"tokio-sleep",
136139
] }
137-
percent-encoding = { workspace = true }
138140

139141
[build-dependencies]
140142
vergen-git2 = { version = "9.1.0" }
141143
anyhow = "1"
142144

143145
[dev-dependencies]
146+
assert_matches.workspace = true
147+
pretty_assertions.workspace = true
144148
tokio-test = "0.4"
145-
assert_matches = { workspace = true }
146-
pretty_assertions = { workspace = true }
147149
rstest = "0.26"
148150
tempfile = "3"
149151

build.rs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
use std::{env, fs, process};
2-
3-
use anyhow::{Result, anyhow};
1+
use anyhow::Result;
42
use vergen_git2::{Emitter, Git2Builder};
53

64
fn main() -> Result<()> {
7-
build_ui()?;
8-
95
Emitter::default()
106
.add_instructions(&Git2Builder::default().sha(true).build()?)?
117
.emit()?;
@@ -14,39 +10,3 @@ fn main() -> Result<()> {
1410

1511
Ok(())
1612
}
17-
18-
fn build_ui() -> Result<()> {
19-
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
20-
21-
if env::var("CARGO_FEATURE_BUILD_UI").is_ok() {
22-
println!("cargo:rerun-if-changed=ui");
23-
24-
let status = process::Command::new("pnpm")
25-
.args(["install", "--frozen-lockfile"])
26-
.current_dir(format!("{manifest_dir}/ui"))
27-
.stdout(std::process::Stdio::inherit())
28-
.stderr(std::process::Stdio::inherit())
29-
.status()?;
30-
31-
if !status.success() {
32-
return Err(anyhow!(
33-
"failed to install ui dependencies with status: {}",
34-
status
35-
));
36-
}
37-
38-
let status = process::Command::new("pnpm")
39-
.args(["run", "build"])
40-
.current_dir(format!("{manifest_dir}/ui"))
41-
.stdout(std::process::Stdio::inherit())
42-
.stderr(std::process::Stdio::inherit())
43-
.status()?;
44-
45-
if !status.success() {
46-
return Err(anyhow!("failed to build ui with status: {}", status));
47-
}
48-
} else {
49-
fs::create_dir_all(format!("{manifest_dir}/ui/dist"))?;
50-
}
51-
Ok(())
52-
}

crates/admin-ui/Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "aisix-admin-ui"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
7+
[features]
8+
build-ui = []
9+
10+
[dependencies]
11+
axum.workspace = true
12+
http.workspace = true
13+
mime_guess = "2.0.5"
14+
rust-embed = { version = "8.11.0", default-features = false, features = [
15+
"axum-ex",
16+
"debug-embed",
17+
"deterministic-timestamps",
18+
] }
19+
20+
[dev-dependencies]
21+
axum.workspace = true
22+
assert_matches.workspace = true
23+
pretty_assertions.workspace = true
24+
25+
[build-dependencies]
26+
anyhow.workspace = true

crates/admin-ui/build.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use std::{env, fs, process};
2+
3+
use anyhow::{Result, bail};
4+
5+
fn main() -> Result<()> {
6+
build_ui()?;
7+
8+
println!("cargo:rerun-if-changed=build.rs");
9+
10+
Ok(())
11+
}
12+
13+
fn build_ui() -> Result<()> {
14+
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap_or_else(|_| ".".to_string());
15+
16+
fs::create_dir_all(format!("{manifest_dir}/ui-dist"))?;
17+
18+
if env::var("CARGO_FEATURE_BUILD_UI").is_ok() {
19+
println!("cargo:rerun-if-changed=ui/");
20+
21+
let status = process::Command::new("pnpm")
22+
.args(["install", "--frozen-lockfile"])
23+
.current_dir(format!("{manifest_dir}/ui"))
24+
.stdout(std::process::Stdio::inherit())
25+
.stderr(std::process::Stdio::inherit())
26+
.status()?;
27+
28+
if !status.success() {
29+
bail!("failed to install ui dependencies with status: {}", status);
30+
}
31+
32+
let status = process::Command::new("pnpm")
33+
.args(["run", "build"])
34+
.current_dir(format!("{manifest_dir}/ui"))
35+
.stdout(std::process::Stdio::inherit())
36+
.stderr(std::process::Stdio::inherit())
37+
.status()?;
38+
39+
if !status.success() {
40+
bail!("failed to build ui with status: {}", status);
41+
}
42+
}
43+
Ok(())
44+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rust_embed::Embed;
55
const UI_INDEX_HTML: &str = "index.html";
66

77
#[derive(Embed)]
8-
#[folder = "ui/dist/"]
8+
#[folder = "ui-dist/"]
99
struct Assets;
1010

1111
pub async fn handler(uri: Uri) -> Response {

0 commit comments

Comments
 (0)