This commit is contained in:
parent
4e109bed1d
commit
6c4743659c
7 changed files with 502 additions and 13 deletions
|
|
@ -122,6 +122,11 @@ crate.spec(
|
||||||
package = "axum-jsonschema",
|
package = "axum-jsonschema",
|
||||||
version = "0.8.0",
|
version = "0.8.0",
|
||||||
)
|
)
|
||||||
|
crate.spec(
|
||||||
|
features = ["debug-embed"],
|
||||||
|
package = "rust-embed",
|
||||||
|
version = "8.0",
|
||||||
|
)
|
||||||
crate.from_specs()
|
crate.from_specs()
|
||||||
use_repo(crate, "crates")
|
use_repo(crate, "crates")
|
||||||
|
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -761,7 +761,7 @@ fi
|
||||||
]
|
]
|
||||||
|
|
||||||
runfiles = ctx.runfiles(
|
runfiles = ctx.runfiles(
|
||||||
files = [ctx.executable.lookup, ctx.executable._service, ctx.executable.analyze, ctx.executable.exec] + configure_executables,
|
files = [ctx.executable.lookup, ctx.executable._service, ctx.executable.analyze, ctx.executable.exec] + configure_executables + ctx.files._dashboard,
|
||||||
).merge(ctx.attr.lookup.default_runfiles).merge(ctx.attr._service.default_runfiles).merge(
|
).merge(ctx.attr.lookup.default_runfiles).merge(ctx.attr._service.default_runfiles).merge(
|
||||||
ctx.attr.analyze.default_runfiles).merge(ctx.attr.exec.default_runfiles).merge(
|
ctx.attr.analyze.default_runfiles).merge(ctx.attr.exec.default_runfiles).merge(
|
||||||
ctx.attr._bash_runfiles.default_runfiles
|
ctx.attr._bash_runfiles.default_runfiles
|
||||||
|
|
@ -821,6 +821,10 @@ _databuild_graph_service = rule(
|
||||||
executable = True,
|
executable = True,
|
||||||
cfg = "target",
|
cfg = "target",
|
||||||
),
|
),
|
||||||
|
"_dashboard": attr.label(
|
||||||
|
default = "@databuild//databuild/dashboard:dist",
|
||||||
|
allow_files = True,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
executable = True,
|
executable = True,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ use aide::{
|
||||||
},
|
},
|
||||||
openapi::OpenApi,
|
openapi::OpenApi,
|
||||||
};
|
};
|
||||||
use axum::Extension;
|
use axum::{Extension, response::Response, http::StatusCode};
|
||||||
use axum_jsonschema::Json;
|
use axum_jsonschema::Json;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use schemars::JsonSchema;
|
use schemars::JsonSchema;
|
||||||
|
|
@ -132,7 +132,7 @@ impl BuildGraphService {
|
||||||
pub fn create_router(self) -> axum::Router {
|
pub fn create_router(self) -> axum::Router {
|
||||||
let mut api = OpenApi::default();
|
let mut api = OpenApi::default();
|
||||||
|
|
||||||
let router = ApiRouter::new()
|
let api_router = ApiRouter::new()
|
||||||
.api_route("/api/v1/builds", post(handlers::submit_build_request))
|
.api_route("/api/v1/builds", post(handlers::submit_build_request))
|
||||||
.api_route("/api/v1/builds/:build_request_id", get(handlers::get_build_status))
|
.api_route("/api/v1/builds/:build_request_id", get(handlers::get_build_status))
|
||||||
.api_route("/api/v1/builds/:build_request_id", delete(handlers::cancel_build_request))
|
.api_route("/api/v1/builds/:build_request_id", delete(handlers::cancel_build_request))
|
||||||
|
|
@ -143,7 +143,13 @@ impl BuildGraphService {
|
||||||
.with_state(Arc::new(self))
|
.with_state(Arc::new(self))
|
||||||
.finish_api(&mut api);
|
.finish_api(&mut api);
|
||||||
|
|
||||||
router
|
let static_router = axum::Router::new()
|
||||||
|
.route("/", axum::routing::get(Self::serve_index))
|
||||||
|
.route("/static/*file", axum::routing::get(Self::serve_static));
|
||||||
|
|
||||||
|
axum::Router::new()
|
||||||
|
.merge(api_router)
|
||||||
|
.merge(static_router)
|
||||||
.layer(Extension(api))
|
.layer(Extension(api))
|
||||||
.layer(axum::middleware::from_fn(Self::cors_middleware))
|
.layer(axum::middleware::from_fn(Self::cors_middleware))
|
||||||
}
|
}
|
||||||
|
|
@ -152,6 +158,62 @@ impl BuildGraphService {
|
||||||
Json(api)
|
Json(api)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn serve_index() -> Response {
|
||||||
|
let index_path = Self::get_runfile_path("databuild+/databuild/dashboard/index.html");
|
||||||
|
|
||||||
|
match std::fs::read_to_string(&index_path) {
|
||||||
|
Ok(content) => Response::builder()
|
||||||
|
.header("content-type", "text/html")
|
||||||
|
.body(content.into())
|
||||||
|
.unwrap(),
|
||||||
|
Err(_) => Response::builder()
|
||||||
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
.body("Failed to load dashboard".into())
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn serve_static(axum::extract::Path(file): axum::extract::Path<String>) -> Response {
|
||||||
|
let file_path = Self::get_runfile_path(&format!("databuild+/databuild/dashboard/{}", file));
|
||||||
|
|
||||||
|
match std::fs::read(file_path) {
|
||||||
|
Ok(content) => {
|
||||||
|
let content_type = match file.split('.').last() {
|
||||||
|
Some("html") => "text/html",
|
||||||
|
Some("css") => "text/css",
|
||||||
|
Some("js") => "application/javascript",
|
||||||
|
Some("png") => "image/png",
|
||||||
|
Some("jpg") | Some("jpeg") => "image/jpeg",
|
||||||
|
Some("svg") => "image/svg+xml",
|
||||||
|
Some("ico") => "image/x-icon",
|
||||||
|
_ => "application/octet-stream",
|
||||||
|
};
|
||||||
|
|
||||||
|
Response::builder()
|
||||||
|
.header("content-type", content_type)
|
||||||
|
.body(content.into())
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
Err(_) => Response::builder()
|
||||||
|
.status(StatusCode::NOT_FOUND)
|
||||||
|
.body("404 Not Found".into())
|
||||||
|
.unwrap(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_runfile_path(relative_path: &str) -> String {
|
||||||
|
if let Ok(runfiles_dir) = std::env::var("RUNFILES_DIR") {
|
||||||
|
format!("{}/{}", runfiles_dir, relative_path)
|
||||||
|
} else if let Ok(_manifest_file) = std::env::var("RUNFILES_MANIFEST_FILE") {
|
||||||
|
// Parse manifest file to find the actual path
|
||||||
|
// For now, just use the relative path
|
||||||
|
relative_path.to_string()
|
||||||
|
} else {
|
||||||
|
// Development mode - files might be in the workspace
|
||||||
|
relative_path.to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn cors_middleware(
|
pub async fn cors_middleware(
|
||||||
request: axum::http::Request<axum::body::Body>,
|
request: axum::http::Request<axum::body::Body>,
|
||||||
next: axum::middleware::Next,
|
next: axum::middleware::Next,
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,5 @@ use_repo(oci, "debian", "debian_linux_amd64", "debian_linux_arm64_v8")
|
||||||
bazel_dep(name = "platforms", version = "0.0.11")
|
bazel_dep(name = "platforms", version = "0.0.11")
|
||||||
|
|
||||||
# TypeScript rules for handling skipLibCheck flag
|
# TypeScript rules for handling skipLibCheck flag
|
||||||
|
# https://github.com/aspect-build/rules_ts/issues/483#issuecomment-1814586063
|
||||||
bazel_dep(name = "aspect_rules_ts", version = "3.6.3")
|
bazel_dep(name = "aspect_rules_ts", version = "3.6.3")
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -52,4 +52,5 @@ use_repo(oci, "debian", "debian_linux_amd64", "debian_linux_arm64_v8")
|
||||||
bazel_dep(name = "platforms", version = "0.0.11")
|
bazel_dep(name = "platforms", version = "0.0.11")
|
||||||
|
|
||||||
# TypeScript rules for handling skipLibCheck flag
|
# TypeScript rules for handling skipLibCheck flag
|
||||||
|
# https://github.com/aspect-build/rules_ts/issues/483#issuecomment-1814586063
|
||||||
bazel_dep(name = "aspect_rules_ts", version = "3.6.3")
|
bazel_dep(name = "aspect_rules_ts", version = "3.6.3")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue