62 lines
No EOL
1.3 KiB
Docker
62 lines
No EOL
1.3 KiB
Docker
# Multi-stage build for Rust backend
|
|
FROM rust:1.75-slim as builder
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
pkg-config \
|
|
libssl-dev \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy Cargo files
|
|
COPY Cargo.toml Cargo.lock ./
|
|
COPY crates/ ./crates/
|
|
|
|
# Build dependencies first (for better caching)
|
|
RUN cargo build --release --bin sharenet-api-postgres
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application
|
|
RUN cargo build --release --bin sharenet-api-postgres
|
|
|
|
# Runtime stage
|
|
FROM debian:bookworm-slim
|
|
|
|
# Install runtime dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
ca-certificates \
|
|
libssl3 \
|
|
wget \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create non-root user
|
|
RUN useradd -r -s /bin/false sharenet
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /app/target/release/sharenet-api-postgres /app/sharenet-api
|
|
|
|
# Copy configuration files
|
|
COPY --from=builder /app/config/ ./config/
|
|
|
|
# Change ownership
|
|
RUN chown -R sharenet:sharenet /app
|
|
|
|
# Switch to non-root user
|
|
USER sharenet
|
|
|
|
# Expose port
|
|
EXPOSE 3001
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1
|
|
|
|
# Run the application
|
|
CMD ["./sharenet-api"] |