Correct docker setup.
This commit is contained in:
parent
151a354518
commit
734ecf8293
1 changed files with 14 additions and 6 deletions
|
|
@ -2,25 +2,33 @@
|
||||||
|
|
||||||
# --- Stage 1: Builder ---
|
# --- Stage 1: Builder ---
|
||||||
# Use a stable Rust version
|
# Use a stable Rust version
|
||||||
FROM rust:1.82-slim AS builder
|
FROM rust:stable-bookworm AS builder
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# Install build dependencies needed for sqlx
|
# Install build dependencies needed for sqlx
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
libssl-dev \
|
libssl-dev \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy the ENTIRE project at once. This ensures Cargo sees a valid project.
|
# Copy manifest files first to leverage Docker layer caching for dependencies
|
||||||
COPY . .
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
|
||||||
# Build the project. Cargo will resolve dependencies and compile.
|
# Create a dummy src to allow cargo to download dependencies into the cache layer
|
||||||
|
RUN mkdir -p src && echo "fn main() { println!(\"cargo cache build\"); }" > src/main.rs
|
||||||
|
|
||||||
|
# Fetch and build dependencies (this will be cached until Cargo.toml changes)
|
||||||
|
RUN cargo build --release || true
|
||||||
|
|
||||||
|
# Now copy the real source and build the final binary
|
||||||
|
COPY src ./src
|
||||||
|
RUN rm -f src/main.rs || true
|
||||||
RUN cargo build --release
|
RUN cargo build --release
|
||||||
|
|
||||||
# --- Stage 2: Final, small image ---
|
# --- Stage 2: Final, small image ---
|
||||||
FROM debian:bookworm-slim
|
FROM debian:bookworm-slim
|
||||||
# Install only necessary runtime dependencies
|
# Install only necessary runtime dependencies
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
libssl3 \
|
libssl3 \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue