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.
This commit is contained in:
2025-09-08 15:09:19 -05:00
parent 738032ead9
commit df97ba5ce4
2 changed files with 41 additions and 0 deletions

3
.dockerignore Normal file
View File

@@ -0,0 +1,3 @@
.git/
target/
Dockerfile

38
Dockerfile Normal file
View File

@@ -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"]