From 5e4b7f04b7ab3102a171d9f61b80ef01632af6c9 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Thu, 4 Sep 2025 09:07:31 -0500 Subject: [PATCH] Dockerfile for WASM build's webserver --- .dockerignore | 3 +++ Dockerfile | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..0822575c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +fly.toml +.git/ +target/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..313ccdf3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM rust:1.89 as builder + +RUN apt-get update +RUN apt-get install -y --no-install-recommends libasound2-dev libudev-dev +RUN rustup target add wasm32-unknown-unknown +RUN cargo install --locked wasm-bindgen-cli + +# Copy only the package manifest and source code. Otherwise changes to anything +# will cause Docker to re-run `cargo build` even when the source hasn't changed. +COPY src/ ./src +COPY Cargo.toml ./Cargo.toml + +RUN cargo build --target wasm32-unknown-unknown --profile=wasm-release +RUN wasm-bindgen --no-typescript --target web --out-dir ./out/ --out-name "boids" target/wasm32-unknown-unknown/wasm-release/another-boids-in-rust.wasm +COPY www/index.html out/index.html + +FROM busybox +RUN mkdir -p /var/www +COPY --from=builder ./out/ /var/www +WORKDIR /var/www + +# TODO: Make httpd accept interrupt signals so the container exits properly. +# (+c and `docker stop ...` don't work because Busybox doesn't answer) +CMD ["httpd", "-f", "-p", "8080"]