Skip to content

Commit 8a90005

Browse files
committed
First pass at Dockerfile
It doesn't work on macOS, due to an issue that seems to originate in llama.cpp: ggml-org/llama.cpp#1655
1 parent 45cb9d8 commit 8a90005

File tree

3 files changed

+139
-1
lines changed

3 files changed

+139
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ serde = { version = "1.0.183", features = ["derive"] }
2121
rand = { version = "0.8.5", optional = true }
2222
env_logger = "0.10.0"
2323
dotenv ={ version = "0.15.0", optional = true }
24-
llm = { git = "https://github.com/rustformers/llm.git", branch = "main", optional = true, features = ["metal"] }
24+
llm = { git = "https://github.com/rustformers/llm.git", branch = "main", optional = true}
2525
actix-ws = { version = "0.2.5", optional = true }
2626
actix-rt = { verson = "2.8.0", optional = true }
2727
futures = { version = "0.3.28", optional = true }
@@ -33,6 +33,7 @@ web-sys = { version = "0.3.64" }
3333
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
3434
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate", "gloo-net/websocket", "dep:futures"]
3535
ssr = ["dep:actix-files", "dep:actix-web", "dep:leptos_actix", "leptos/ssr", "leptos_meta/ssr", "leptos_router/ssr", "dep:rand", "dep:dotenv", "dep:llm", "dep:actix-ws", "dep:actix-rt", "dep:futures", "tokio/sync"]
36+
metal = ["llm/metal"]
3637

3738
[profile.dev.package.ggml-sys]
3839
opt-level = 3

Dockerfile

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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"]

compose.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Comments are provided throughout this file to help you get started.
2+
# If you need more help, visit the Docker compose reference guide at
3+
# https://docs.docker.com/compose/compose-file/
4+
5+
# Here the instructions define your application as a service called "server".
6+
# This service is built from the Dockerfile in the current directory.
7+
# You can add other services your application may depend on here, such as a
8+
# database or a cache. For examples, see the Awesome Compose repository:
9+
# https://github.com/docker/awesome-compose
10+
services:
11+
server:
12+
build:
13+
context: .
14+
target: final
15+
ports:
16+
- 3000:3000
17+
18+
# The commented out section below is an example of how to define a PostgreSQL
19+
# database that your application can use. `depends_on` tells Docker Compose to
20+
# start the database before your application. The `db-data` volume persists the
21+
# database data between container restarts. The `db-password` secret is used
22+
# to set the database password. You must create `db/password.txt` and add
23+
# a password of your choosing to it before running `docker compose up`.
24+
# depends_on:
25+
# db:
26+
# condition: service_healthy
27+
# db:
28+
# image: postgres
29+
# restart: always
30+
# user: postgres
31+
# secrets:
32+
# - db-password
33+
# volumes:
34+
# - db-data:/var/lib/postgresql/data
35+
# environment:
36+
# - POSTGRES_DB=example
37+
# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password
38+
# expose:
39+
# - 5432
40+
# healthcheck:
41+
# test: [ "CMD", "pg_isready" ]
42+
# interval: 10s
43+
# timeout: 5s
44+
# retries: 5
45+
# volumes:
46+
# db-data:
47+
# secrets:
48+
# db-password:
49+
# file: db/password.txt
50+

0 commit comments

Comments
 (0)