# Multi-stage build for Fortress Server
FROM rust:1.75-slim as builder
# Install build dependencies
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy Cargo files
COPY Cargo.toml Cargo.lock ./
COPY crates/ ./crates/
# Build the server binary
RUN cargo build --release -p fortress-server
# Runtime stage
FROM debian:bookworm-slim
# Install runtime dependencies
RUN apt-get update && apt-get install -y \
ca-certificates \
libssl3 \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN useradd -r -s /bin/false fortress
# Create app directory
WORKDIR /app
# Copy the binary from builder stage
COPY --from=builder /app/target/release/fortress-server /usr/local/bin/fortress-server
# Create data directory
RUN mkdir -p /data && chown fortress:fortress /data
# Switch to non-root user
USER fortress
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8080/health || exit 1
# Set environment variables
ENV RUST_LOG=info
ENV FORTRESS_DATA_DIR=/data
# Run the server
CMD ["fortress-server"]