wip: final docker compose
This commit is contained in:
parent
50f19e0d64
commit
caf6e771f8
5 changed files with 53 additions and 7 deletions
13
Dockerfile
Normal file
13
Dockerfile
Normal 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
|
|
@ -1,4 +1,19 @@
|
||||||
services:
|
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:
|
mongodb:
|
||||||
build: ./mongodb_rs
|
build: ./mongodb_rs
|
||||||
hostname: mongodb
|
hostname: mongodb
|
||||||
|
@ -15,11 +30,11 @@ services:
|
||||||
- mongo-data:/data/db/
|
- mongo-data:/data/db/
|
||||||
- mongo-logs:/var/log/mongodb/
|
- mongo-logs:/var/log/mongodb/
|
||||||
networks:
|
networks:
|
||||||
- mongodb_network
|
- app_network
|
||||||
|
|
||||||
redis:
|
redis:
|
||||||
image: redis:latest
|
image: redis:latest
|
||||||
hostname: redis
|
hostname: redis-server
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "6379:6379"
|
- "6379:6379"
|
||||||
|
@ -29,11 +44,11 @@ services:
|
||||||
volumes:
|
volumes:
|
||||||
- redis-data:/root/redis
|
- redis-data:/root/redis
|
||||||
networks:
|
networks:
|
||||||
- redis_network
|
- app_network
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
mongodb_network:
|
app_network:
|
||||||
redis_network:
|
driver: bridge
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
mongo-data:
|
mongo-data:
|
||||||
|
|
12
docker_entrypoint.sh
Normal file
12
docker_entrypoint.sh
Normal 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
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
generator client {
|
generator client {
|
||||||
provider = "prisma-client-js"
|
provider = "prisma-client-js"
|
||||||
|
binaryTargets = ["debian-openssl-1.1.x", "linux-musl-openssl-3.0.x"]
|
||||||
}
|
}
|
||||||
|
|
||||||
datasource db {
|
datasource db {
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
import { createClient } from 'redis';
|
import { createClient } from 'redis';
|
||||||
|
|
||||||
const client = await createClient({
|
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));
|
client.on('error', (err) => console.error('Redis Error:', err));
|
||||||
|
|
||||||
|
try {
|
||||||
await client.connect();
|
await client.connect();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Redis Error:', error);
|
||||||
|
}
|
||||||
|
|
||||||
export default client;
|
export default client;
|
||||||
|
|
Loading…
Add table
Reference in a new issue