2026-07-24 13:08:09 +07:00
|
|
|
# ============================================================
|
|
|
|
|
# Stage 1: Build Rust Backend
|
|
|
|
|
# ============================================================
|
|
|
|
|
FROM rust:1.85-slim-bookworm AS chef
|
|
|
|
|
RUN cargo install cargo-chef
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
FROM chef AS planner
|
2026-07-24 13:11:54 +07:00
|
|
|
COPY apps/tools/backend/ .
|
2026-07-24 13:08:09 +07:00
|
|
|
RUN cargo chef prepare --recipe-path recipe.json
|
|
|
|
|
|
|
|
|
|
FROM chef AS builder
|
|
|
|
|
COPY --from=planner /app/recipe.json recipe.json
|
|
|
|
|
RUN cargo chef cook --release --recipe-path recipe.json
|
|
|
|
|
|
2026-07-24 13:11:54 +07:00
|
|
|
COPY apps/tools/backend/ .
|
2026-07-24 13:08:09 +07:00
|
|
|
RUN cargo build --release --bin tools-gateway --bin tools-workers
|
|
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
# Stage 2: Build Next.js Frontend
|
|
|
|
|
# ============================================================
|
|
|
|
|
FROM oven/bun:1.3 AS frontend-builder
|
|
|
|
|
WORKDIR /app
|
2026-07-24 13:11:54 +07:00
|
|
|
|
2026-07-24 13:20:30 +07:00
|
|
|
# Copy package files
|
|
|
|
|
COPY apps/tools/frontend/package.json ./
|
|
|
|
|
RUN bun install
|
2026-07-24 13:11:54 +07:00
|
|
|
|
|
|
|
|
COPY apps/tools/frontend/ .
|
2026-07-24 13:08:09 +07:00
|
|
|
RUN bun run build
|
|
|
|
|
|
|
|
|
|
# ============================================================
|
|
|
|
|
# Stage 3: Production Runtime
|
|
|
|
|
# ============================================================
|
|
|
|
|
FROM debian:bookworm-slim AS runtime
|
|
|
|
|
|
|
|
|
|
# Install runtime dependencies
|
|
|
|
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
|
|
|
tesseract-ocr \
|
|
|
|
|
tesseract-ocr-eng \
|
|
|
|
|
tesseract-ocr-ind \
|
|
|
|
|
ca-certificates \
|
|
|
|
|
fonts-dejavu-core \
|
|
|
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
# Copy Rust binaries
|
|
|
|
|
COPY --from=builder /app/target/release/tools-gateway /app/gateway
|
|
|
|
|
COPY --from=builder /app/target/release/tools-workers /app/workers
|
|
|
|
|
|
|
|
|
|
# Copy Next.js build
|
|
|
|
|
COPY --from=frontend-builder /app/.next /app/.next
|
|
|
|
|
COPY --from=frontend-builder /app/public /app/public
|
|
|
|
|
COPY --from=frontend-builder /app/package.json /app/package.json
|
|
|
|
|
COPY --from=frontend-builder /app/node_modules /app/node_modules
|
|
|
|
|
COPY --from=frontend-builder /app/next.config.ts /app/next.config.ts
|
|
|
|
|
|
|
|
|
|
# Create temp storage directory
|
|
|
|
|
RUN mkdir -p /data/tools && chmod 1777 /data/tools
|
|
|
|
|
|
2026-07-24 13:11:54 +07:00
|
|
|
# Copy entrypoint
|
|
|
|
|
COPY apps/tools/scripts/entrypoint.sh /app/entrypoint.sh
|
|
|
|
|
RUN chmod +x /app/entrypoint.sh
|
|
|
|
|
|
2026-07-24 13:08:09 +07:00
|
|
|
# Environment
|
|
|
|
|
ENV TESSDATA_PREFIX=/usr/share/tesseract-ocr/5/tessdata
|
|
|
|
|
ENV STORAGE_PATH=/data/tools
|
|
|
|
|
ENV GATEWAY_PORT=3001
|
|
|
|
|
ENV TOOLS_WORKER_CONCURRENCY=4
|
|
|
|
|
ENV RUST_LOG=info
|
|
|
|
|
|
|
|
|
|
# Expose port
|
|
|
|
|
EXPOSE 3001
|
|
|
|
|
|
|
|
|
|
CMD ["/app/entrypoint.sh"]
|