Skip to content

Dockerize API application with multi-stage build and update utils#49

Open
ChristianSanchez25 wants to merge 1 commit intofeat/new-templatefrom
feat-docker-api
Open

Dockerize API application with multi-stage build and update utils#49
ChristianSanchez25 wants to merge 1 commit intofeat/new-templatefrom
feat-docker-api

Conversation

@ChristianSanchez25
Copy link
Copy Markdown

Dockerfile optimizado para la API
image
image

@socket-security
Copy link
Copy Markdown

Comment on lines +50 to +54
COPY --from=prod-deps --chown=nestjs:nodejs /app/node_modules ./node_modules
COPY --from=installer --chown=nestjs:nodejs /app/packages ./packages
COPY --from=installer --chown=nestjs:nodejs /app/${APP_PATH}/dist ./${APP_PATH}/dist
COPY --from=installer --chown=nestjs:nodejs /app/${APP_PATH}/package.json ./${APP_PATH}/package.json
COPY --from=installer --chown=nestjs:nodejs /app/package.json ./package.json
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The COPY --chown command in the Dockerfile references a non-existent group nodejs instead of the created avilatek group, causing file permission errors at runtime.
Severity: CRITICAL

Suggested Fix

In the Dockerfile, change all instances of COPY --chown=nestjs:nodejs to COPY --chown=nestjs:avilatek to correctly assign file ownership to the user and group created within the Docker image.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: apps/api/Dockerfile#L50-L54

Potential issue: The Dockerfile creates a user group named `avilatek` but later attempts
to assign file ownership to a non-existent group `nodejs` using `COPY
--chown=nestjs:nodejs`. Docker silently ignores ownership changes when the specified
group does not exist, causing the files to be owned by `root`. Since the container runs
as the `nestjs` user, the application will not have the necessary permissions to read
its own files, leading to "permission denied" errors and causing the container to crash
upon startup.

Did we get this right? 👍 / 👎 to inform future reviews.

EXPOSE 3000

WORKDIR /app/${APP_PATH}
CMD ["node", "dist/src/main.js"] No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The Dockerfile CMD instruction points to an incorrect entry point path (dist/src/main.js) that does not match the actual build output location (dist/main.js).
Severity: CRITICAL

Suggested Fix

Update the CMD instruction in the Dockerfile to point to the correct entry point path. Change CMD ["node", "dist/src/main.js"] to CMD ["node", "dist/main.js"].

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: apps/api/Dockerfile#L60

Potential issue: The Dockerfile's `CMD` instruction specifies `dist/src/main.js` as the
application entry point. However, the NestJS build process, configured with `sourceRoot:
"src"`, compiles `src/main.ts` directly to `dist/main.js`, without preserving the `src`
directory in the output. When the container starts, it will attempt to execute a file at
a path that does not exist, resulting in an immediate "Error: Cannot find module" crash.

Did we get this right? 👍 / 👎 to inform future reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app:api kind:feat Is a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant