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:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
||||
.git/
|
||||
target/
|
||||
Dockerfile
|
||||
38
Dockerfile
Normal file
38
Dockerfile
Normal 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"]
|
||||
Reference in New Issue
Block a user