From d02c348d92e0f9a2c16bde7cf2affe37b2ff9dfa Mon Sep 17 00:00:00 2001 From: goose Date: Sun, 22 Feb 2026 00:08:22 -0300 Subject: [PATCH] fix: Use multi-stage Dockerfile to run binary directly instead of cargo run --- backend/docker/Dockerfile.dev | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/backend/docker/Dockerfile.dev b/backend/docker/Dockerfile.dev index c13fbc4..f244a40 100644 --- a/backend/docker/Dockerfile.dev +++ b/backend/docker/Dockerfile.dev @@ -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"]