From 5b6601cc15f373cdd432f3a5a172a873d4ddf57b Mon Sep 17 00:00:00 2001 From: victor <52110451+cs50victor@users.noreply.github.com> Date: Tue, 30 Jan 2024 18:47:41 -0500 Subject: [PATCH] refactor: move examples to crates (#13) --- .dockerignore | 15 +++++++++ Cargo.toml | 2 +- Dockerfile | 25 +++++++++++++++ .../minimal_example}/Cargo.toml | 0 .../minimal_example}/src/main.rs | 0 {examples => crates}/new_media/Cargo.toml | 0 .../new_media/src/controls.rs | 0 {examples => crates}/new_media/src/main.rs | 2 +- {examples => crates}/new_media/src/server.rs | 0 demo/app/page.tsx | 2 +- demo/components/Canvas.tsx | 25 +-------------- demo/components/Controller.tsx | 31 +++++++++++++++++++ demo/components/WebSocketExample.tsx | 11 +++---- 13 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile rename {examples/minimal => crates/minimal_example}/Cargo.toml (100%) rename {examples/minimal => crates/minimal_example}/src/main.rs (100%) rename {examples => crates}/new_media/Cargo.toml (100%) rename {examples => crates}/new_media/src/controls.rs (100%) rename {examples => crates}/new_media/src/main.rs (97%) rename {examples => crates}/new_media/src/server.rs (100%) create mode 100644 demo/components/Controller.tsx diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..62aa066 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +# Ignore everything +* + +# Allow files and directories +!/.cargo/ +!/Cargo.toml +!/Cargo.lock +!/crates/new_media +!/recipie.json +# 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 7c8c3f4..7bd7a91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = ["crates/*", "examples/*"] +members = ["crates/*"] package.rust-version = "1.75.0" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..91e0152 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM rust as planner +WORKDIR /app +RUN cargo install cargo-chef +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +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 + +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 + +FROM bitnami/minideb:bookworm +COPY --from=builder /app/target/release/new_media /app/new_media +WORKDIR /app + +EXPOSE 8080 +CMD ["./new_media"] diff --git a/examples/minimal/Cargo.toml b/crates/minimal_example/Cargo.toml similarity index 100% rename from examples/minimal/Cargo.toml rename to crates/minimal_example/Cargo.toml diff --git a/examples/minimal/src/main.rs b/crates/minimal_example/src/main.rs similarity index 100% rename from examples/minimal/src/main.rs rename to crates/minimal_example/src/main.rs diff --git a/examples/new_media/Cargo.toml b/crates/new_media/Cargo.toml similarity index 100% rename from examples/new_media/Cargo.toml rename to crates/new_media/Cargo.toml diff --git a/examples/new_media/src/controls.rs b/crates/new_media/src/controls.rs similarity index 100% rename from examples/new_media/src/controls.rs rename to crates/new_media/src/controls.rs diff --git a/examples/new_media/src/main.rs b/crates/new_media/src/main.rs similarity index 97% rename from examples/new_media/src/main.rs rename to crates/new_media/src/main.rs index c66d73a..fd0189e 100644 --- a/examples/new_media/src/main.rs +++ b/crates/new_media/src/main.rs @@ -30,7 +30,7 @@ fn setup_gaussian_cloud( ) { // let remote_file = Some("https://huggingface.co/datasets/cs50victor/splats/resolve/main/train/point_cloud/iteration_7000/point_cloud.gcloud"); // TODO: figure out how to load remote files later - let splat_file = "splats/counter/point_cloud/iteration_7000/point_cloud.gcloud"; + let splat_file = "splats/playroom/point_cloud/iteration_7000/point_cloud.gcloud"; log::info!("loading {}", splat_file); let cloud = asset_server.load(splat_file.to_string()); diff --git a/examples/new_media/src/server.rs b/crates/new_media/src/server.rs similarity index 100% rename from examples/new_media/src/server.rs rename to crates/new_media/src/server.rs diff --git a/demo/app/page.tsx b/demo/app/page.tsx index 2edefbc..0a420a7 100644 --- a/demo/app/page.tsx +++ b/demo/app/page.tsx @@ -4,7 +4,7 @@ export default function Page() { return (