-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
77 lines (54 loc) · 2.36 KB
/
Copy pathDockerfile
File metadata and controls
77 lines (54 loc) · 2.36 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
FROM node:20-alpine AS base
# Step 1. Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
ARG ENV_FILE=.env.prod
RUN apk add --update python3 make g++ \
&& rm -rf /var/cache/apk/*
# Install pnpm globally
RUN corepack enable && corepack prepare pnpm@latest --activate
COPY . ./
RUN mv $ENV_FILE tempenv && rm .env.* && mv tempenv .env
# Omit --production flag for TypeScript devDependencies
# RUN pnpm install;
# Environment variables must be present at build time
# https://github.com/vercel/next.js/discussions/14030
# ARG NEXT_PUBLIC_APP_URL
# ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
# ARG NEXT_PUBLIC_API_URL
# ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry
# Uncomment the following line to disable telemetry at build time
# ENV NEXT_TELEMETRY_DISABLED 1
# Build Next.js based on the preferred package manager
RUN pnpm install --frozen-lockfile
RUN pnpm build
################################################################################################################################
# Note: It is not necessary to add an intermediate step that does a full copy of `node_modules` here
# Step 2. Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/.env ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/pnpm-lock.yaml ./pnpm-lock.yaml
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Environment variables must be redefined at run time
# ARG NEXT_PUBLIC_APP_URL
# ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
# ARG NEXT_PUBLIC_API_URL
# ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
# Uncomment the following line to disable telemetry at run time
# ENV NEXT_TELEMETRY_DISABLED 1
# Expose the listening port
EXPOSE 3000
ENV PORT 3000
CMD ["node", "server.js"]