|
1 | 1 | # To use this Dockerfile, you have to set `output: 'standalone'` in your next.config.mjs file. |
2 | | -# From https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile |
| 2 | +# Based on https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile |
| 3 | + |
| 4 | +ARG PNPM_VERSION=10.16.1 |
3 | 5 |
|
4 | 6 | FROM node:22.12.0-alpine AS base |
| 7 | +ARG PNPM_VERSION |
| 8 | +RUN npm install -g pnpm@${PNPM_VERSION} |
5 | 9 |
|
6 | 10 | # Install dependencies only when needed |
7 | 11 | FROM base AS deps |
8 | | -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. |
9 | 12 | RUN apk add --no-cache libc6-compat |
10 | 13 | WORKDIR /app |
11 | 14 |
|
12 | | -# Install dependencies based on the preferred package manager |
13 | | -COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./ |
14 | | -RUN \ |
15 | | - if [ -f yarn.lock ]; then yarn --frozen-lockfile; \ |
16 | | - elif [ -f package-lock.json ]; then npm ci; \ |
17 | | - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \ |
18 | | - else echo "Lockfile not found." && exit 1; \ |
19 | | - fi |
20 | | - |
| 15 | +COPY package.json pnpm-lock.yaml ./ |
| 16 | +RUN pnpm install --frozen-lockfile |
21 | 17 |
|
22 | 18 | # Rebuild the source code only when needed |
23 | 19 | FROM base AS builder |
24 | 20 | WORKDIR /app |
| 21 | + |
25 | 22 | COPY --from=deps /app/node_modules ./node_modules |
26 | 23 | COPY . . |
27 | 24 |
|
28 | | -# Next.js collects completely anonymous telemetry data about general usage. |
29 | | -# Learn more here: https://nextjs.org/telemetry |
30 | | -# Uncomment the following line in case you want to disable telemetry during the build. |
31 | | -# ENV NEXT_TELEMETRY_DISABLED 1 |
| 25 | +ENV NODE_ENV=production \ |
| 26 | + NEXT_TELEMETRY_DISABLED=1 \ |
| 27 | + NEXT_PUBLIC_APP_URL=http://localhost:3000 |
32 | 28 |
|
33 | | -RUN \ |
34 | | - if [ -f yarn.lock ]; then yarn run build; \ |
35 | | - elif [ -f package-lock.json ]; then npm run build; \ |
36 | | - elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \ |
37 | | - else echo "Lockfile not found." && exit 1; \ |
38 | | - fi |
| 29 | +RUN --mount=type=secret,id=database_uri,env=DATABASE_URI \ |
| 30 | + --mount=type=secret,id=payload_secret,env=PAYLOAD_SECRET \ |
| 31 | + --mount=type=secret,id=sentry_auth_token,env=SENTRY_AUTH_TOKEN \ |
| 32 | + --mount=type=secret,id=sentry_org,env=SENTRY_ORG \ |
| 33 | + --mount=type=secret,id=sentry_project,env=SENTRY_PROJECT \ |
| 34 | + NODE_OPTIONS="--no-deprecation" pnpm exec next build |
39 | 35 |
|
40 | 36 | # Production image, copy all the files and run next |
41 | 37 | FROM base AS runner |
| 38 | +ARG TIKA_VERSION=3.2.3 |
42 | 39 | WORKDIR /app |
43 | 40 |
|
44 | | -ENV NODE_ENV production |
45 | | -# Uncomment the following line in case you want to disable telemetry during runtime. |
46 | | -# ENV NEXT_TELEMETRY_DISABLED 1 |
| 41 | +ENV NODE_ENV=production \ |
| 42 | + TIKA_VERSION=${TIKA_VERSION} \ |
| 43 | + TIKA_PORT=9998 \ |
| 44 | + TIKA_HOST=0.0.0.0 \ |
| 45 | + TIKA_SERVER_JAR=/opt/tika/tika-server.jar \ |
| 46 | + TIKA_ENABLED=1 \ |
| 47 | + AX_APACHE_TIKA_URL=http://127.0.0.1:9998/ \ |
| 48 | + HOSTNAME=0.0.0.0 \ |
| 49 | + PORT=3000 |
| 50 | + |
| 51 | +RUN apk add --no-cache openjdk17-jre-headless curl |
47 | 52 |
|
48 | 53 | RUN addgroup --system --gid 1001 nodejs |
49 | 54 | RUN adduser --system --uid 1001 nextjs |
50 | 55 |
|
51 | | -# Remove this line if you do not have this folder |
| 56 | +RUN mkdir -p /opt/tika \ |
| 57 | + && curl -fsSL "https://archive.apache.org/dist/tika/${TIKA_VERSION}/tika-server-standard-${TIKA_VERSION}.jar" -o "${TIKA_SERVER_JAR}" \ |
| 58 | + && chmod 644 "${TIKA_SERVER_JAR}" |
| 59 | + |
52 | 60 | COPY --from=builder /app/public ./public |
53 | 61 |
|
54 | | -# Set the correct permission for prerender cache |
55 | 62 | RUN mkdir .next |
56 | 63 | RUN chown nextjs:nodejs .next |
57 | 64 |
|
58 | | -# Automatically leverage output traces to reduce image size |
59 | | -# https://nextjs.org/docs/advanced-features/output-file-tracing |
60 | 65 | COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ |
61 | 66 | COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static |
62 | 67 |
|
| 68 | +COPY docker/entrypoint.sh /entrypoint.sh |
| 69 | +RUN chmod +x /entrypoint.sh |
| 70 | + |
| 71 | +RUN mkdir -p /app/temp /app/media \ |
| 72 | + && chown nextjs:nodejs /app/temp /app/media \ |
| 73 | + && chmod 775 /app/temp /app/media |
| 74 | + |
63 | 75 | USER nextjs |
64 | 76 |
|
65 | 77 | EXPOSE 3000 |
66 | 78 |
|
67 | | -ENV PORT 3000 |
68 | | - |
69 | | -# server.js is created by next build from the standalone output |
70 | | -# https://nextjs.org/docs/pages/api-reference/next-config-js/output |
71 | | -CMD HOSTNAME="0.0.0.0" node server.js |
| 79 | +ENTRYPOINT ["/entrypoint.sh"] |
| 80 | +CMD ["node", "server.js"] |
0 commit comments