chore(docker): configure docker build and deployment#24
chore(docker): configure docker build and deployment#24francescopausellii wants to merge 3 commits intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces Docker support for the Next.js application using a multi-stage build and a distroless runtime image. Feedback focuses on ensuring the Dockerfile aligns with the project's Next.js configuration for standalone output, addressing a security risk associated with unverified remote script execution during the build process, and improving image portability by removing hardcoded runtime environment variables.
| HOSTNAME=0.0.0.0 | ||
|
|
||
| # Copy optimized build output | ||
| COPY --from=builder --chown=nonroot:nonroot /app/.next/standalone ./ |
There was a problem hiding this comment.
| RUN npm run build && \ | ||
| curl -sf https://gobinaries.com/tj/node-prune | sh && \ | ||
| node-prune .next/standalone/node_modules |
There was a problem hiding this comment.
Piping curl to sh from a URL is a security risk as it executes remote code without verification. For improved security and reproducibility, it's better to download a specific, versioned release of node-prune from its official GitHub repository.
RUN npm run build && \
(curl -sfL https://github.com/tj/node-prune/releases/download/v1.7.0/node-prune_1.7.0_linux_amd64.tar.gz | tar -xz -C /usr/local/bin) && \
node-prune .next/standalone/node_modules
| ENV NODE_ENV=production \ | ||
| PORT=3000 \ | ||
| HOSTNAME=0.0.0.0 |
There was a problem hiding this comment.
Hardcoding runtime configuration like PORT and HOSTNAME in the Docker image reduces its portability. It's better to configure these via environment variables at runtime (which you are already doing in docker-compose.yml). I suggest removing them from the Dockerfile and only keeping NODE_ENV=production.
ENV NODE_ENV=production
No description provided.