From df97ba5ce44a45fc56578f719b09b2548df02ee8 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 8 Sep 2025 15:09:19 -0500 Subject: [PATCH] Create Dockerfile for tiny webserver image This will build the WASM binary, generate the JS bindings, and then copy them and the index.html into a BusyBox image for serving. --- .dockerignore | 3 +++ Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4f72f9d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.git/ +target/ +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ec1911a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# This is a simple, stand-alone server image for hosting the WASM file. +# It is not intended to integrate with other webpages, webservers, or sites +# on an existing server. For that, you must patch the code yourself. +FROM rust AS builder + +# Install build tools +RUN rustup target add wasm32-unknown-unknown +RUN cargo install --locked wasm-bindgen-cli + +# Build the program + +# Copy in only the Rust source so the builder doesn't discard any cached build +# layers just because the README changed. +COPY src/ src/ +COPY Cargo.toml Cargo.toml +COPY Cargo.lock Cargo.lock +COPY .cargo .cargo + +RUN cargo build --locked --target wasm32-unknown-unknown --release +RUN wasm-bindgen \ + --no-typescript \ + --target web \ + --out-dir out/ \ + --out-name "chaos-game-rs" \ + target/wasm32-unknown-unknown/release/chaos-game-rs.wasm + + +# Copy WASM & JS to a new image for use +FROM busybox:musl +RUN mkdir -p /var/www +COPY --from=builder out/ /var/www +COPY index.html /var/www/index.html + +WORKDIR /var/www + +EXPOSE 8080/tcp + +CMD ["httpd", "-f"]