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

Demo - [Guidelines] - Adding Dockerfile #93

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

wvl94
Copy link
Contributor

@wvl94 wvl94 commented Nov 5, 2024

💡 PR Summary generated by FirstMate

Overview: Added a Dockerfile to containerize the application for easier deployment.

Changes:
New Dockerfile:

  • Created /Dockerfile to define the application environment.
  • Set base image to node:19-alpine for a lightweight container.
  • Configured working directory to /usr/src/app.
  • Installed git using Alpine package manager.
  • Copied application files into the container.
  • Exposed port 8080 for application access.
  • Defined command to start the application with npm.

TLDR: A Dockerfile was added to facilitate application containerization; focus on the configuration and commands defined within.

Generated by FirstMate and automatically updated on every commit.

Copy link

firstmatebot bot commented Nov 5, 2024

PR Review

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

    ❌ Docker & containerization: Optimize Dockerfiles with multi-stage builds and avoid running as root for security.

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

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

WORKDIR /usr/src/app

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

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

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

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

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

WORKDIR /usr/src/app

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

The Dockerfile is currently running as the root user, which poses a security risk. It's better to create a non-root user and switch to it by adding the following lines to your Dockerfile:

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

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