Skip to content

Commit

Permalink
Add redis config with container and update node.js and postgres version
Browse files Browse the repository at this point in the history
  • Loading branch information
timursevimli committed Jan 27, 2024
1 parent 936d34e commit e85f5af
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM node:16-alpine
FROM node:20-alpine
WORKDIR /usr/server
COPY . .
COPY package*.json .
RUN npm ci --only=production
COPY . .
EXPOSE 8000
EXPOSE 8001
EXPOSE 8002
Expand Down
6 changes: 6 additions & 0 deletions application/config/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
({
socket: {
host: process.env.REDIS_HOST || '127.0.0.1',
port: 6379,
},
});
4 changes: 2 additions & 2 deletions application/db/redis/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ async () => {
if (application.worker.id === 'W1') {
console.debug('Connect to redis');
}
const client = npm.redis.createClient();
const client = npm.redis.createClient(config.redis);
db.redis.client = client;
client.on('error', () => {
if (application.worker.id === 'W1') {
console.warn('No redis service detected, so quit client');
}
client.quit();
});
//await client.connect();
await client.connect();
};
11 changes: 10 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ services:
container_name: api-example
environment:
- DB_HOST=pg-example
- REDIS_HOST=redis-example
volumes:
- ./application:/usr/server/application
depends_on:
- pg-example
- redis-example
ports:
- 127.0.0.1:8000:8000
- 127.0.0.1:8001:8001
- 127.0.0.1:8002:8002
restart: always

pg-example:
image: postgres:14.1-alpine3.15
image: postgres:16.1-alpine3.19
container_name: pg-example
environment:
- POSTGRES_USER=marcus
Expand All @@ -33,6 +35,13 @@ services:
- 127.0.0.1:5432:5432
restart: always

redis-example:
image: redis:7-alpine
container_name: redis-example
ports:
- 127.0.0.1:6379:6379
restart: always

networks:
default:
name: api-example-network

0 comments on commit e85f5af

Please sign in to comment.