-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
85 lines (59 loc) · 2.05 KB
/
Dockerfile
File metadata and controls
85 lines (59 loc) · 2.05 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
ARG NODE=node:23-alpine3.22
FROM ${NODE} AS base
# Enable corepack and prepare pnpm
RUN npm install --ignore-scripts -g corepack@latest
RUN corepack enable
RUN corepack prepare pnpm@9.15.9 --activate
# Install necessary build tools and compilers
RUN apk update && apk add --no-cache cmake g++ gcc git jq make openssl-dev python3
# Increase Node.js memory limit as a regular build argument
ARG NODE_OPTIONS="--max_old_space_size=4096"
ENV NODE_OPTIONS=${NODE_OPTIONS}
# Set the working directory
WORKDIR /app
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
# Install the dependencies
RUN pnpm install --ignore-scripts
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the database package first
RUN pnpm build
#
## setup production runner
#
FROM ${NODE} AS runner
RUN npm install --ignore-scripts -g corepack@latest
RUN corepack enable
RUN apk add --no-cache curl \
&& apk add --no-cache supercronic \
# && addgroup --system --gid 1001 nodejs \
&& addgroup -S nextjs \
&& adduser -S -u 1001 -G nextjs nextjs
WORKDIR /home/nextjs
ENV NODE_ENV production
# Ensure no write permissions are assigned to the copied resources
COPY --from=builder /app/.next/standalone ./
RUN chown -R nextjs:nextjs ./ && chmod -R 755 ./
COPY --from=builder /app/next.config.mjs .
RUN chmod 644 ./next.config.mjs
COPY --from=builder /app/package.json .
RUN chmod 644 ./package.json
COPY --from=builder /app/.next/static ./.next/static
RUN chown -R nextjs:nextjs ./.next/static && chmod -R 755 ./.next/static
COPY --from=builder /app/content ./content
RUN chown -R nextjs:nextjs ./content && chmod -R 755 ./content
# We have no public yet
# COPY --from=builder /app/public ./public
# RUN chown -R nextjs:nextjs ./public && chmod -R 755 ./public
EXPOSE 3000
ENV HOSTNAME="0.0.0.0"
USER nextjs
ENV PORT 3000
CMD ["node", "server.js"]