# Stage 1: Builder
FROM rust:1.92-slim AS builder
WORKDIR /app
# Install build dependencies (Required for Protobuf and SSL)
RUN apt-get update && apt-get install -y protobuf-compiler libssl-dev pkg-config
# Copy manifests and build requirements
COPY ./Cargo.toml ./Cargo.lock* ./
COPY ./build.rs ./build.rs
COPY ./proto ./proto
# Build dependencies with empty main()
RUN mkdir src && echo "fn main() {}" > src/main.rs
RUN cargo build --release
# Copy in source and migrations
COPY ./src src
COPY ./migrations migrations
# Touch file to set modified time, then build
RUN touch src/main.rs
RUN cargo build --release
# Stage 2: Runtime
FROM debian:13.2-slim
WORKDIR /app
# Install runtime dependencies
RUN apt-get update && apt-get install -y ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
# Copy binary to release image
COPY --from=builder /app/target/release/obscura-server .
# Run the application
CMD ["./obscura-server"]