← All notes

Next.js on Coolify: the build doesn't belong in the entrypoint

A deploy times out, the container never becomes healthy, and the logs show nothing obvious. It all looked like Coolify's fault, or the webhook's, or the network's. It was something else.

The problem

The Dockerfile only copied the sources. The real build ran afterwards, in entrypoint.sh:

npx prisma generate
npm run build
npx prisma migrate deploy
npm start

Every container start re-ran next build. On a development branch, with a build taking several minutes, the deploy timed out before the app was up. To Coolify it had failed; to me it was "just slow".

The fix

The build is a step of the image, not of startup. In the Dockerfile:

RUN npx prisma generate
RUN npm run build

And the entrypoint keeps only what must happen on every start:

npx prisma migrate deploy
npm start

The container starts in seconds, the image is identical across restarts, and rollbacks behave the way you'd expect.

The bonus: Invalid signature

If you trigger deploys from Git with a webhook (it happened to me with Bitbucket) and you see Invalid signature, check that the secret is identical in the repository settings and in Coolify. One character off and every push is rejected with no other clue.

Rule of thumb

If something doesn't change between one start and the next, don't do it at startup.