From 01c3ceb76d0bb80014066d72dae8922567fef6fd Mon Sep 17 00:00:00 2001 From: Tuan-Dat Tran Date: Fri, 7 Feb 2025 00:28:29 +0100 Subject: [PATCH] feat(deploy): Set Dockerfile according to official dioxus docs Signed-off-by: Tuan-Dat Tran --- Dockerfile | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index fec47b2..9ba41e0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,33 @@ -FROM rust:1.84.0 AS dioxus -RUN cargo install dioxus-cli@^0.6 +FROM rust:1 AS chef +RUN cargo install cargo-chef +WORKDIR /app -FROM dioxus AS builder -WORKDIR /athome/ -RUN apt-get update && apt install libwebkit2gtk-4.1-dev build-essential curl npm \ - wget file libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev -y\ - && rm -rf /var/lib/apt/lists/* -RUN npm install -D tailwindcss -COPY ./Cargo.toml ./Cargo.toml -COPY ./Dioxus.toml ./Dioxus.toml -COPY ./input.css ./input.css -COPY ./tailwind.config.js ./tailwind.config.js -COPY ./src/ ./src/ -COPY ./assets/ ./assets/ +FROM chef AS planner +COPY . . +RUN cargo chef prepare --recipe-path recipe.json + +FROM chef AS builder +COPY --from=planner /app/recipe.json recipe.json +RUN cargo chef cook --release --recipe-path recipe.json +COPY . . + +# Install `dx` +RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash +RUN cargo binstall dioxus-cli --root /.cargo -y --force +ENV PATH="/.cargo/bin:$PATH" + +# Create the final bundle folder. Bundle always executes in release mode with optimizations enabled RUN dx bundle --platform web -FROM alpine:3 AS runner -WORKDIR /app/ -COPY --from=builder /athome/docs/ ./ -CMD [ "./server" ] +FROM chef AS runtime +COPY --from=builder /app/target/dx/athome/release/web/ /usr/local/app + +# set our port and make sure to listen for all connections +ENV PORT=8080 +ENV IP=0.0.0.0 + +# expose the port 8080 +EXPOSE 8080 + +WORKDIR /usr/local/app +ENTRYPOINT [ "/usr/local/app/server" ]