2026-06-11 15:43:10 +08:00
|
|
|
# syntax=docker/dockerfile:1
|
|
|
|
|
|
|
|
|
|
########################################
|
|
|
|
|
# Build stage
|
|
|
|
|
########################################
|
|
|
|
|
FROM rust:1-bookworm AS builder
|
|
|
|
|
|
2026-06-11 16:25:13 +08:00
|
|
|
# sqlx's SQLite driver bundles libsqlite3 and compiles it with the C toolchain
|
|
|
|
|
# already in the base image — no sqlcipher, no OpenSSL, no extra apt packages.
|
2026-06-11 15:43:10 +08:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Build dependencies first against a stub binary so the (slow) SQLCipher/OpenSSL
|
|
|
|
|
# compilation is cached and only re-runs when Cargo.toml/Cargo.lock change.
|
|
|
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
|
RUN mkdir src \
|
|
|
|
|
&& echo "fn main() {}" > src/main.rs \
|
|
|
|
|
&& cargo build --release --locked \
|
2026-06-11 15:47:15 +08:00
|
|
|
&& rm -rf src target/release/deps/chat_store* target/release/chat-store
|
2026-06-11 15:43:10 +08:00
|
|
|
|
|
|
|
|
# Now build the real binary; dependency artifacts above are reused.
|
|
|
|
|
COPY src ./src
|
2026-06-11 15:47:15 +08:00
|
|
|
RUN cargo build --release --locked --bin chat-store
|
2026-06-11 15:43:10 +08:00
|
|
|
|
|
|
|
|
########################################
|
|
|
|
|
# Runtime stage
|
|
|
|
|
########################################
|
|
|
|
|
FROM debian:bookworm-slim AS runtime
|
|
|
|
|
|
|
|
|
|
RUN apt-get update \
|
|
|
|
|
&& apt-get install -y --no-install-recommends ca-certificates \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
2026-06-11 15:47:15 +08:00
|
|
|
COPY --from=builder /app/target/release/chat-store /usr/local/bin/chat-store
|
2026-06-11 15:43:10 +08:00
|
|
|
|
|
|
|
|
# Matches the default --bind 0.0.0.0:8080.
|
|
|
|
|
EXPOSE 8080
|
|
|
|
|
|
|
|
|
|
# Persist the SQLite database on a volume rather than the container layer.
|
|
|
|
|
VOLUME ["/data"]
|
|
|
|
|
ENV RUST_LOG=info
|
|
|
|
|
|
2026-06-11 15:47:15 +08:00
|
|
|
ENTRYPOINT ["chat-store"]
|
|
|
|
|
CMD ["--bind", "0.0.0.0:8080", "--db", "/data/chat-store.db"]
|