Skip to content

Commit 1eb3388

Browse files
committed
infra: fix Dockerfile for web
1 parent fed9985 commit 1eb3388

File tree

1 file changed

+25
-66
lines changed

1 file changed

+25
-66
lines changed

web/Dockerfile

Lines changed: 25 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,41 @@
1-
# Stage 1: Dependencies
2-
FROM node:22-alpine AS deps
3-
WORKDIR /app
4-
5-
# Install pnpm and required OpenSSL dependencies
6-
RUN apk add --no-cache openssl openssl-dev
7-
RUN corepack enable && corepack prepare pnpm@latest --activate
1+
FROM node:18-alpine AS base
82

9-
# Copy package.json and pnpm-lock.yaml
3+
# Stage 1: Install web dependencies
4+
FROM base AS deps
5+
WORKDIR /app
6+
COPY .env ./.env
107
COPY package.json pnpm-lock.yaml ./
8+
RUN corepack enable pnpm && pnpm install --frozen-lockfile
119

12-
# Install dependencies
13-
RUN pnpm install --frozen-lockfile
14-
15-
# Stage 2: Builder
16-
FROM node:22-alpine AS builder
10+
# Stage 2: Build the web application
11+
FROM base AS builder
1712
WORKDIR /app
18-
19-
# Install pnpm and required OpenSSL dependencies
20-
RUN apk add --no-cache openssl openssl-dev
21-
RUN corepack enable && corepack prepare pnpm@latest --activate
22-
23-
# Copy dependencies from deps stage
2413
COPY --from=deps /app/node_modules ./node_modules
25-
26-
# Copy all files
14+
COPY --from=deps /app/.env ./.env
2715
COPY . .
16+
RUN corepack enable pnpm && \
17+
pnpm prisma generate && \
18+
pnpm run build
2819

29-
# Set environment variables for building
30-
ENV NEXT_TELEMETRY_DISABLED 1
31-
32-
# Generate prisma client - make sure it exists
33-
RUN pnpm prisma generate
34-
35-
# Build the application
36-
RUN pnpm build
37-
38-
# Stage 3: Production runner
39-
FROM node:22-alpine AS runner
20+
# Stage 3: Production runtime
21+
FROM base AS runner
4022
WORKDIR /app
23+
ENV NODE_ENV=production
24+
EXPOSE 3000
4125

42-
# Install pnpm and required OpenSSL dependencies
43-
RUN apk add --no-cache openssl openssl-dev
44-
RUN corepack enable && corepack prepare pnpm@latest --activate
45-
46-
# Set environment variables
47-
ENV NODE_ENV production
48-
ENV NEXT_TELEMETRY_DISABLED 1
49-
ENV CONTAINER_RUNTIME docker
50-
51-
# Add a non-root user to run the app
26+
# Create a non-root user
5227
RUN addgroup --system --gid 1001 nodejs && \
53-
adduser --system --uid 1001 nextjs && \
54-
chown -R nextjs:nodejs /app
28+
adduser --system --uid 1001 nextjs
5529

56-
# Copy necessary files for the standalone app
57-
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
30+
# Copy only the necessary files
5831
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
59-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
60-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
61-
62-
# Copy Prisma schema and generate client during runtime
63-
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
64-
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
65-
COPY --from=builder --chown=nextjs:nodejs /app/pnpm-lock.yaml ./
32+
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
6633

67-
# Install only production dependencies, including Prisma, and generate Prisma client
68-
RUN pnpm install --prod --frozen-lockfile && \
69-
pnpm prisma generate
34+
# Check if standalone build exists, otherwise use regular build output
35+
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
36+
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
37+
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./package.json
7038

71-
# Switch to non-root user
7239
USER nextjs
7340

74-
# Expose the port the app will run on
75-
ENV PORT 3000
76-
EXPOSE ${PORT}
77-
78-
# Health check to verify app is running
79-
# HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
80-
# CMD wget -q -O - http://localhost:${PORT}/api/health || exit 1
81-
82-
CMD ["node", "server.js"]
41+
CMD ["pnpm", "start"]

0 commit comments

Comments
 (0)