Skip to content

Commit 41b3af4

Browse files
committed
feat: added decoker files system
1 parent b0c0323 commit 41b3af4

5 files changed

Lines changed: 207 additions & 0 deletions

File tree

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
node_modules
2+
dist
3+
.git
4+
*.log
5+
.env.local
6+
.env.docker.local
7+
Dockerfile
8+
docker-compose*
9+
npm-debug.log
10+
build
11+
coverage
12+
test

docker-compose.dev.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: docker/dev/Dockerfile
8+
container_name: notify-pro-dev
9+
restart: unless-stopped
10+
ports:
11+
- "3000:3000"
12+
- "9229:9229" # Node.js debug port
13+
environment:
14+
- 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
28+
29+
mongo:
30+
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
39+
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
49+
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
67+
68+
volumes:
69+
mongo-dev-data:
70+
driver: local
71+
redis-dev-data:
72+
driver: local
73+
74+
networks:
75+
backend:
76+
driver: bridge

docker-compose.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
version: '3.8'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: docker/prod/Dockerfile
8+
container_name: notify-pro
9+
restart: unless-stopped
10+
ports:
11+
- "3000:3000"
12+
environment:
13+
- 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
24+
networks:
25+
- backend
26+
27+
mongo:
28+
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
39+
ports:
40+
- "27017:27017"
41+
42+
# Optional Redis for caching
43+
redis:
44+
image: redis:7-alpine
45+
container_name: redis
46+
restart: always
47+
volumes:
48+
- redis-data:/data
49+
networks:
50+
- backend
51+
ports:
52+
- "6379:6379"
53+
54+
volumes:
55+
mongo-data:
56+
driver: local
57+
redis-data:
58+
driver: local
59+
60+
networks:
61+
backend:
62+
driver: bridge

docker/dev/Dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:20-alpine
2+
3+
WORKDIR /usr/src/app
4+
5+
# Install dependencies
6+
COPY package*.json ./
7+
RUN npm install
8+
9+
# Install NestJS CLI globally
10+
RUN npm install -g @nestjs/cli
11+
12+
# Copy config files
13+
COPY tsconfig*.json ./
14+
COPY nest-cli.json ./
15+
16+
EXPOSE 3000 9229
17+
18+
CMD ["npm", "run", "start:dev"]

docker/prod/Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Stage 1: Build
2+
FROM node:20-alpine AS builder
3+
4+
WORKDIR /usr/src/app
5+
6+
# Install dependencies
7+
COPY package*.json ./
8+
COPY tsconfig*.json ./
9+
RUN npm ci --omit=dev
10+
11+
# Copy source
12+
COPY src ./src
13+
COPY nest-cli.json ./
14+
15+
# Build
16+
RUN npm run build
17+
18+
# Stage 2: Run
19+
FROM node:20-alpine
20+
21+
WORKDIR /usr/src/app
22+
23+
# Install production dependencies
24+
COPY package*.json ./
25+
RUN npm ci --omit=dev
26+
27+
# Copy built files
28+
COPY --from=builder /usr/src/app/dist ./dist
29+
30+
# Set timezone
31+
RUN apk add --no-cache tzdata
32+
ENV TZ=UTC
33+
34+
# Health check
35+
HEALTHCHECK --interval=30s --timeout=5s \
36+
CMD wget --spider http://localhost:3000/api/health || exit 1
37+
38+
EXPOSE 3000
39+
CMD ["node", "dist/main"]

0 commit comments

Comments
 (0)