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 #124

Closed
wants to merge 2 commits into from
Closed

add docker & api route #124

wants to merge 2 commits into from

Conversation

wvl94
Copy link
Contributor

@wvl94 wvl94 commented Nov 14, 2024

💡 PR Summary generated by FirstMate

Overview: Added Docker support and a new API route for fetching examples by ID.

Changes:
Dockerfile:

  • Created a Dockerfile using Node.js 19-alpine for containerization.
  • Set working directory, added user/group, and installed Git.

API Route Update:

  • Added a new GET route /get/:id in exampleRouter.js for fetching example data.

Configuration Change:

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

TLDR: Introduced Docker support and a new API route for fetching examples, while updating the server port configuration. Review the Dockerfile and exampleRouter.js for key changes.

Generated by FirstMate and automatically updated on every commit.

Copy link

firstmatebot bot commented Nov 14, 2024

PR Review

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

    ❌ Documentation drift: Update documentation for default server port change from 8080 to 80.
    ❌ Docker best practices: Implement multi-stage builds in Dockerfile for optimized image size.
    ❌ Security issues: Add grantAccessByPermissionMiddleware to '/get/:id' route for permission checks.

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

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

You changed the default server port from 8080 to 80. This change seems important, so it might be smart to change the documentation accordingly. Update the documentation to reflect the new default port.

For example:

## Running the Application

To start the application, use:

```bash
npm start

The application will now run on port 80 by default.

Comment on lines +1 to +10
FROM node:19-alpine

WORKDIR /usr/src/app

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

RUN apk add --no-cache git
COPY . .
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

Your Dockerfile should implement multi-stage builds to optimize image size and improve build performance. Consider using a builder stage to install dependencies and build the application, then copy the necessary files to a smaller runtime image. Here's an example:

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

# Production stage
FROM node:19-alpine
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/dist ./
CMD ["npm", "start", "--no-update-notifier"]

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

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)

(Based on guideline 'Routes should check permissions')

Copy link

firstmatebot bot commented Nov 14, 2024

alt text

I analysed the failed pipeline job Validate docker:

Failure Analysis

The pipeline crashed during the Docker build step, specifically when trying to execute the command RUN apk add --no-cache git. The logs indicate a permission issue:

ERROR: Unable to lock database: Permission denied
ERROR: Failed to open apk database: Permission denied

This suggests that the Dockerfile is attempting to install packages as a non-root user (appuser), which does not have the necessary permissions to modify the APK database. This issue is likely related to the Dockerfile configuration rather than the changes made in the PR.

Suggested Fix

To resolve the permission issue, you can modify the Dockerfile to switch to the root user before running the package installation command and then switch back to the non-root user afterward. Here’s how you can adjust the Dockerfile:

- USER appuser
+ USER root
RUN apk add --no-cache git
+ USER appuser

This change ensures that the apk add command runs with the necessary permissions, allowing the installation of the git package to succeed.

@wvl94 wvl94 closed this Nov 14, 2024
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