fix: Use multi-stage Dockerfile to run binary directly instead of cargo run
This commit is contained in:
parent
66b0f03878
commit
d02c348d92
1 changed files with 21 additions and 6 deletions
|
|
@ -1,6 +1,6 @@
|
|||
# Development Dockerfile
|
||||
# Uses Rust 1.93+ to support Edition 2024 dependencies
|
||||
FROM rust:1.93-slim
|
||||
FROM rust:1.93-slim as builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y \
|
|||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy Cargo files first for better caching
|
||||
COPY Cargo.toml ./
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
|
||||
# Create dummy main.rs for dependency caching
|
||||
RUN mkdir src && echo 'fn main() {}' > src/main.rs
|
||||
|
|
@ -22,10 +22,25 @@ RUN cargo build && rm -rf src
|
|||
# Copy actual source code
|
||||
COPY src ./src
|
||||
|
||||
# Build the application
|
||||
RUN cargo build
|
||||
|
||||
# Runtime stage
|
||||
FROM rust:1.93-slim
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install runtime dependencies
|
||||
RUN apt-get update && apt-get install -y \
|
||||
pkg-config \
|
||||
libssl-dev \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Copy the binary from builder
|
||||
COPY --from=builder /app/target/debug/normogen-backend /app/normogen-backend
|
||||
|
||||
# Expose port
|
||||
EXPOSE 8000
|
||||
|
||||
# Run the application with unbuffered output
|
||||
# PYTHONUNBUFFERED=1 and stdio -u flag for Python compatibility
|
||||
# RUST_BACKTRACE=1 for better error messages
|
||||
CMD ["sh", "-c", "RUST_BACKTRACE=1 cargo run"]
|
||||
# Run the binary directly
|
||||
CMD ["/app/normogen-backend"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue