-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
132 lines (100 loc) · 4.28 KB
/
Dockerfile
File metadata and controls
132 lines (100 loc) · 4.28 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# syntax=docker/dockerfile:1
# ================================
# Stage 1: Dependencies
# ================================
FROM node:24-alpine AS deps
# Install dependencies required for native modules
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Enable corepack for pnpm
RUN corepack enable && corepack prepare pnpm@10.25.0 --activate
# Copy package files for dependency installation
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
COPY apps/web/package.json ./apps/web/
COPY packages/database/package.json ./packages/database/
COPY packages/auth/package.json ./packages/auth/
COPY packages/ui/package.json ./packages/ui/
COPY packages/ai-hub/package.json ./packages/ai-hub/
COPY packages/i18n/package.json ./packages/i18n/
COPY packages/env/package.json ./packages/env/
COPY packages/config/biome-config/package.json ./packages/config/biome-config/
COPY packages/config/tailwind-config/package.json ./packages/config/tailwind-config/
COPY packages/config/typescript-config/package.json ./packages/config/typescript-config/
COPY packages/model-depot/package.json ./packages/model-depot/
# Configure npm registry (optional)
# CN users can use: --build-arg NPM_REGISTRY=https://registry.npmmirror.com
ARG NPM_REGISTRY=https://registry.npmjs.org
RUN pnpm config set registry ${NPM_REGISTRY}
# Install all dependencies with retry
RUN pnpm install --frozen-lockfile
# ================================
# Stage 2: Builder
# ================================
FROM node:24-alpine AS builder
WORKDIR /app
RUN corepack enable && corepack prepare pnpm@10.25.0 --activate
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules
COPY --from=deps /app/packages ./packages
# Copy source code
COPY . .
# Set build environment variables
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# Build arguments for environment variables needed at build time
ARG DEPLOYMENT_MODE=selfhost
ARG NEXT_PUBLIC_DEPLOYMENT_MODE=selfhost
ARG NEXT_PUBLIC_APP_URL=http://localhost:3000
ENV DEPLOYMENT_MODE=$DEPLOYMENT_MODE
ENV NEXT_PUBLIC_DEPLOYMENT_MODE=$NEXT_PUBLIC_DEPLOYMENT_MODE
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
# Build the application
RUN pnpm --filter @lmring/web build
# ================================
# Stage 3: Runner
# ================================
FROM node:24-alpine AS runner
WORKDIR /app
# Install runtime dependencies
RUN apk add --no-cache libc6-compat
# Set production environment
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy public assets
COPY --from=builder /app/apps/web/public ./public
# Set correct permissions for prerender cache
RUN mkdir -p .next
RUN chown nextjs:nodejs .next
# Copy standalone output
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/apps/web/.next/static ./apps/web/.next/static
# Copy database migrations for Drizzle
COPY --from=builder --chown=nextjs:nodejs /app/packages/database/migrations ./packages/database/migrations
COPY --from=builder --chown=nextjs:nodejs /app/packages/database/drizzle.config.ts ./packages/database/
# Copy pnpm for running migrations
RUN corepack enable && corepack prepare pnpm@10.25.0 --activate
COPY --from=builder /app/package.json ./
COPY --from=builder /app/pnpm-lock.yaml ./
COPY --from=builder /app/pnpm-workspace.yaml ./
COPY --from=builder /app/packages/database/package.json ./packages/database/
# Configure npm registry (optional)
# CN users can use: --build-arg NPM_REGISTRY=https://registry.npmmirror.com
ARG NPM_REGISTRY=https://registry.npmjs.org
RUN pnpm config set registry ${NPM_REGISTRY}
# Install only database dependencies for migrations
RUN pnpm install --filter @lmring/database --prod --frozen-lockfile
# Switch to non-root user
USER nextjs
# Expose port
EXPOSE 3000
# Health check (using Node.js wget is not available in Alpine)
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1)).on('error', () => process.exit(1))"
# Start the server
CMD ["node", "apps/web/server.js"]