-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
39 lines (29 loc) · 1.46 KB
/
Copy pathDockerfile
File metadata and controls
39 lines (29 loc) · 1.46 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
# ─── Stage 1: Build ──────────────────────────────────────────────
# Use the official Rust image to compile the application
FROM rust:1.85-slim-bookworm AS builder
# Install required system libraries for linking
RUN apt-get update && apt-get install -y pkg-config libssl-dev && rm -rf /var/lib/apt/lists/*
# Create a new empty project and build dependencies first (for Docker caching)
WORKDIR /app
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release 2>/dev/null || true
# Copy the actual source code and build the real binary
COPY src/ src/
RUN cargo build --release
# ─── Stage 2: Runtime ────────────────────────────────────────────
# Use a slim runtime image (no compiler needed)
FROM debian:bookworm-slim
# Install runtime dependencies (PostgreSQL client libraries, ca-certificates)
RUN apt-get update && apt-get install -y libssl3 ca-certificates && rm -rf /var/lib/apt/lists/*
# Create a non-root user for security
RUN useradd --create-home --shell /bin/bash appuser
# Copy the compiled binary from the builder stage
COPY --from=builder /app/target/release/rust-notes-api /app/rust-notes-api
# Use the non-root user
USER appuser
WORKDIR /app
# Expose the application port
EXPOSE 3000
# Run the binary
CMD ["./rust-notes-api"]