Skip to content

Commit eb2535c

Browse files
committed
feat(docker): update Dockerfiles to use npm instead of yarn and restructure docker-compose files
1 parent b482d19 commit eb2535c

8 files changed

Lines changed: 83 additions & 86 deletions

Dockerfile.dev

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
# Stage 1: Build the frontend
21
FROM node:20-alpine
32

4-
# Set the working directory
53
WORKDIR /app
64

7-
# Copy package.json
85

96
COPY package.json .
107

11-
# Install all dependencies
12-
RUN yarn install
8+
RUN npm install
139

14-
# Copy the rest of the application files
1510
COPY . .
1611

17-
# Expose the port for the application
18-
EXPOSE 3000
12+
EXPOSE 5173
1913

20-
# Start Nginx
21-
CMD ["yarn","dev", "--port", "3000","--host"]
14+
CMD ["npm","run","dev"]

Dockerfile renamed to Dockerfile.prod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ WORKDIR /app
88
COPY package.json .
99

1010
# Install production dependencies using Yarn
11-
RUN yarn install --production
11+
RUN npm install --production
1212
# Copy the rest of the application files
1313
COPY . .
1414

1515
# Build the frontend using Yarn
16-
RUN yarn run build
16+
RUN npm run build
1717

1818
# Stage 2: Serve the application with Nginx
1919
FROM nginx:alpine

backend/Dockerfile.dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ WORKDIR /app
88
COPY package.json ./
99

1010
# Install all dependencies using Yarn
11-
RUN yarn install
11+
RUN npm install
1212

1313
# Copy the rest of the application files
1414
COPY . .
@@ -17,4 +17,4 @@ COPY . .
1717
EXPOSE 5000
1818

1919
# Start the server in dev mode using Yarn
20-
CMD ["yarn", "dev"]
20+
CMD ["npm","run", "dev"]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ WORKDIR /app
88
COPY package.json ./
99

1010
# Install production dependencies using Yarn
11-
RUN yarn install --production
11+
RUN npm install --production
1212

1313
# Copy the rest of the application files
1414
COPY . .
@@ -17,4 +17,4 @@ COPY . .
1717
EXPOSE 5000
1818

1919
# Start the server in production mode using Yarn
20-
CMD ["yarn", "start"]
20+
CMD ["npm","run", "start"]

docker-compose.dev.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

docker-compose.prod.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

docker-compose.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
services:
2+
frontend:
3+
image: frontend
4+
container_name: frontend-container
5+
build:
6+
context: .
7+
dockerfile: Dockerfile.dev
8+
ports:
9+
- "5173:5173"
10+
env_file:
11+
- .env
12+
volumes:
13+
- .:/app
14+
- /app/node_modules
15+
depends_on:
16+
- backend
17+
networks:
18+
- app-network-1
19+
profiles:
20+
- dev
21+
backend:
22+
image: backend
23+
container_name: backend-container
24+
build:
25+
context: ./backend
26+
dockerfile: Dockerfile.dev
27+
ports:
28+
- "5000:5000"
29+
env_file:
30+
- ./backend/.env
31+
volumes:
32+
- ./backend:/app
33+
- /app/node_modules
34+
networks:
35+
- app-network-1
36+
profiles:
37+
- dev
38+
frontend-prod:
39+
image: frontend-prod
40+
container_name: frontend-prod-container
41+
build:
42+
context: .
43+
dockerfile: Dockerfile.prod
44+
ports:
45+
- "3000:3000"
46+
env_file:
47+
- .env
48+
depends_on:
49+
- backend-prod
50+
networks:
51+
- app-network-2
52+
profiles:
53+
- prod
54+
backend-prod:
55+
image: backend-prod
56+
container_name: backend-prod-container
57+
build:
58+
context: backend
59+
dockerfile: Dockerfile.prod
60+
ports:
61+
- "5000:5000"
62+
env_file:
63+
- backend/.env
64+
networks:
65+
- app-network-2
66+
profiles:
67+
- prod
68+
networks:
69+
app-network-1:
70+
app-network-2:

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
"version": "0.0.0",
55
"type": "module",
66
"scripts": {
7-
"dev": "vite",
7+
"dev": "vite --host",
88
"build": "vite build",
99
"lint": "eslint .",
10-
"preview": "vite preview"
10+
"preview": "vite preview",
11+
"docker:dev":"docker compose --profile dev up --build",
12+
"docker:prod":"docker compose --profile prod up -d --build"
1113
},
1214
"dependencies": {
1315
"@emotion/react": "^11.11.3",

0 commit comments

Comments
 (0)