wip: final docker compose

This commit is contained in:
Nabil Ould Hamou 2024-12-17 17:43:15 +01:00
parent 50f19e0d64
commit caf6e771f8
5 changed files with 53 additions and 7 deletions

13
Dockerfile Normal file
View file

@ -0,0 +1,13 @@
# Build stage
FROM node:18.18-alpine
RUN npm i -g pnpm
EXPOSE 3000
ENV NODE_ENV=production
COPY . /app
WORKDIR /app
CMD docker_entrypoint.sh

View file

@ -1,4 +1,19 @@
services:
app:
build: .
hostname: chat-app
restart: always
environment:
- DATABASE_URL=mongodb://temp-root-username:temp-password@mongodb:27017/chat_projetweb
- JWT_SECRET=1f49ba5426afebd6e27eed416d0c31925ca5c4dc39ab4fdea514c8a858312608
ports:
- "3000:3000"
networks:
- app_network
depends_on:
- mongodb
- redis
mongodb:
build: ./mongodb_rs
hostname: mongodb
@ -15,11 +30,11 @@ services:
- mongo-data:/data/db/
- mongo-logs:/var/log/mongodb/
networks:
- mongodb_network
- app_network
redis:
image: redis:latest
hostname: redis
hostname: redis-server
restart: always
ports:
- "6379:6379"
@ -29,11 +44,11 @@ services:
volumes:
- redis-data:/root/redis
networks:
- redis_network
- app_network
networks:
mongodb_network:
redis_network:
app_network:
driver: bridge
volumes:
mongo-data:

12
docker_entrypoint.sh Normal file
View file

@ -0,0 +1,12 @@
#!/bin/sh
set -xe
pnpm install
pnpm prisma generate
pnpm run build
pnpm prune --prod
pnpx prisma db push
node build/index.js

View file

@ -6,6 +6,7 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["debian-openssl-1.1.x", "linux-musl-openssl-3.0.x"]
}
datasource db {

View file

@ -1,11 +1,16 @@
import { createClient } from 'redis';
const client = await createClient({
url: process.env.REDIS_URL || 'redis://localhost:6379'
url: process.env.REDIS_URL || 'redis://redis-server:6379'
});
client.on('error', (err) => console.error('Redis Error:', err));
await client.connect();
try {
await client.connect();
} catch (error) {
console.error('Redis Error:', error);
}
export default client;