Skip to content

Commit 9ad6c75

Browse files
author
Prakash Bhandari
committed
dockrizing the app
1 parent 9349ddc commit 9ad6c75

7 files changed

+75
-14
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
README.md
2+
*Dockerfile*
3+
*docker-compose*
4+
node_modules
5+
.idea

.env.example

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
NODE_ENV = development
2-
PORT = 8000
2+
PORT = 3000
3+
EXTERNAL_PORT = 8000
34

45
# DATABASE
56
DB_TYPE = mysql
6-
DB_HOST = 127.0.0.1
7+
DB_HOST = db
78
DB_PORT = 3306
8-
DB_USER = root
9-
DB_PASSWORD = root
10-
DB_NAME = test_db
9+
DB_EXTERNAL_PORT = 33006
10+
DB_USER = dbuser
11+
DB_PASSWORD = dbpassword
12+
DB_ROOT_PASSWORD = root
13+
DB_NAME = app_db
1114

1215
#JWT
1316
SECRET_TOKEN = SECRET_TOKEN
1417

1518
#SES
16-
AWS_REGION =
17-
AWS_SES_SECRET_ACCESS_KEY =
18-
AWS_SES_ACCESS_KEY_ID =
19-
FROM_EMIAL =
19+
AWS_REGION = us-est
20+
AWS_SES_SECRET_ACCESS_KEY = AWS_SES_SECRET_ACCESS_KEY
21+
AWS_SES_ACCESS_KEY_ID = AWS_SES_ACCESS_KEY_ID
22+
FROM_EMIAL = FROM_EMIAL
2023

2124

2225
WEB_APP_BASE_URL = http://localhost:3001

docker-compose.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '3.8'
2+
3+
services:
4+
db:
5+
image: mysql:8.0
6+
env_file: ./.env
7+
environment:
8+
- MYSQL_DATABASE=${DB_NAME}
9+
- MYSQL_USER=${DB_USER}
10+
- MYSQL_PASSWORD=${DB_PASSWORD}
11+
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD}
12+
command: >
13+
mysqld --default-authentication-plugin=mysql_native_password
14+
--character-set-server=utf8mb4
15+
--collation-server=utf8mb4_unicode_ci
16+
restart: always
17+
healthcheck:
18+
test: ["CMD-SHELL", "mysqladmin ping -h localhost -u$DB_USER -p$MYSQL_ROOT_PASSWORD"]
19+
interval: 10s
20+
timeout: 20s
21+
retries: 6
22+
ports:
23+
- "${DB_EXTERNAL_PORT}:${DB_PORT}"
24+
volumes:
25+
- db_data:/var/lib/mysql
26+
27+
app:
28+
depends_on:
29+
- db
30+
build: .
31+
restart: unless-stopped
32+
env_file: ./.env
33+
ports:
34+
- "${EXTERNAL_PORT}:${PORT}"
35+
stdin_open: true
36+
tty: true
37+
volumes:
38+
- app_data:/app
39+
40+
volumes:
41+
db_data:
42+
app_data:

dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM node:20
2+
3+
WORKDIR /app
4+
COPY package.json .
5+
RUN npm install
6+
COPY . .
7+
RUN npm run predev
8+
RUN npm run prebuild
9+
RUN npm run build
10+
EXPOSE 8000
11+
CMD npm start

src/entities/user.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { Entity, Column, PrimaryGeneratedColumn, OneToMany } from "typeorm";
33
import { UserI } from "./user.interface";
44

5-
@Entity("users_1")
5+
@Entity("users")
66
export class User implements UserI {
77
@PrimaryGeneratedColumn("increment")
88
id: number;

src/migrations/1707005739450-create_users.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MigrationInterface, QueryRunner } from "typeorm";
33
export class CreateUsers1707005739450 implements MigrationInterface {
44
public async up(queryRunner: QueryRunner): Promise<void> {
55
await queryRunner.query(`
6-
CREATE TABLE users_1 (
6+
CREATE TABLE users (
77
id INT PRIMARY KEY AUTO_INCREMENT,
88
firstName VARCHAR(50) NOT NULL,
99
lastName VARCHAR(50) NOT NULL,
@@ -20,6 +20,6 @@ export class CreateUsers1707005739450 implements MigrationInterface {
2020
}
2121

2222
public async down(queryRunner: QueryRunner): Promise<void> {
23-
await queryRunner.query(`DROP TABLE IF EXISTS users_1`);
23+
await queryRunner.query(`DROP TABLE IF EXISTS users`);
2424
}
2525
}

src/migrations/1707006229778-add_verified_at.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { MigrationInterface, QueryRunner } from "typeorm";
22

33
export class AddVerifiedAt1707006229778 implements MigrationInterface {
44
public async up(queryRunner: QueryRunner): Promise<void> {
5-
await queryRunner.query(`ALTER TABLE users_1
5+
await queryRunner.query(`ALTER TABLE users
66
ADD COLUMN verifiedAt TIMESTAMP NULL AFTER active;
77
`);
88
}
99

1010
public async down(queryRunner: QueryRunner): Promise<void> {
11-
await queryRunner.query(`ALTER TABLE users_1 DROP COLUMN verifiedAt`);
11+
await queryRunner.query(`ALTER TABLE users DROP COLUMN verifiedAt`);
1212
}
1313
}

0 commit comments

Comments
 (0)