fix: Use multi-stage Dockerfile to run binary directly instead of cargo run
Some checks failed
Lint and Build / Lint (push) Failing after 5s
Lint and Build / Build (push) Has been skipped
Lint and Build / Docker Build (push) Has been skipped

This commit is contained in:
goose 2026-02-22 00:08:22 -03:00
parent 66b0f03878
commit d02c348d92

View file

@ -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"]