|
| 1 | +ARG RUST_VERSION=1.72.0 |
| 2 | +ARG APP_NAME=rusty_llama |
| 3 | +ARG NODE_MAJOR=20 |
| 4 | + |
| 5 | +FROM rust:${RUST_VERSION}-bookworm AS planner |
| 6 | +WORKDIR app |
| 7 | +RUN cargo install cargo-chef |
| 8 | +COPY . . |
| 9 | +RUN cargo chef prepare --recipe-path recipe.json |
| 10 | + |
| 11 | +FROM rust:${RUST_VERSION}-bookworm AS cacher |
| 12 | +WORKDIR app |
| 13 | +RUN cargo install cargo-chef |
| 14 | +COPY --from=planner /app/recipe.json recipe.json |
| 15 | +RUN cargo chef cook --release --recipe-path recipe.json |
| 16 | + |
| 17 | +FROM rust:${RUST_VERSION}-bookworm AS build |
| 18 | +ARG APP_NAME |
| 19 | +WORKDIR /app |
| 20 | + |
| 21 | +# direct apt-get to the latest version of node, which is needed for tailwind |
| 22 | +# this is all from here https://github.com/nodesource/distributions#debian-versions |
| 23 | +RUN apt-get update |
| 24 | +RUN apt-get install -y ca-certificates curl gnupg |
| 25 | +RUN mkdir -p /etc/apt/keyrings |
| 26 | +RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg |
| 27 | +RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list |
| 28 | +RUN apt-get update && apt-get install -y pkg-config openssl libssl-dev nodejs |
| 29 | +# RUN apk --no-cache add pkgconfig openssl-dev nodejs npm musl-dev |
| 30 | + |
| 31 | +COPY --from=cacher /app/target /target |
| 32 | +COPY --from=cacher /usr/local/cargo /usr/local/cargo |
| 33 | + |
| 34 | +RUN cargo install cargo-leptos |
| 35 | + |
| 36 | + |
| 37 | +COPY . /app |
| 38 | +RUN npm install |
| 39 | +RUN npx tailwindcss -i ./input.css -o ./style/output.css |
| 40 | +RUN rustup target add wasm32-unknown-unknown |
| 41 | +RUN cargo leptos build --release -vv |
| 42 | +# RUN cp ./target/server/release/$APP_NAME /bin/server |
| 43 | +# RUN cp -r ./target/site /bin/site |
| 44 | + |
| 45 | +################################################################################ |
| 46 | +# Create a new stage for running the application that contains the minimal |
| 47 | +# runtime dependencies for the application. This often uses a different base |
| 48 | +# image from the build stage where the necessary files are copied from the build |
| 49 | +# stage. |
| 50 | +# |
| 51 | +# The example below uses the debian bookworm image as the foundation for running the app. |
| 52 | +# By specifying the "slim-bookworm" tag, it will also use whatever happens to be the |
| 53 | +# most recent version of that tag when you build your Dockerfile. If |
| 54 | +# reproducability is important, consider using a digest |
| 55 | +# (e.g., debian@sha256:ac707220fbd7b67fc19b112cee8170b41a9e97f703f588b2cdbbcdcecdd8af57). |
| 56 | +FROM rustlang/rust:nightly-bookworm AS final |
| 57 | +# |
| 58 | +# install openssl |
| 59 | +RUN apt-get update && apt-get install -y openssl |
| 60 | +# RUN apk --no-cache add openssl |
| 61 | +# Create a non-privileged user that the app will run under. |
| 62 | +# See https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user |
| 63 | +ARG UID=10001 |
| 64 | +RUN adduser \ |
| 65 | + --disabled-password \ |
| 66 | + --gecos "" \ |
| 67 | + --home "/nonexistent" \ |
| 68 | + --shell "/sbin/nologin" \ |
| 69 | + --no-create-home \ |
| 70 | + --uid "${UID}" \ |
| 71 | + appuser |
| 72 | +USER appuser |
| 73 | + |
| 74 | +# grab the model |
| 75 | +COPY --from=build llama-2-13b-chat.ggmlv3.q4_K_S.bin /bin/model |
| 76 | +ENV MODEL_PATH=/bin/model |
| 77 | +# Copy the executable from the "build" stage. |
| 78 | +COPY --from=build /app/target/server/release/$APP_NAME /bin/ |
| 79 | + |
| 80 | +# Copy the frontend stuff |
| 81 | +COPY --from=build /app/target/site /bin/site |
| 82 | + |
| 83 | +# Expose the port that the application listens on. |
| 84 | +EXPOSE 3000 |
| 85 | + |
| 86 | +# What the container should run when it is started. |
| 87 | +CMD ["/bin/server"] |
0 commit comments