# Multi-stage build for VAPORA MCP Server
# Build stage
FROM rust:1.75-alpine AS builder

WORKDIR /usr/src/app

# Install build dependencies
RUN apk add --no-cache \
    musl-dev \
    pkgconfig \
    openssl-dev \
    openssl-libs-static

# Copy workspace files
COPY Cargo.toml Cargo.lock ./
COPY crates ./crates

# Build MCP server
RUN cargo build --release -p vapora-mcp-server

# Runtime stage
FROM alpine:latest

RUN apk add --no-cache \
    ca-certificates \
    openssl \
    curl

WORKDIR /app

# Copy binary from builder
COPY --from=builder /usr/src/app/target/release/vapora-mcp-server /app/vapora-mcp-server

# Create non-root user
RUN addgroup -g 1000 vapora && \
    adduser -D -u 1000 -G vapora vapora && \
    chown -R vapora:vapora /app

USER vapora

# Expose port
EXPOSE 3000

# Health check
HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:3000/health || exit 1

# Run
ENTRYPOINT ["/app/vapora-mcp-server"]
CMD ["--port", "3000"]
