From 0258a918306c2c8fa817b93d9a43ffaa2860072a Mon Sep 17 00:00:00 2001 From: victor <52110451+cs50victor@users.noreply.github.com> Date: Thu, 15 Feb 2024 23:31:48 -0500 Subject: [PATCH] feat: docker (#18) * chore: remove unused files * refactor: docker works --- .dockerignore | 9 ++++--- Cargo.toml | 4 +-- Dockerfile | 25 ++++++++++++++--- README.md | 4 +++ crates/bevy_headless/src/plugin.rs | 6 ----- crates/new_media/Cargo.toml | 26 ------------------ new_media/Cargo.toml | 27 +++++++++++++++++++ .../new_media => new_media}/src/controls.rs | 0 {crates/new_media => new_media}/src/main.rs | 7 +++-- {crates/new_media => new_media}/src/server.rs | 2 +- package.json | 1 + 11 files changed, 65 insertions(+), 46 deletions(-) delete mode 100644 crates/new_media/Cargo.toml create mode 100644 new_media/Cargo.toml rename {crates/new_media => new_media}/src/controls.rs (100%) rename {crates/new_media => new_media}/src/main.rs (93%) rename {crates/new_media => new_media}/src/server.rs (97%) diff --git a/.dockerignore b/.dockerignore index 62aa066..f5284ad 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,12 +4,15 @@ # Allow files and directories !/.cargo/ !/Cargo.toml -!/Cargo.lock -!/crates/new_media -!/recipie.json +!/crates/bevy_ws_server +!/crates/bevy_headless +!/new_media/Cargo.toml +!/new_media/src/** + # Ignore unnecessary files inside allowed directories # This should go after the allowed directories # **/*~ # **/*.log # **/.DS_Store # **/Thumbs.db + diff --git a/Cargo.toml b/Cargo.toml index 7bd7a91..03ab94d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["crates/*"] +members = ["crates/*", "new_media"] package.rust-version = "1.75.0" @@ -28,7 +28,7 @@ bevy = { version = "0.12.1", default-features = false, features = [ "bevy_asset", "bevy_core_pipeline", "bevy_render", - "multi-threaded" + "multi-threaded", ] } bevy_panorbit_camera = "0.10.0" crossbeam-channel = "0.5.10" diff --git a/Dockerfile b/Dockerfile index 91e0152..4748d08 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,18 +8,35 @@ FROM rust as cacher WORKDIR /app RUN cargo install cargo-chef COPY --from=planner /app/recipe.json recipe.json -RUN cargo chef cook --release --recipe-path=recipe.json +# Build tools +RUN apt-get update && apt-get install -y -qq xorg xauth +RUN cargo chef cook --release --features docker --recipe-path=recipe.json FROM rust as builder COPY . /app WORKDIR /app COPY --from=cacher /app/target target COPY --from=cacher /usr/local/cargo /usr/local/cargo -RUN cargo build --release +# Build tools +RUN apt-get update && apt-get install -y -qq xorg xauth +RUN cargo build --release --features docker -FROM bitnami/minideb:bookworm +FROM ubuntu:22.04 COPY --from=builder /app/target/release/new_media /app/new_media WORKDIR /app +# Build tools +RUN apt-get update +RUN apt-get install -y -qq build-essential software-properties-common pkg-config xorg openbox xauth +# Bevy dependencies +RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -yq libasound2-dev libudev-dev libxkbcommon-x11-0 +RUN apt-get update -y -qq +RUN add-apt-repository ppa:kisak/turtle -y +RUN apt-get update +RUN apt install -y xvfb libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers +ENV CARGO_TARGET_DIR="../rust-target" +ENV PATH="/root/.cargo/bin:${PATH}" + EXPOSE 8080 -CMD ["./new_media"] + +CMD xvfb-run -s "-screen 0 1024x768x24" "./new_media" \ No newline at end of file diff --git a/README.md b/README.md index 855f0ec..98baed6 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ ## notes to self - only "audio" feature MUST be real-time "lipsync" - focus on primarily building realistic camera features not visual effects existing video editing programs (i.e Davinci) work on. + + +- run web: `pnpm --dir=demo dev` +- run server: `docker run -it -p 8080:8080 $(docker build -q .)` diff --git a/crates/bevy_headless/src/plugin.rs b/crates/bevy_headless/src/plugin.rs index 848d310..61772a8 100644 --- a/crates/bevy_headless/src/plugin.rs +++ b/crates/bevy_headless/src/plugin.rs @@ -238,12 +238,6 @@ fn capture_img_bytes( match ImageBuffer::::from_raw(source_size.width, source_size.height, image_bytes) { Some(image_bytes) => { curr_img.0.lock().update_data(frame_id, &image_bytes, extension.to_owned()); - - // if let Some(curr_img) = curr_img.as_mut(){ - // curr_img.update_data(frame_id, &image_bytes, extension.to_owned()); - // }else{ - // log::info!("Curr Image Resource still doesn't exist"); - // } }, None => { log::error!("Failed creating image buffer for frame - '{frame_id}'"); diff --git a/crates/new_media/Cargo.toml b/crates/new_media/Cargo.toml deleted file mode 100644 index ae04407..0000000 --- a/crates/new_media/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "new_media" -version = "0.0.1" -edition = "2021" -rust-version.workspace = true -default-run = "new_media" - -[dependencies] -anyhow = {workspace = true} -async-net = {workspace = true} -base64 = {workspace = true} -bevy = { workspace = true } -bevy_ws_server = { path = "../../crates/bevy_ws_server" } -bevy_headless = { path = "../../crates/bevy_headless" } -bevy_gaussian_splatting = { version = "2.0.2", default-features = true } -bevy_panorbit_camera = { workspace = true } -crossbeam-channel = { workspace = true } -dotenvy = "0.15.7" -log = { workspace = true } -pretty_env_logger = {workspace = true} -serde = { version = "1.0.192", features = ["derive"] } -serde_json = "1.0.108" -tungstenite = {workspace = true} - -# [target.i686-unknown-linux-gnu.dependencies] -# winit = { version = "0.29.10", default-features = false, features = ["x11"]} diff --git a/new_media/Cargo.toml b/new_media/Cargo.toml new file mode 100644 index 0000000..5bc410f --- /dev/null +++ b/new_media/Cargo.toml @@ -0,0 +1,27 @@ +[package] +name = "new_media" +version = "0.0.1" +edition = "2021" +rust-version.workspace = true +default-run = "new_media" + +[dependencies] +anyhow = { workspace = true } +async-net = { workspace = true } +base64 = { workspace = true } +bevy = { workspace = true } +bevy_ws_server = { path = "../crates/bevy_ws_server" } +bevy_headless = { path = "../crates/bevy_headless" } +bevy_gaussian_splatting = { version = "2.0.2", default-features = true } +bevy_panorbit_camera = { workspace = true } +crossbeam-channel = { workspace = true } +dotenvy = "0.15.7" +log = { workspace = true } +pretty_env_logger = { workspace = true } +serde = { version = "1.0.192", features = ["derive"] } +serde_json = "1.0.108" +tungstenite = { workspace = true } +openssl = { version = "0.10.63", features = ["vendored"], optional = true} + +[features] +docker = ["dep:openssl","bevy/x11"] diff --git a/crates/new_media/src/controls.rs b/new_media/src/controls.rs similarity index 100% rename from crates/new_media/src/controls.rs rename to new_media/src/controls.rs diff --git a/crates/new_media/src/main.rs b/new_media/src/main.rs similarity index 93% rename from crates/new_media/src/main.rs rename to new_media/src/main.rs index db0bbf4..7198dbf 100644 --- a/crates/new_media/src/main.rs +++ b/new_media/src/main.rs @@ -23,7 +23,7 @@ use server::{receive_message, start_ws}; fn setup_gaussian_cloud( mut commands: Commands, asset_server: Res, - _gaussian_assets: ResMut>, + mut gaussian_assets: ResMut>, mut scene_controller: ResMut, mut images: ResMut>, export_sources: ResMut>, @@ -32,9 +32,9 @@ fn setup_gaussian_cloud( // TODO: figure out how to load remote files later let splat_file = "splats/garden/point_cloud/iteration_7000/point_cloud.gcloud"; log::info!("loading {}", splat_file); - let cloud = asset_server.load(splat_file.to_string()); + // let cloud = asset_server.load(splat_file.to_string()); - // let cloud = gaussian_assets.add(GaussianCloud::test_model()); + let cloud = gaussian_assets.add(GaussianCloud::test_model()); let render_target = bevy_headless::setup_render_target( &mut commands, @@ -70,7 +70,6 @@ pub struct AppConfig { fn main() { dotenvy::from_filename_override(".env.local").ok(); - // ************** REQUIRED ENV VARS ************** pretty_env_logger::formatted_builder() .filter_module("new_media", log::LevelFilter::Info) diff --git a/crates/new_media/src/server.rs b/new_media/src/server.rs similarity index 97% rename from crates/new_media/src/server.rs rename to new_media/src/server.rs index cc04fd8..7fc7774 100644 --- a/crates/new_media/src/server.rs +++ b/new_media/src/server.rs @@ -38,7 +38,7 @@ pub fn start_ws(listener: Res) { .parse::() .expect("PORT couldn't be set"); - match listener.listen(([127, 0, 0, 1], port), None) { + match listener.listen(([0, 0, 0, 0], port), None) { Ok(host) => { log::info!("Websocket Server listening on {host:?}"); }, diff --git a/package.json b/package.json index 1290e3e..6bed94e 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "build": "pnpm --dir=demo build", + "dev:server": "docker run --rm -it $(docker build -q .)", "dev": "concurrently --names 'WEB,SERVER' -c 'auto' \"pnpm --dir=demo dev\" \"cargo rr --bin new_media\"", "format": "concurrently --names 'fmt:web,fmt:rs,fmt:toml' -c 'auto' \"pnpm format:prettier\" \"pnpm format:rs\" \"pnpm format:toml\"", "format:prettier": "prettier --write \"**/*.{js,ts,tsx}\"",