Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docker & api route #116

Closed
wants to merge 1 commit into from
Closed

add docker & api route #116

wants to merge 1 commit into from

Conversation

wvl94
Copy link
Contributor

@wvl94 wvl94 commented Nov 13, 2024

💡 PR Summary generated by FirstMate

Overview: Added Docker support and a new API route for enhanced functionality.

Changes:
Dockerfile creation:

  • Added a Dockerfile to containerize the application using Node.js 19-alpine.
  • Configured environment variables and user permissions for better security.

API route updates:

  • Introduced a new GET route /get/:id in exampleRouter.js for fetching data by ID.
  • Maintained existing route functionality with permission middleware.

Configuration change:

  • Updated default server port in appConfig.js from 8080 to 80 for consistency.

TLDR: This PR adds Docker support, a new API route for data retrieval, and updates the default server port. Review the Dockerfile and new route in exampleRouter.js.

Generated by FirstMate and automatically updated on every commit.

Copy link

firstmatebot bot commented Nov 13, 2024

PR Review

⚠️ It seems that you can still improve the quality of your PR:

    ❌ Documentation drift: Update documentation for port change from 80 to 8080.
    ❌ Security issues: Missing permission middleware on '/get/:id' route.
    ❌ Dockerfile optimization: Implement multi-stage builds in Dockerfile.
    ❌ Configuration management: Add server port env variable to helm chart values.yaml.

Generated by Firstmate to make sure you can focus on coding new features.

@wvl94 wvl94 closed this Nov 13, 2024
Comment on lines +2 to +12
ENV PORT 8080

WORKDIR /usr/src/app

RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

RUN apk add --no-cache git
COPY . .
EXPOSE 8080
CMD ["npm", "start", "--no-update-notifier"]
Copy link

Choose a reason for hiding this comment

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

alt text

You changed the application to run on port 8080 in the Dockerfile, while the configuration in appConfig.js now defaults to port 80. This change seems important, so it might be smart to change the documentation accordingly.

For example, update the documentation to reflect the following:

## Running the Application

To start the application, use the following command:

```bash
docker run -p 8080:8080 your-image-name

By default, the application will run on port 80 unless specified otherwise.

Comment on lines +12 to +13
router.route("/get/:id").get(exampleController.getById)

Copy link

Choose a reason for hiding this comment

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

alt text

The route '/get/:id' is missing the grantAccessByPermissionMiddleware, which is essential for proper permission checks. Update the route definition to include this middleware as follows:

+ router.route("/get/:id").get(grantAccessByPermissionMiddleware([API_PERMISSIONS.PUBLIC_ENDPOINT]), exampleController.getById)

This ensures that access permissions are validated before executing the controller logic.

(Based on guideline 'Routes should check permissions')

Comment on lines +1 to +12
FROM node:19-alpine
ENV PORT 8080

WORKDIR /usr/src/app

RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser

RUN apk add --no-cache git
COPY . .
EXPOSE 8080
CMD ["npm", "start", "--no-update-notifier"]
Copy link

Choose a reason for hiding this comment

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

alt text

Consider using multi-stage builds in your Dockerfile to optimize the build process and reduce the final image size. You can achieve this by separating the build and runtime stages like this:

FROM node:19-alpine AS build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .

FROM node:19-alpine
WORKDIR /usr/src/app
COPY --from=build /usr/src/app ./
EXPOSE 8080
CMD ["npm", "start", "--no-update-notifier"]

(Based on guideline 'Dockerfiles should use multi-stage builds')

Comment on lines +4 to 5
return process.env.PORT || 80;
}
Copy link

Choose a reason for hiding this comment

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

alt text

Ensure that the updated server port environment variable is added to the helm chart values.yaml file under the configmap section for non-secret variables. This will allow for better configuration management and flexibility in your deployments. Here's an example of how you can add it:

configmap:
  serverPort: {{ .Values.serverPort | default "80" }}

(Based on guideline 'Env vars in helm chart values.yaml')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant