Skip to content

Commit 648366c

Browse files
authored
feat: add dockerfile and config for standalone builds (#384)
1 parent e3ff7c3 commit 648366c

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

Dockerfile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
ARG NODE_VERSION=lts
2+
3+
FROM node:${NODE_VERSION} AS dependencies
4+
5+
WORKDIR /app
6+
7+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
8+
9+
RUN --mount=type=cache,target=/root/.npm \
10+
--mount=type=cache,target=/usr/local/share/.cache/yarn \
11+
--mount=type=cache,target=/root/.local/share/pnpm/store \
12+
if [ -f package-lock.json ]; then \
13+
npm ci --no-audit --no-fund; \
14+
elif [ -f yarn.lock ]; then \
15+
corepack enable yarn && yarn install --frozen-lockfile --production=false; \
16+
elif [ -f pnpm-lock.yaml ]; then \
17+
corepack enable pnpm && pnpm install --frozen-lockfile; \
18+
else \
19+
echo "No lockfile found." && exit 1; \
20+
fi
21+
22+
FROM node:${NODE_VERSION} AS builder
23+
24+
WORKDIR /app
25+
26+
COPY --from=dependencies /app/node_modules ./node_modules
27+
COPY . .
28+
29+
ENV NODE_ENV=production
30+
ENV NEXT_TELEMETRY_DISABLED=1
31+
32+
RUN if [ -f package-lock.json ]; then \
33+
npm run build; \
34+
elif [ -f yarn.lock ]; then \
35+
corepack enable yarn && yarn build; \
36+
elif [ -f pnpm-lock.yaml ]; then \
37+
corepack enable pnpm && pnpm build; \
38+
else \
39+
echo "No lockfile found." && exit 1; \
40+
fi
41+
42+
FROM node:${NODE_VERSION} AS runner
43+
44+
WORKDIR /app
45+
46+
ENV NODE_ENV=production
47+
ENV PORT=3000
48+
ENV HOSTNAME="0.0.0.0"
49+
ENV NEXT_TELEMETRY_DISABLED=1
50+
51+
COPY --from=builder --chown=node:node /app/public ./public
52+
53+
RUN mkdir .next && chown node:node .next
54+
55+
# Standalone output: copies server.js and all required node_modules
56+
COPY --from=builder --chown=node:node /app/.next/standalone ./
57+
# Static assets still need to be copied separately
58+
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
59+
60+
# Seed the fetch cache from build time
61+
COPY --from=builder --chown=node:node /app/.next/cache ./.next/cache
62+
63+
USER node
64+
65+
EXPOSE 3000
66+
67+
CMD ["node", "server.js"]

next.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const nextConfig: NextConfig = {
4949
},
5050
viewTransition: true,
5151
},
52+
output: "standalone",
5253
};
5354

5455
const withNextIntl = createNextIntlPlugin();

0 commit comments

Comments
 (0)