File size: 2,733 Bytes
f69e867
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# CourtMitra API + Worker β€” NestJS + Fastify + Inngest on Hugging Face Spaces
# HF expects a web service on PORT (default 7860).
# This container runs BOTH the API and the Inngest worker in one process.

# ── Stage 1: builder ────────────────────────────────────────────────────────
FROM node:23-alpine AS builder
RUN corepack enable && corepack prepare pnpm@10 --activate
WORKDIR /app

# Workspace manifests
COPY pnpm-lock.yaml pnpm-workspace.yaml package.json tsconfig.base.json ./
COPY apps/api/package.json apps/api/
COPY apps/worker/package.json apps/worker/
COPY packages/adapters/package.json packages/adapters/
COPY packages/contracts/package.json packages/contracts/
COPY packages/db/package.json packages/db/
COPY packages/domain/package.json packages/domain/
COPY packages/ports/package.json packages/ports/
COPY packages/prompts/package.json packages/prompts/

RUN pnpm install --frozen-lockfile

# Source β€” API + Worker + all packages
COPY apps/api/src apps/api/src
COPY apps/worker/src apps/worker/src
COPY packages/adapters/src packages/adapters/src
COPY packages/contracts/src packages/contracts/src
COPY packages/db/src packages/db/src
COPY packages/domain/src packages/domain/src
COPY packages/ports/src packages/ports/src
COPY packages/prompts/src packages/prompts/src
COPY packages/db/drizzle.config.ts packages/db/drizzle.config.ts
COPY apps/api/tsconfig.json apps/api/tsconfig.json
COPY apps/worker/tsconfig.json apps/worker/tsconfig.json

# Deploy flat production node_modules for the API
RUN pnpm --filter @courtmitra/api deploy --prod --legacy /deploy

# Remove leaked frontend-only packages to save space
RUN rm -rf /deploy/node_modules/.pnpm/next@* \
           /deploy/node_modules/.pnpm/@next+* \
           /deploy/node_modules/.pnpm/typescript@* \
           /deploy/node_modules/.pnpm/caniuse-lite@* \
           /deploy/node_modules/.pnpm/react@* \
           /deploy/node_modules/.pnpm/react-dom@* \
           /deploy/node_modules/.pnpm/web-streams-polyfill@*

# ── Stage 2: runner ─────────────────────────────────────────────────────────
FROM node:23-alpine AS runner
RUN apk add --no-cache tini curl
WORKDIR /app

COPY --from=builder /deploy ./

# HF provides PORT env var (default 7860)
EXPOSE 7860
ENV API_PORT=7860
ENV PORT=7860

# Healthcheck for HF
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD curl -f http://localhost:7860/api/admin/health || exit 1

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["npx", "tsx", "src/main.ts"]