Copied from api_gateway, removed REST handlers (port 8080), added tonic-web + CORS for grpc-web browser access. Binary renamed: api-gateway → api Changes: - Package name: api-gateway → api - Deleted src/handlers/ (REST ML endpoints on port 8080) - Added tonic-web 0.13 + tower-http CORS layer - Server::builder().accept_http1(true) for grpc-web - CORS_ORIGINS env var (default http://localhost:5173) - Metrics server on port 9091 (axum) preserved - All 95 lib tests pass, 0 clippy warnings - Added services/api to workspace members Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
83 lines
2.2 KiB
Docker
83 lines
2.2 KiB
Docker
# Multi-stage build for Foxhunt API Service
|
|
# Production-optimized Docker image
|
|
|
|
# =============================================================================
|
|
# Builder Stage
|
|
# =============================================================================
|
|
FROM rust:1.89-slim-bookworm AS builder
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
pkg-config \
|
|
libssl-dev \
|
|
protobuf-compiler \
|
|
perl \
|
|
make \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Set working directory
|
|
WORKDIR /build
|
|
|
|
# Copy workspace manifests
|
|
COPY Cargo.toml Cargo.lock ./
|
|
|
|
# Copy sqlx offline cache for compile-time query verification
|
|
COPY .sqlx ./.sqlx
|
|
|
|
# Copy workspace members to satisfy manifest dependencies
|
|
COPY crates ./crates
|
|
COPY bin/fxt ./bin/fxt
|
|
COPY services ./services
|
|
COPY testing ./testing
|
|
|
|
# Enable sqlx offline mode to use cached query metadata
|
|
ENV SQLX_OFFLINE=true
|
|
|
|
# Build the application
|
|
RUN cargo build --release -p api
|
|
|
|
# =============================================================================
|
|
# Runtime Stage
|
|
# =============================================================================
|
|
FROM debian:bookworm-slim
|
|
|
|
# Install runtime dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
ca-certificates \
|
|
libssl3 \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Download and install grpc_health_probe for health checks
|
|
RUN curl -sSL https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v0.4.25/grpc_health_probe-linux-amd64 \
|
|
-o /usr/local/bin/grpc_health_probe && \
|
|
chmod +x /usr/local/bin/grpc_health_probe
|
|
|
|
# Create non-root user
|
|
RUN groupadd --system --gid 1000 foxhunt && \
|
|
useradd --system --uid 1000 --gid foxhunt --shell /bin/bash foxhunt
|
|
|
|
# Create application directories
|
|
RUN mkdir -p /app/config /app/logs && \
|
|
chown -R foxhunt:foxhunt /app
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /build/target/release/api ./api
|
|
RUN chmod +x ./api
|
|
|
|
# Switch to non-root user
|
|
USER foxhunt
|
|
|
|
# Expose gRPC and metrics ports
|
|
EXPOSE 50051 9091
|
|
|
|
# Health check using grpc_health_probe
|
|
HEALTHCHECK --interval=10s --timeout=5s --start-period=30s --retries=3 \
|
|
CMD /usr/local/bin/grpc_health_probe -addr=localhost:50051 || exit 1
|
|
|
|
# Run the application
|
|
ENTRYPOINT ["./api"]
|