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

Added the Dockerfile #156

Merged
merged 6 commits into from
Oct 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM node:18 AS frontend-build

WORKDIR /app/frontend
COPY frontend/package*.json ./

RUN npm install
COPY frontend/ ./

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using a .dockerignore file for the frontend.

The frontend build stage follows good practices by leveraging Docker's layer caching. However, copying the entire frontend directory might include unnecessary files, potentially increasing the image size.

Consider creating a .dockerignore file in the frontend directory to exclude files not needed for the build (e.g., .git, node_modules, etc.). This can help reduce the image size and build time.

Example .dockerignore content:

node_modules
npm-debug.log
.git
.gitignore
README.md


FROM node:18 AS backend-build

WORKDIR /app/backend
COPY backend/package*.json ./

RUN npm install
COPY backend/ ./

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider using a .dockerignore file for the backend.

The backend build stage, like the frontend, follows good practices by leveraging Docker's layer caching. However, copying the entire backend directory might include unnecessary files, potentially increasing the image size.

Consider creating a .dockerignore file in the backend directory to exclude files not needed for the build (e.g., .git, node_modules, etc.). This can help reduce the image size and build time.

Example .dockerignore content:

node_modules
npm-debug.log
.git
.gitignore
README.md


FROM node:18
RUN npm install -g concurrently

WORKDIR /app

COPY --from=backend-build /app/backend ./backend
COPY --from=frontend-build /app/frontend ./frontend

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider alternatives to global package installation.

While using concurrently is a good approach for running multiple commands simultaneously, installing packages globally in a production image is generally not recommended as it can lead to versioning issues and larger image sizes.

Consider these alternatives:

  1. Install concurrently as a local dev dependency in your project:

    RUN npm init -y && npm install concurrently --save-dev
    

    Then update the CMD to use the local installation:

    CMD ["npx", "concurrently", "cd frontend && npm run dev", "cd backend && npm run dev"]
    
  2. Use a shell script to start both services:
    Create a start.sh file:

    #!/bin/sh
    cd frontend && npm run dev &
    cd backend && npm run dev

    Then in your Dockerfile:

    COPY start.sh .
    CMD ["sh", "start.sh"]

These approaches avoid global package installation and provide more flexibility.

EXPOSE 5173 3000

CMD concurrently "cd frontend && npm run dev" "cd backend && npm run dev"