Skip to content

Commit 04ef57e

Browse files
committed
build stuff
1 parent a8d8f43 commit 04ef57e

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Dockerfile
2+
.dockerignore
3+
node_modules
4+
npm-debug.log
5+
README.md
6+
.next
7+
.git
8+
.env.local
9+
.env.prod
10+
.env.dev
11+
.env
12+
.envrc
13+
.env.development
14+
.env.production
15+
.env.development

Dockerfile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
FROM node:22-alpine AS base
2+
3+
ENV YARN_VERSION=4.3.1
4+
RUN corepack enable && corepack prepare yarn@${YARN_VERSION}
5+
6+
# Install dependencies only when needed
7+
FROM base AS deps
8+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
9+
RUN apk add --no-cache libc6-compat
10+
WORKDIR /app
11+
12+
# Install dependencies based on the preferred package manager
13+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
14+
COPY .yarnrc.yml* ./
15+
COPY .yarn* ./.yarn
16+
17+
RUN \
18+
if [ -f yarn.lock ]; then yarn --immutable; \
19+
elif [ -f package-lock.json ]; then npm ci; \
20+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
21+
else echo "Lockfile not found." && exit 1; \
22+
fi
23+
24+
# Rebuild the source code only when needed
25+
FROM base AS builder
26+
WORKDIR /app
27+
COPY --from=deps /app/node_modules ./node_modules
28+
COPY . .
29+
30+
# Next.js collects completely anonymous telemetry data about general usage.
31+
# Learn more here: https://nextjs.org/telemetry
32+
# Uncomment the following line in case you want to disable telemetry during the build.
33+
# ENV NEXT_TELEMETRY_DISABLED 1
34+
35+
RUN \
36+
if [ -f yarn.lock ]; then yarn run build; \
37+
elif [ -f package-lock.json ]; then npm run build; \
38+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
39+
else echo "Lockfile not found." && exit 1; \
40+
fi
41+
42+
# Production image, copy all the files and run next
43+
FROM base AS runner
44+
WORKDIR /app
45+
46+
ENV NODE_ENV production
47+
# Uncomment the following line in case you want to disable telemetry during runtime.
48+
# ENV NEXT_TELEMETRY_DISABLED 1
49+
50+
RUN addgroup --system --gid 1001 nodejs
51+
RUN adduser --system --uid 1001 nextjs
52+
53+
COPY --from=builder /app/public ./public
54+
55+
# Set the correct permission for prerender cache
56+
RUN mkdir .next
57+
RUN chown nextjs:nodejs .next
58+
59+
# Automatically leverage output traces to reduce image size
60+
# https://nextjs.org/docs/advanced-features/output-file-tracing
61+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
62+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
63+
64+
USER nextjs
65+
66+
EXPOSE 3000
67+
68+
ENV PORT 3000
69+
70+
# server.js is created by next build from the standalone output
71+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
72+
CMD HOSTNAME="0.0.0.0" node server.js

next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
22
reactStrictMode: true,
3+
output: 'standalone'
34
}

0 commit comments

Comments
 (0)