-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (44 loc) · 1.87 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (44 loc) · 1.87 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
FROM node:20-alpine AS builder
WORKDIR /app
# :hammer_and_spanner: Install build tools and Python for native modules
RUN apk add --no-cache python3 make g++ jq
# :jigsaw: Symlink python3 → python (required by node-gyp)
RUN ln -sf /usr/bin/python3 /usr/bin/python
# :brain: Let node-gyp know where Python is
ENV PYTHON=/usr/bin/python
# :package: Copy package files
COPY package.json package-lock.json* ./
# :broom: Remove @inco-fhevm/js from dependencies (temporary build hack)
RUN cp package.json package.json.backup && \
cat package.json | jq 'del(.dependencies."@inco-fhevm/js")' > package.json.tmp && \
mv package.json.tmp package.json
# :rocket: Install dependencies (including dev dependencies for flexibility)
RUN npm install --no-audit
# :file_folder: Copy the full project source
COPY . .
# :plaster: Fix styled-jsx issue (explicitly add compatible version)
RUN npm install styled-jsx@5.1.6
# :package: Build the Next.js app (for all environments)
# NODE_ENV will be set at runtime for the runner stage
RUN npm run build
FROM node:20-alpine AS runner
WORKDIR /app
# :seedling: Default to production, but can be overridden at runtime
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# :silhouette: Create a non-root user for security
RUN addgroup -S nextjs && adduser -S nextjs -G nextjs
# :open_file_folder: Copy only necessary files from builder stage
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
# Add environment configuration files for all environments
COPY --from=builder /app/.env* ./
# :silhouette: Switch to non-root user
USER nextjs
# :satellite_antenna: Expose port 3000
EXPOSE 3000
# :checkered_flag: Start the app with environment-specific settings
CMD ["node", "server.js"]