-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
58 lines (42 loc) · 1.42 KB
/
Copy pathDockerfile
File metadata and controls
58 lines (42 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Stage 1: Planner - Generate dependency recipe
FROM rust:1.90 AS planner
WORKDIR /app
# Install cargo-chef
RUN cargo install cargo-chef
# Copy backend source files to generate recipe
COPY backend/ .
# Generate recipe.json for dependency caching
RUN cargo chef prepare --recipe-path recipe.json
# Stage 2: Builder - Build dependencies and application
FROM rust:1.90 AS builder
WORKDIR /app
# Install cargo-chef and protobuf compiler
RUN cargo install cargo-chef && \
apt-get update && \
apt-get install -y protobuf-compiler && \
rm -rf /var/lib/apt/lists/*
# Copy the recipe from planner
COPY --from=planner /app/recipe.json recipe.json
# Build dependencies only (this layer will be cached)
RUN cargo chef cook --release --recipe-path recipe.json
# Copy the rest of the backend source code
COPY backend/ .
# Copy protobuf files (needed for build.rs)
COPY protos/ /protos
# Build the gRPC server binary
RUN cargo build --release --bin grpc-server
# Stage 3: Runtime - Minimal runtime image
FROM debian:trixie-slim AS runtime
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && \
apt-get install -y ca-certificates libssl3 && \
rm -rf /var/lib/apt/lists/*
# Copy the binary from builder
COPY --from=builder /app/target/release/grpc-server /usr/local/bin/grpc-server
# Create data directory for SQLite volume mount
RUN mkdir -p /app/data
# Expose gRPC port
EXPOSE 50051
# Run the gRPC server
CMD ["grpc-server"]