Skip to content

Commit f718194

Browse files
committed
add docker
1 parent 3dfbc11 commit f718194

File tree

10 files changed

+82
-47
lines changed

10 files changed

+82
-47
lines changed

server/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,7 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131-
coffeenearyou-firebase.json
131+
coffeenearyou-firebase.json
132+
pgadmin
133+
redis
134+
bot_db

server/Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN npm install --legacy-peer-deps
1212

1313
# Set Env
1414
ENV NODE_ENV development
15-
EXPOSE 3000
15+
EXPOSE 8080
1616

1717
# Cmd script
1818
CMD ["npm", "run", "dev"]

server/docker-compose.yml

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,69 @@
1-
version: "3.9"
1+
version: '3.8'
22

33
services:
4-
proxy:
5-
container_name: proxy
6-
image: nginx:alpine
7-
ports:
8-
- "80:80"
9-
volumes:
10-
- ./nginx.conf:/etc/nginx/nginx.conf
11-
restart: "unless-stopped"
12-
networks:
13-
- backend
4+
server:
5+
container_name: server
6+
build:
7+
context: ./
8+
dockerfile: Dockerfile.dev
9+
ports:
10+
- '8080:8080'
11+
volumes:
12+
- ./:/app
13+
- /app/node_modules
14+
restart: 'unless-stopped'
15+
networks:
16+
- backend
1417

15-
server:
16-
container_name: server
17-
build:
18-
context: ./
19-
dockerfile: Dockerfile.dev
20-
ports:
21-
- "3000:3000"
22-
volumes:
23-
- ./:/app
24-
- /app/node_modules
25-
restart: 'unless-stopped'
26-
networks:
27-
- backend
18+
db:
19+
container_name: dialogue-bot-db
20+
image: postgres:latest
21+
ports:
22+
- '5432:5432'
23+
environment:
24+
POSTGRES_PASSWORD: 'postgres'
25+
POSTGRES_DB: 'dialoguebot'
26+
volumes:
27+
[
28+
{
29+
type: 'volume',
30+
source: 'bot_db',
31+
target: '/var/lib/postgresql/data',
32+
},
33+
]
34+
restart: 'unless-stopped'
35+
networks:
36+
- backend
37+
38+
pgadmin:
39+
container_name: pgadmin
40+
image: dpage/pgadmin4
41+
ports:
42+
- '5050:80'
43+
environment:
44+
PGADMIN_DEFAULT_EMAIL: '[email protected]'
45+
PGADMIN_DEFAULT_PASSWORD: 'admin'
46+
restart: 'unless-stopped'
47+
networks:
48+
- backend
49+
volumes:
50+
[{ type: 'volume', source: 'pgadmin', target: '/var/lib/pgadmin' }]
51+
52+
redis:
53+
container_name: redis
54+
image: redis:alpine
55+
ports:
56+
- '6379:6379'
57+
restart: 'unless-stopped'
58+
networks:
59+
- backend
60+
volumes: [{ type: 'volume', source: 'redis', target: '/data' }]
2861

2962
networks:
30-
backend:
31-
driver: bridge
63+
backend:
64+
driver: bridge
3265

3366
volumes:
34-
data:
35-
driver: local
67+
bot_db:
68+
pgadmin:
69+
redis:

server/drizzle.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export default {
55
out: './src/database/migrations',
66
driver: 'pg',
77
dbCredentials: {
8-
connectionString:
9-
'postgres://postgres:postgres@localhost:5432/server_bot',
8+
connectionString: process.env.DATABASE_URL as string,
109
},
1110
} satisfies Config;

server/nodemon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"watch": ["src", ".env"],
2+
"watch": ["src", ".env.development.local"],
33
"ext": "js,ts,json",
44
"ignore": ["src/logs/*", "src/**/*.{spec,test}.ts"],
55
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts"

server/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"start": "npm run build && cross-env NODE_ENV=production concurrently \"npm run start:api\" \"npm run start:worker\" \"npm run typesafe-i18n\"",
1010
"start:api": "cross-env NODE_ENV=production node dist/server.js",
1111
"start:worker": "cross-env NODE_ENV=production node dist/worker.js",
12-
"dev:worker": "nodemon --watch src/worker.ts --exec \"ts-node -r tsconfig-paths/register --transpile-only src/worker.ts\"",
13-
"dev:api": "cross-env NODE_ENV=development nodemon",
12+
"dev:worker": "nodemon --legacy-watch src/worker.ts --exec \"ts-node -r tsconfig-paths/register --transpile-only src/worker.ts\"",
13+
"dev:api": "cross-env NODE_ENV=development nodemon --legacy-watch ",
1414
"build": "swc src -d dist --source-maps --copy-files",
1515
"build:tsc": "tsc && tsc-alias",
1616
"test": "jest --forceExit --detectOpenHandles",
@@ -25,7 +25,7 @@
2525
"db:studio": "drizzle-kit studio --port 5050",
2626
"db:seed": "ts-node -r tsconfig-paths/register --transpile-only src/database/seed.ts",
2727
"typesafe-i18n": "typesafe-i18n",
28-
"debug": "cross-env NODE_ENV=development nodemon --exec \"node --inspect=0.0.0.0:9229 --require ts-node/register -r tsconfig-paths/register src/server.ts\""
28+
"debug": "cross-env NODE_ENV=development DATABASE_URL=postgres://postgres:postgres@localhost:5432/dialoguebot REDIS_HOST=localhost nodemon --exec \"node --inspect=0.0.0.0:9229 --require ts-node/register -r tsconfig-paths/register src/server.ts\""
2929
},
3030
"dependencies": {
3131
"@paralleldrive/cuid2": "^2.2.2",

server/src/database/db.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { drizzle } from 'drizzle-orm/node-postgres';
2-
import { Pool } from 'pg';
1+
import { DATABASE_URL } from '@/config';
2+
import { logger } from '@/utils/logger';
33
import type { LogWriter } from 'drizzle-orm/logger';
44
import { DefaultLogger } from 'drizzle-orm/logger';
5-
import { logger } from '@/utils/logger';
5+
import { drizzle } from 'drizzle-orm/node-postgres';
6+
import { Pool } from 'pg';
67
import * as schema from './schema';
78

89
class Logger implements LogWriter {
@@ -12,8 +13,7 @@ class Logger implements LogWriter {
1213
}
1314

1415
export const client = new Pool({
15-
connectionString:
16-
'postgres://postgres:postgres@localhost:5432/coffeenearyou',
16+
connectionString: DATABASE_URL,
1717
});
1818

1919
export const db = drizzle(client, {

server/src/dtos/auth.dto.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH } from '@/constants';
2+
import { getCurrentLocale } from '@/i18n/get-current';
13
import {
24
IsEmail,
35
IsNotEmpty,
@@ -6,8 +8,6 @@ import {
68
MaxLength,
79
MinLength,
810
} from 'class-validator';
9-
import { MAX_PASSWORD_LENGTH, MIN_PASSWORD_LENGTH } from '@/constants';
10-
import { getCurrentLocale } from '@/i18n/get-current';
1111

1212
export class LoginDto {
1313
@IsEmail(

server/src/i18n/get-preferred-locale.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { Request } from 'express';
2-
import { Locales } from './i18n-types';
32
import {
43
initAcceptLanguageHeaderDetector,
5-
initRequestParametersDetector,
64
initRequestCookiesDetector,
7-
initQueryStringDetector,
85
} from 'typesafe-i18n/detectors';
6+
import { Locales } from './i18n-types';
97
import { detectLocale } from './i18n-util';
108

119
export const getPreferredLocale = (req: Request): Locales => {
@@ -16,6 +14,7 @@ export const getPreferredLocale = (req: Request): Locales => {
1614
{ headers },
1715
'lang'
1816
);
17+
1918
const requestCookiesDetector = initRequestCookiesDetector(req, 'lang');
2019

2120
return detectLocale(acceptLanguageDetector, requestCookiesDetector);

server/src/libs/redis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Redis } from 'ioredis';
21
import { REDIS_HOST, REDIS_PORT } from '@/config';
2+
import { Redis } from 'ioredis';
33

44
export const redis = new Redis({
55
host: REDIS_HOST,

0 commit comments

Comments
 (0)