contentlayerdev/contentlayer

Do we need to copy the .contentlayer in Docker?

alamenai opened this issue · 1 comments

I'm trying to add Docker to my NextJS application, however, I'm encountering an issue which is related to this issue. Thought, I tried the recommended solution but I'm still facing the issue.

ISSUE LOG

$ sudo docker-compose up --build --force-recreate
Building app
[+] Building 330.4s (21/21) FINISHED                                                                               docker:default
 => [internal] load build definition from Dockerfile                                                                         0.0s
 => => transferring dockerfile: 557B                                                                                         0.0s
 => [internal] load .dockerignore                                                                                            0.0s
 => => transferring context: 108B                                                                                            0.0s
 => [internal] load metadata for docker.io/library/node:20                                                                   0.8s
 => [internal] load build context                                                                                            0.1s
 => => transferring context: 57.87kB                                                                                         0.1s
 => [ 1/17] FROM docker.io/library/node:20@sha256:ffebb4405810c92d267a764b21975fb2d96772e41877248a37bf3abaa0d3b590           0.0s
 => CACHED [ 2/17] WORKDIR /app                                                                                              0.0s
 => [ 3/17] COPY package.json ./                                                                                             0.1s
 => [ 4/17] RUN npm install pnpm -g                                                                                          4.9s
 => [ 5/17] RUN pnpm install                                                                                               299.5s 
 => [ 6/17] COPY public ./public                                                                                             0.5s 
 => [ 7/17] COPY next.config.js ./next.config.js                                                                             0.2s 
 => [ 8/17] COPY .contentlayer ./.contentlayer                                                                               0.2s 
 => [ 9/17] COPY scripts ./scripts                                                                                           0.2s 
 => [10/17] COPY src ./src                                                                                                   0.8s 
 => [11/17] COPY ui ./ui                                                                                                     0.3s 
 => [12/17] COPY .sentryclirc ./sentryclirc                                                                                  0.2s
 => [13/17] COPY sentry.server.config.ts ./sentry.server.config.ts                                                           0.2s
 => [14/17] COPY sentry.client.config.ts ./sentry.client.config.ts                                                           0.6s
 => [15/17] COPY sentry.edge.config.ts ./sentry.edge.config.ts                                                               0.2s
 => [16/17] RUN npm install -g pnpm                                                                                         13.1s
 => ERROR [17/17] RUN pnpm build                                                                                             8.0s
------                                                                                                                            
 > [17/17] RUN pnpm build:                                                                                                        
2.188                                                                                                                             
2.188 > credium-gersthofen-app@0.1.0 build /app
2.188 > INIT_CWD=$PWD next build
2.188 
4.110 Attention: Next.js now collects completely anonymous telemetry regarding usage.
4.111 This information is used to shape Next.js' roadmap and prioritize features.
4.111 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
4.111 https://nextjs.org/telemetry
4.111 
4.321    ▲ Next.js 14.0.4
4.322 
4.322    Creating an optimized production build ...
5.143 warn  - It seems like you don't have a global error handler set up. It is recommended that you add a global-error.js file with Sentry instrumentation so that React rendering errors are reported to Sentry. Read more: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#react-render-errors-in-app-router
7.773 NoConfigFoundError {
7.773   cwd: '/app',
7.773   configPath: undefined,
7.773   _tag: 'NoConfigFoundError',
7.773   toString: [Function (anonymous)],
7.773   [Symbol()]: { cwd: '/app', configPath: undefined },
7.773   [Symbol()]: [ 'configPath', 'cwd' ]
7.773 }
7.801  ELIFECYCLE  Command failed with exit code 1.
------
Dockerfile:33
--------------------
  31 |     RUN npm install -g pnpm
  32 |     
  33 | >>> RUN pnpm build
  34 |     
  35 |     EXPOSE 3000
--------------------
ERROR: failed to solve: process "/bin/sh -c pnpm build" did not complete successfully: exit code: 1
ERROR: Service 'app' failed to build : Build failed

ERROR

NoConfigFoundError {
7.773   cwd: '/app',
7.773   configPath: undefined,
7.773   _tag: 'NoConfigFoundError',
7.773   toString: [Function (anonymous)],
7.773   [Symbol()]: { cwd: '/app', configPath: undefined },
7.773   [Symbol()]: [ 'configPath', 'cwd' ]
7.773 }
7.801  ELIFECYCLE  Command failed with exit code 1.
------

Dockerfile

FROM node:20

WORKDIR /app

COPY package.json ./

RUN npm install pnpm -g

RUN pnpm install

COPY public ./public

COPY next.config.js ./next.config.js

COPY .contentlayer ./.contentlayer

COPY scripts ./scripts

COPY src ./src

COPY ui ./ui

COPY .sentryclirc ./sentryclirc

COPY sentry.server.config.ts ./sentry.server.config.ts

COPY sentry.client.config.ts ./sentry.client.config.ts

COPY sentry.edge.config.ts ./sentry.edge.config.ts

RUN npm install -g pnpm

RUN pnpm build

EXPOSE 3000

CMD [ "pnpm","start" ]

Recommended solution

 "build": "INIT_CWD=$PWD next build",

It does not work, any thoughts guys?

I figured out that .contentlayer is a generated folder which means when I copy the NextJS configuration it will generate that folder inside the docker container.