# Build stage FROM rust:latest AS builder WORKDIR /app # Install build dependencies RUN apt-get update && apt-get install -y \ pkg-config \ libssl-dev \ && rm -rf /var/lib/apt/lists/* # Copy manifests COPY Cargo.toml Cargo.lock* ./ # Create dummy main.rs to cache dependencies RUN mkdir src && echo "fn main() {}" > src/main.rs # Build dependencies (this will be cached) RUN cargo build --release && rm -rf src # Copy source code COPY src ./src COPY migrations ./migrations # Build the actual application RUN touch src/main.rs && cargo build --release # Runtime stage FROM debian:trixie-slim WORKDIR /app # Install runtime dependencies RUN apt-get update && apt-get install -y \ ca-certificates \ libssl3 \ curl \ && rm -rf /var/lib/apt/lists/* # Copy the binary COPY --from=builder /app/target/release/vrbattles-api /app/vrbattles-api # Copy migrations COPY --from=builder /app/migrations /app/migrations # Create non-root user RUN useradd -r -s /bin/false vrbattles && \ chown -R vrbattles:vrbattles /app USER vrbattles # Expose port EXPOSE 3000 # Health check HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD curl -f http://localhost:3000/health || exit 1 # Run the binary CMD ["./vrbattles-api"]