2025-09-16 16:10:10+04:00

This commit is contained in:
2025-09-16 16:10:10 +04:00
committed by nett00n
parent 9d8ef03fea
commit 7ff599aae0

View File

@@ -1,28 +1,53 @@
# cat Dockerfile # Stage 1: Dependencies
# Stage 1: Builder FROM node:20-alpine AS deps
FROM node:20-alpine AS builder
WORKDIR /app WORKDIR /app
# Install pnpm
RUN npm install -g pnpm@9.0.0 RUN npm install -g pnpm@9.0.0
# Copy files # Copy dependency files first for better caching
COPY pnpm-lock.yaml ./ COPY package.json pnpm-lock.yaml turbo.json ./
COPY package.json ./ COPY apps/web/package.json ./apps/web/
COPY turbo.json ./ # Add other app package.json files as needed
RUN pnpm install --frozen-lockfile
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
RUN npm install -g pnpm@9.0.0
# Copy dependencies from previous stage
COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/package.json /app/pnpm-lock.yaml /app/turbo.json ./
# Copy source code
COPY . . COPY . .
# Install deps and build # Build the application
RUN pnpm install --frozen-lockfile
RUN pnpm build RUN pnpm build
# Stage 2: Runtime # Stage 3: Runtime
FROM node:20-alpine FROM node:20-alpine AS runtime
WORKDIR /app WORKDIR /app
COPY --from=builder /app ./ # Install pnpm for production
RUN npm install -g pnpm@9.0.0
# Copy package files
COPY package.json pnpm-lock.yaml turbo.json ./
COPY apps/web/package.json ./apps/web/
# Install only production dependencies
RUN pnpm install --prod --frozen-lockfile
# Copy built application from builder
COPY --from=builder /app/apps/web/dist ./apps/web/dist
COPY --from=builder /app/apps/web/server.js ./apps/web/
# Copy other necessary runtime files
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001
USER nextjs
EXPOSE 3000
CMD ["node", "apps/web/server.js"] CMD ["node", "apps/web/server.js"]