Skip to content

Commit 880bbbb

Browse files
Add Dockerfile for backend and frontend applications
* **Backend Dockerfile** - Add instructions to build and run the backend server - Use node:20-alpine as the base image - Set the working directory to /app - Copy package.json and pnpm-lock.yaml to the working directory - Install dependencies using pnpm install --frozen-lockfile - Copy the rest of the application code to the working directory - Build the application using pnpm nx build devmx --verbose - Expose port 3000 - Set the command to run the application using node dist/apps/server/main.js * **Frontend Dockerfile** - Add instructions to build and run the frontend application - Use node:20-alpine as the base image - Set the working directory to /app - Copy package.json and pnpm-lock.yaml to the working directory - Install dependencies using pnpm install --frozen-lockfile - Copy the rest of the application code to the working directory - Build the application using pnpm nx build devmx --verbose - Expose port 4200 - Set the command to run the application using pnpm nx serve devmx * **package.json** - Add docker-compose script to start all services using Docker Compose * **docker-compose.yml** - Add server service to build and run the backend server - Add devmx service to build and run the frontend application - Configure mongodb service to depend on server and devmx services
1 parent 181c124 commit 880bbbb

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Backend Dockerfile
2+
13
# Use node:20-alpine as the base image
24
FROM node:20-alpine
35

@@ -21,3 +23,29 @@ EXPOSE 3000
2123

2224
# Set the command to run the application using node dist/apps/server/main.js
2325
CMD ["node", "dist/apps/server/main.js"]
26+
27+
# Frontend Dockerfile
28+
29+
# Use node:20-alpine as the base image
30+
FROM node:20-alpine
31+
32+
# Set the working directory to /app
33+
WORKDIR /app
34+
35+
# Copy package.json and pnpm-lock.yaml to the working directory
36+
COPY package.json pnpm-lock.yaml ./
37+
38+
# Install dependencies using pnpm install --frozen-lockfile
39+
RUN npm install -g pnpm && pnpm install --frozen-lockfile
40+
41+
# Copy the rest of the application code to the working directory
42+
COPY . .
43+
44+
# Build the application using pnpm nx build devmx --verbose
45+
RUN pnpm nx build devmx --verbose
46+
47+
# Expose port 4200
48+
EXPOSE 4200
49+
50+
# Set the command to run the application using pnpm nx serve devmx
51+
CMD ["pnpm", "nx", "serve", "devmx"]

docker-compose.yml

+34
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,37 @@ services:
99
MONGO_INITDB_DATABASE: ${DB_NAME}
1010
ports:
1111
- 27017:27017
12+
13+
server:
14+
build:
15+
context: .
16+
dockerfile: Dockerfile
17+
environment:
18+
PORT: ${PORT}
19+
DB_HOST: mongodb
20+
DB_PORT: ${DB_PORT}
21+
DB_NAME: ${DB_NAME}
22+
DB_USER: ${DB_USER}
23+
DB_PASS: ${DB_PASS}
24+
JWT_SECRET: ${JWT_SECRET}
25+
SMTP_HOST: ${SMTP_HOST}
26+
SMTP_PORT: ${SMTP_PORT}
27+
SMTP_USER: ${SMTP_USER}
28+
SMTP_PASS: ${SMTP_PASS}
29+
CODE_LIFE_TIME: ${CODE_LIFE_TIME}
30+
ports:
31+
- 3000:3000
32+
depends_on:
33+
- mongodb
34+
35+
devmx:
36+
build:
37+
context: .
38+
dockerfile: Dockerfile
39+
environment:
40+
PORT: ${PORT}
41+
ports:
42+
- 4200:4200
43+
depends_on:
44+
- server
45+
- mongodb

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"dev:setup": "./tools/scripts/setup.sh",
1313
"commit": "czg",
1414
"prepare": "husky",
15-
"docker:build": "docker build -t devmx-server ."
15+
"docker:build": "docker build -t devmx-server .",
16+
"docker-compose": "docker-compose up --build"
1617
},
1718
"private": true,
1819
"devDependencies": {

0 commit comments

Comments
 (0)