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
|
# Development Dockerfile
|
||||||
# Uses Rust 1.93+ to support Edition 2024 dependencies
|
# Uses Rust 1.93+ to support Edition 2024 dependencies
|
||||||
FROM rust:1.93-slim
|
FROM rust:1.93-slim as builder
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ RUN apt-get update && apt-get install -y \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Copy Cargo files first for better caching
|
# Copy Cargo files first for better caching
|
||||||
COPY Cargo.toml ./
|
COPY Cargo.toml Cargo.lock ./
|
||||||
|
|
||||||
# Create dummy main.rs for dependency caching
|
# Create dummy main.rs for dependency caching
|
||||||
RUN mkdir src && echo 'fn main() {}' > src/main.rs
|
RUN mkdir src && echo 'fn main() {}' > src/main.rs
|
||||||
|
|
@ -22,10 +22,25 @@ RUN cargo build && rm -rf src
|
||||||
# Copy actual source code
|
# Copy actual source code
|
||||||
COPY src ./src
|
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 port
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# Run the application with unbuffered output
|
# Run the binary directly
|
||||||
# PYTHONUNBUFFERED=1 and stdio -u flag for Python compatibility
|
CMD ["/app/normogen-backend"]
|
||||||
# RUST_BACKTRACE=1 for better error messages
|
|
||||||
CMD ["sh", "-c", "RUST_BACKTRACE=1 cargo run"]
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue