Skip to content

Commit 7dc43f1

Browse files
committed
feat: add docker compose for windows
1 parent 41b3af4 commit 7dc43f1

File tree

5 files changed

+62
-100
lines changed

5 files changed

+62
-100
lines changed

docker-compose.dev.yml

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,32 @@ version: '3.8'
22

33
services:
44
app:
5+
image: notifylog:dev
56
build:
67
context: .
7-
dockerfile: docker/dev/Dockerfile
8-
container_name: notify-pro-dev
9-
restart: unless-stopped
8+
dockerfile: docker/dev/Dockerfile.windows
9+
volumes:
10+
- type: bind
11+
source: D:\Github_profile\SmartEduHub-Repo\NotifyLog # host path (Windows OK)
12+
target: /app # <= POSIX path
13+
consistency: cached
14+
- type: volume
15+
source: app_node_modules
16+
target: /app/node_modules
1017
ports:
1118
- "3000:3000"
12-
- "9229:9229" # Node.js debug port
1319
environment:
1420
- NODE_ENV=development
15-
- PORT=3000
16-
- DEBUG=nest:*
17-
- MONGO_URL=mongodb://mongo:27017/notifybd
18-
volumes:
19-
- ./src:/usr/src/app/src
20-
- /usr/src/app/node_modules
21-
- ./tsconfig.json:/usr/src/app/tsconfig.json
22-
- ./nest-cli.json:/usr/src/app/nest-cli.json
23-
depends_on:
24-
- mongo
25-
networks:
26-
- backend
27-
command: npm run start:dev
21+
- MONGO_URL=mongodb://mongo:27017/notifylog
2822

2923
mongo:
3024
image: mongo:6.0
31-
container_name: mongo-dev
32-
restart: always
33-
volumes:
34-
- mongo-dev-data:/data/db
35-
environment:
36-
MONGO_INITDB_ROOT_USERNAME: root
37-
MONGO_INITDB_ROOT_PASSWORD: example
38-
MONGO_INITDB_DATABASE: notifybd
3925
ports:
40-
- "27018:27017" # Different port to avoid conflict with local mongo
41-
networks:
42-
- backend
43-
44-
# Optional Redis for development
45-
redis:
46-
image: redis:7-alpine
47-
container_name: redis-dev
48-
restart: always
26+
- "27017:27017"
4927
volumes:
50-
- redis-dev-data:/data
51-
ports:
52-
- "6380:6379" # Different port to avoid conflict
53-
networks:
54-
- backend
55-
56-
# Optional PGAdmin for database management
57-
pgadmin:
58-
image: dpage/pgadmin4
59-
container_name: pgadmin-dev
60-
environment:
61-
PGADMIN_DEFAULT_EMAIL: admin@example.com
62-
PGADMIN_DEFAULT_PASSWORD: admin
63-
ports:
64-
- "5050:80"
65-
networks:
66-
- backend
28+
- mongo_data:/data/db
6729

6830
volumes:
69-
mongo-dev-data:
70-
driver: local
71-
redis-dev-data:
72-
driver: local
73-
74-
networks:
75-
backend:
76-
driver: bridge
31+
app_node_modules:
32+
name: notifylog_app_node_modules
33+
mongo_data:

docker-compose.yml

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,38 @@ version: '3.8'
22

33
services:
44
app:
5+
image: notifylog:prod
56
build:
67
context: .
7-
dockerfile: docker/prod/Dockerfile
8-
container_name: notify-pro
9-
restart: unless-stopped
8+
dockerfile: docker/prod/Dockerfile.windows
109
ports:
1110
- "3000:3000"
1211
environment:
1312
- NODE_ENV=production
14-
- PORT=3000
15-
- MONGO_URL=mongodb://mongo:27017/notifybd
16-
# Add other environment variables from your .env
17-
depends_on:
18-
- mongo
19-
healthcheck:
20-
test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
21-
interval: 30s
22-
timeout: 10s
23-
retries: 3
13+
- MONGO_URL=mongodb://mongo:27017/notifylog-prod
14+
restart: unless-stopped
2415
networks:
2516
- backend
2617

2718
mongo:
2819
image: mongo:6.0
29-
container_name: mongo
30-
restart: always
31-
volumes:
32-
- mongo-data:/data/db
33-
environment:
34-
MONGO_INITDB_ROOT_USERNAME: root
35-
MONGO_INITDB_ROOT_PASSWORD: example
36-
MONGO_INITDB_DATABASE: notifybd
37-
networks:
38-
- backend
3920
ports:
4021
- "27017:27017"
41-
42-
# Optional Redis for caching
43-
redis:
44-
image: redis:7-alpine
45-
container_name: redis
46-
restart: always
4722
volumes:
48-
- redis-data:/data
23+
- mongo_data:/data/db
24+
environment:
25+
MONGO_INITDB_ROOT_USERNAME: root
26+
MONGO_INITDB_ROOT_PASSWORD: your_secure_password
27+
MONGO_INITDB_DATABASE: notifylog-prod
28+
restart: unless-stopped
4929
networks:
5030
- backend
51-
ports:
52-
- "6379:6379"
5331

5432
volumes:
55-
mongo-data:
56-
driver: local
57-
redis-data:
33+
mongo_data:
5834
driver: local
35+
name: notifylog_mongo_data
5936

6037
networks:
6138
backend:
62-
driver: bridge
39+
driver: nat

docker/dev/Dockerfile.windows

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /app # POSIX path
4+
5+
COPY package*.json ./
6+
RUN npm install
7+
8+
COPY . .
9+
10+
CMD ["npm", "run", "start:dev"]

docker/prod/Dockerfile.windows

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Stage 1: Build
2+
FROM node:18.16.0-windowsservercore AS builder
3+
WORKDIR C:/app
4+
COPY package*.json ./
5+
RUN npm ci --only=production
6+
COPY . .
7+
RUN npm run build
8+
9+
# Stage 2: Run
10+
FROM node:18.16.0-windowsservercore
11+
WORKDIR C:/app
12+
COPY --from=builder C:/app/node_modules ./node_modules
13+
COPY --from=builder C:/app/dist ./dist
14+
COPY --from=builder C:/app/package*.json ./
15+
16+
EXPOSE 3000
17+
CMD ["node", "dist/main"]

src/app.module.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import { LoggerModule } from './logger/logger.module';
88
imports: [
99
ConfigModule.forRoot({
1010
isGlobal: true,
11-
envFilePath: '.env', // Explicit path to .env
12-
ignoreEnvFile: false, // Ensure it's not ignored
11+
envFilePath: '.env', // Loads .env from root directory
1312
}),
1413
MongooseModule.forRootAsync({
1514
imports: [ConfigModule],
16-
useFactory: () => {
17-
const uri = 'mongodb://localhost:27017/notifybd';
15+
useFactory: async (configService: ConfigService) => {
16+
const uri = await Promise.resolve(
17+
configService.get<string>('MONGO_URL'),
18+
);
1819
if (!uri) {
19-
throw new Error('MONGO_URI not found in configuration');
20+
throw new Error('MONGO_URL not found in configuration');
2021
}
2122
return { uri };
2223
},

0 commit comments

Comments
 (0)