-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: crate-type on Cargo.toml as prerequisite for wasm-pack feat: multi-stage build with final artifacts for node todo: go back one stage and serve the spa with trunk instead feat: nginx.conf basic configuration for wasm mimetypes and CORS handling by connecting to the server api; port defined on compose.yml
- Loading branch information
Showing
4 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
FROM rust:1.77.1-alpine3.18 as build | ||
# This is the first stage. This image is used to compile the Rust application. | ||
#FROM rust:bookworm as builder | ||
FROM rust:1.77.1-alpine3.18 as builder | ||
WORKDIR /app | ||
|
||
# | ||
# build stage | ||
# | ||
WORKDIR /usr/src/mcl/ | ||
COPY . . | ||
COPY .env.docker .env | ||
|
||
# | ||
#RUN apt-update && apt-get --yes install pkg-config libssl-dev \ | ||
#cargo install trunk --version 0.16.0 \ | ||
RUN apk update && apk add --upgrade "pkgconf" "openssl-dev" && \ | ||
apk add --no-cache musl-dev && \ | ||
wget -qO- https://github.com/trunk-rs/trunk/releases/download/v0.19.2/trunk-x86_64-unknown-linux-musl.tar.gz | tar -xzf- && \ | ||
rustup target add wasm32-unknown-unknown && \ | ||
rustup component add rustfmt && \ | ||
rustup component add clippy-preview && \ | ||
cargo install --path . | ||
# Install the package in the current directory | ||
CMD ["./target/release/app"] | ||
|
||
# | ||
# deploy stage | ||
# | ||
#FROM gcr.io/distroless/cc-debian11 as relay | ||
#FROM debian:bookworm-slim | ||
FROM alpine:3.18 as relay | ||
#FROM rust:1.77.1-alpine3.18 as relay | ||
|
||
#COPY --from=builder /usr/local/cargo/bin/app /usr/local/bin/app | ||
WORKDIR /app | ||
|
||
# will work with others, but not wasm-bindgen. Use trunk or others | ||
COPY --from=builder /usr/local/cargo/bin/client /usr/local/bin/app | ||
COPY --from=builder ["/app/index.html", "/app/Cargo.toml", "/app/Cargo.lock", "/app/dist/", "/app/trunk", "/app/.env", "/app/src/", "."] | ||
COPY --from=builder /app/src/ ./src/ | ||
|
||
RUN apk add --no-cache musl-dev wasm-pack && \ | ||
cargo update -p bumpalo@3.15.4 --precise 3.12.0 && \ | ||
wasm-pack build --target nodejs | ||
|
||
ARG ARCH=aarch64 | ||
EXPOSE 8081 | ||
|
||
#WORKDIR /usr/src/mcl/ | ||
CMD ["./trunk", "serve", "--address", "0.0.0.0", "--port", "8081"] | ||
#CMD ["wasm-pack", "build"] | ||
#works | ||
##./trunk serve --address 0.0.0.0 --port 8080 | ||
ENTRYPOINT ["/bin/sh"] | ||
|
||
#COPY --from=build /usr/local/cargo/bin/mcl /usr/local/bin/mcl | ||
COPY --from=build /usr/local/cargo/bin/client /usr/local/bin/mcl | ||
#COPY --from=build /usr/src/mcl/.env /usr/local/bin/.env | ||
COPY --from=build /usr/src/mcl/.env /.env | ||
FROM node:21-alpine3.18 | ||
|
||
WORKDIR /app/ | ||
COPY --from=relay /app/pkg/ /app/pkg/ | ||
|
||
CMD ["mcl"] | ||
#CMD ["cargo", "run"] | ||
ENTRYPOINT [ "/bin/sh" ] | ||
EXPOSE 8081 | ||
|
||
ENTRYPOINT ["/bin/sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
include /etc/nginx/mime.types; | ||
|
||
server { | ||
# ipv4 | ||
listen 443 ssl; | ||
# ipv6 | ||
listen [::]:443 ssl; | ||
server_name ${gh_user}.github.io/${repo_subdir}; | ||
|
||
types { | ||
application/wasm wasm; | ||
} | ||
|
||
# yew-rs frontend | ||
location / { | ||
root ./client/dist/index.html; | ||
try_files $uri $uri/ ./client/index.html; | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
} | ||
# SpringBoot backend | ||
location /api { | ||
proxy_pass http://localhost:8080; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header Host $http_host; | ||
|
||
} | ||
} |