-
Notifications
You must be signed in to change notification settings - Fork 62
feat(docker): add Docker support for frontend and backend with development and production configurations #91
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
Changes from all commits
c143fca
b482d19
eb2535c
b0be39e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| backend | ||
| node_modules | ||
| dist | ||
| build | ||
| .gitignore | ||
| .git | ||
| .env.* | ||
| .github | ||
| yarn.lock |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| # Node modules | ||
| node_modules/ | ||
| package-lock.json | ||
| */yarn.lock | ||
| yarn.lock | ||
| # Logs | ||
| logs | ||
| *.log | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| FROM node:20-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
|
|
||
| COPY package.json . | ||
|
|
||
| RUN npm install | ||
|
|
||
| COPY . . | ||
|
|
||
| EXPOSE 5173 | ||
|
|
||
| CMD ["npm","run","dev"] | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,44 @@ | ||||||||||||||||||||||||||||||||
| # Stage 1: Build the frontend | ||||||||||||||||||||||||||||||||
| FROM node:20-alpine AS build | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Set the working directory | ||||||||||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Copy package.json | ||||||||||||||||||||||||||||||||
| COPY package.json . | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Install production dependencies using Yarn | ||||||||||||||||||||||||||||||||
| RUN npm install --production | ||||||||||||||||||||||||||||||||
| # Copy the rest of the application files | ||||||||||||||||||||||||||||||||
| COPY . . | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Build the frontend using Yarn | ||||||||||||||||||||||||||||||||
| RUN npm run build | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
Comment on lines
+10
to
+17
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build will fail – The build stage installs only production deps, but the -# Install production dependencies using Yarn
-RUN npm install --production
+# Install all deps required for the build
+COPY package*.json ./
+RUN npm ciIf you want a slim final image, keep 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| # Stage 2: Serve the application with Nginx | ||||||||||||||||||||||||||||||||
| FROM nginx:alpine | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Copy the build output from the previous stage to Nginx's serve directory | ||||||||||||||||||||||||||||||||
| COPY --from=build /app/dist /usr/share/nginx/html | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Remove the default Nginx configuration file | ||||||||||||||||||||||||||||||||
| RUN rm /etc/nginx/conf.d/default.conf | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Create a new Nginx configuration file | ||||||||||||||||||||||||||||||||
| RUN echo $'\ | ||||||||||||||||||||||||||||||||
| server { \n\ | ||||||||||||||||||||||||||||||||
| listen 3000; \n\ | ||||||||||||||||||||||||||||||||
| server_name localhost; \n\ | ||||||||||||||||||||||||||||||||
| root /usr/share/nginx/html; \n\ | ||||||||||||||||||||||||||||||||
| index index.html; \n\ | ||||||||||||||||||||||||||||||||
| \n\ | ||||||||||||||||||||||||||||||||
| location / { \n\ | ||||||||||||||||||||||||||||||||
| try_files $uri $uri/ /index.html; \n\ | ||||||||||||||||||||||||||||||||
| } \n\ | ||||||||||||||||||||||||||||||||
| }' > /etc/nginx/conf.d/default.conf | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Expose port 3000 | ||||||||||||||||||||||||||||||||
| EXPOSE 3000 | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| # Start Nginx | ||||||||||||||||||||||||||||||||
| CMD ["nginx", "-g", "daemon off;"] | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| node_modules | ||
| .gitignore | ||
| .git | ||
| .env.* | ||
| yarn.lock |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||
| # Use a lightweight Node.js Alpine image | ||||||||||||||||||||||
| FROM node:20-alpine | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Set the working directory | ||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Copy package.json and yarn.lock files for dependency installation | ||||||||||||||||||||||
| COPY package.json ./ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Install all dependencies using Yarn | ||||||||||||||||||||||
| RUN npm install | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
+7
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Copy the lock-file and switch to
-# Copy package.json and yarn.lock files for dependency installation
-COPY package.json ./
-
-# Install all dependencies using Yarn
-RUN npm install
+# Copy manifest + lock-file for proper layer caching
+COPY package*.json ./
+
+# Faster, deterministic install
+RUN npm ci📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| # Copy the rest of the application files | ||||||||||||||||||||||
| COPY . . | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Expose the port for the application | ||||||||||||||||||||||
| EXPOSE 5000 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # Start the server in dev mode using Yarn | ||||||||||||||||||||||
| CMD ["npm","run", "dev"] | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||||
| # Use a lightweight Node.js Alpine image | ||||||||||||||||||||||||
| FROM node:20-alpine | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Set the working directory | ||||||||||||||||||||||||
| WORKDIR /app | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Copy package.json and yarn.lock files for dependency installation | ||||||||||||||||||||||||
| COPY package.json ./ | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Install production dependencies using Yarn | ||||||||||||||||||||||||
| RUN npm install --production | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
Comment on lines
+7
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Production image installs without lockfile and misses
-# Copy package.json and yarn.lock files for dependency installation
-COPY package.json ./
-# Install production dependencies using Yarn
-RUN npm install --production
+# Copy manifest + lock-file
+COPY package*.json ./
+
+# Install only prod deps in a reproducible way
+ENV NODE_ENV=production
+RUN npm ci --only=production📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| # Copy the rest of the application files | ||||||||||||||||||||||||
| COPY . . | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Expose the port for the application | ||||||||||||||||||||||||
| EXPOSE 5000 | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Start the server in production mode using Yarn | ||||||||||||||||||||||||
| CMD ["npm","run", "start"] | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| services: | ||
| frontend: | ||
| image: frontend | ||
| container_name: frontend-container | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile.dev | ||
| ports: | ||
| - "5173:5173" | ||
| env_file: | ||
| - .env | ||
| volumes: | ||
| - .:/app | ||
| - /app/node_modules | ||
| depends_on: | ||
| - backend | ||
| networks: | ||
| - app-network-1 | ||
| profiles: | ||
| - dev | ||
| backend: | ||
| image: backend | ||
| container_name: backend-container | ||
| build: | ||
| context: ./backend | ||
| dockerfile: Dockerfile.dev | ||
| ports: | ||
| - "5000:5000" | ||
| env_file: | ||
| - ./backend/.env | ||
| volumes: | ||
| - ./backend:/app | ||
| - /app/node_modules | ||
| networks: | ||
| - app-network-1 | ||
| profiles: | ||
| - dev | ||
| frontend-prod: | ||
| image: frontend-prod | ||
| container_name: frontend-prod-container | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile.prod | ||
| ports: | ||
| - "3000:3000" | ||
| env_file: | ||
| - .env | ||
| depends_on: | ||
| - backend-prod | ||
| networks: | ||
| - app-network-2 | ||
| profiles: | ||
| - prod | ||
| backend-prod: | ||
| image: backend-prod | ||
| container_name: backend-prod-container | ||
| build: | ||
| context: backend | ||
| dockerfile: Dockerfile.prod | ||
| ports: | ||
| - "5000:5000" | ||
| env_file: | ||
| - backend/.env | ||
| networks: | ||
| - app-network-2 | ||
| profiles: | ||
| - prod | ||
| networks: | ||
| app-network-1: | ||
| app-network-2: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,12 @@ | |
| "version": "0.0.0", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vite", | ||
| "dev": "vite --host", | ||
| "build": "vite build", | ||
| "lint": "eslint .", | ||
| "preview": "vite preview" | ||
| "preview": "vite preview", | ||
| "docker:dev":"docker compose --profile dev up --build", | ||
| "docker:prod":"docker compose --profile prod up -d --build" | ||
| }, | ||
| "dependencies": { | ||
| "@emotion/react": "^11.11.3", | ||
|
|
@@ -22,7 +24,10 @@ | |
| "react-dom": "^18.3.1", | ||
| "react-hot-toast": "^2.4.1", | ||
| "react-icons": "^5.3.0", | ||
| "react-router-dom": "^6.28.0" | ||
| "react-router-dom": "^6.28.0", | ||
| "postcss": "^8.4.47", | ||
| "autoprefixer": "^10.4.20", | ||
| "tailwindcss": "^3.4.14" | ||
|
Comment on lines
+28
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate
@@
- "postcss": "^8.4.47",
- "autoprefixer": "^10.4.20",
- "tailwindcss": "^3.4.14"
+ "postcss": "^8.4.47",
+ "tailwindcss": "^3.4.14"
@@
- "autoprefixer": "^10.4.20",Move it to one block (usually Also applies to: 41-41 🤖 Prompt for AI Agents |
||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "^9.13.0", | ||
|
|
@@ -44,9 +49,7 @@ | |
| "jasmine": "^5.9.0", | ||
| "passport": "^0.7.0", | ||
| "passport-local": "^1.0.0", | ||
| "postcss": "^8.4.47", | ||
| "supertest": "^7.1.4", | ||
| "tailwindcss": "^3.4.14", | ||
| "vite": "^5.4.10" | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Lock-file omitted – builds will be slow and non-reproducible
Identical to the backend dev image, copy the lock-file and prefer
npm ci:🤖 Prompt for AI Agents