Create release docker image

This commit is contained in:
2024-05-06 21:27:07 +02:00
parent d63d3ecebc
commit 1c0ba90b8e
8 changed files with 171 additions and 4 deletions

@ -9,6 +9,7 @@ pub mod auth_controller;
pub mod server_controller;
pub mod sys_info_controller;
pub mod vm_controller;
pub mod static_controller;
/// Custom error to ease controller writing
#[derive(Debug)]

@ -0,0 +1,45 @@
#[cfg(debug_assertions)]
pub use serve_static_debug::{root_index, serve_static_content};
#[cfg(not(debug_assertions))]
pub use serve_static_release::{root_index, serve_static_content};
#[cfg(debug_assertions)]
mod serve_static_debug {
use actix_web::{HttpResponse, Responder};
pub async fn root_index() -> impl Responder {
HttpResponse::Ok().body("Hello world! Debug=on for VirtWeb!")
}
pub async fn serve_static_content() -> impl Responder {
HttpResponse::NotFound().body("Hello world! Static assets are not served in debug mode")
}
}
#[cfg(not(debug_assertions))]
mod serve_static_release {
use actix_web::{web, HttpResponse, Responder};
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "static/"]
struct Asset;
fn handle_embedded_file(path: &str, can_fallback: bool) -> HttpResponse {
match (Asset::get(path), can_fallback) {
(Some(content), _) => HttpResponse::Ok()
.content_type(mime_guess::from_path(path).first_or_octet_stream().as_ref())
.body(content.data.into_owned()),
(None, false) => HttpResponse::NotFound().body("404 Not Found"),
(None, true) => handle_embedded_file("index.html", false),
}
}
pub async fn root_index() -> impl Responder {
handle_embedded_file("index.html", false)
}
pub async fn serve_static_content(path: web::Path<String>) -> impl Responder {
handle_embedded_file(path.as_ref(), !path.as_ref().starts_with("static/"))
}
}

@ -11,9 +11,7 @@ use actix_web::{web, App, HttpServer};
use light_openid::basic_state_manager::BasicStateManager;
use remote_backend::app_config::AppConfig;
use remote_backend::constants;
use remote_backend::controllers::{
auth_controller, server_controller, sys_info_controller, vm_controller,
};
use remote_backend::controllers::{auth_controller, server_controller, static_controller, sys_info_controller, vm_controller};
use remote_backend::middlewares::auth_middleware::AuthChecker;
use std::time::Duration;
@ -61,6 +59,7 @@ async fn main() -> std::io::Result<()> {
.app_data(Data::new(RemoteIPConfig {
proxy: AppConfig::get().proxy_ip.clone(),
}))
// Server routes
.route(
"/api/server/config",
web::get().to(server_controller::config),
@ -81,6 +80,7 @@ async fn main() -> std::io::Result<()> {
"/api/auth/sign_out",
web::get().to(auth_controller::sign_out),
)
// VM routes
.route("/api/vm/list", web::get().to(vm_controller::list))
.route("/api/vm/{uid}/state", web::get().to(vm_controller::state))
.route("/api/vm/{uid}/start", web::get().to(vm_controller::start))
@ -99,6 +99,7 @@ async fn main() -> std::io::Result<()> {
"/api/vm/{uid}/screenshot",
web::get().to(vm_controller::screenshot),
)
// Sys info routes
.route(
"/api/sysinfo/config",
web::get().to(sys_info_controller::config),
@ -107,6 +108,12 @@ async fn main() -> std::io::Result<()> {
"/api/sysinfo/status",
web::get().to(sys_info_controller::status),
)
// Static assets
.route("/", web::get().to(static_controller::root_index))
.route(
"/{tail:.*}",
web::get().to(static_controller::serve_static_content),
)
})
.bind(&AppConfig::get().listen_address)?
.run()