Skip to content

Commit

Permalink
Merge pull request #6 from nokibul/feat/kubernetes
Browse files Browse the repository at this point in the history
Feat/kubernetes
  • Loading branch information
nokibul committed Mar 30, 2024
2 parents 06da5d6 + 2c46181 commit 3b5a6dd
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DATABASE_URL="postgresql://postgres:nokib@localhost:5432/postgres"
DATABASE_URL="postgres://postgres:nokib@postgres-deployment:5432/postgres?schema=public"
MAILDEV_INCOMING_USER="nokibnur@gmail.com"
MAILDEV_INCOMING_PASS="Oh9AY7wCfM56U2Hj"
NODE_ENV=development
9 changes: 4 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --save-dev @nestjs/cli

RUN npm install -g pnpm

RUN pnpm install

RUN npx prisma generate

COPY . .

RUN npx prisma generate

EXPOSE 3000

CMD ["npm", "start"]
# Command to migrate the database and start the server
CMD ["npm", "run", "start:migrate"]
12 changes: 6 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ services:
context: .
dockerfile: Dockerfile
ports:
- "3000:3000"
- '3000:3000'
environment:
NODE_ENV: development
DATABASE_URL: postgresql://postgres:nokib@localhost:5432/postgres
DATABASE_URL: postgresql://postgres:nokib@database:5432/postgres?schema=public
volumes:
- './src:/usr/src/app/src'
depends_on:
- database

database:
image: postgres:latest
image: postgres:16
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: nokib
POSTGRES_DB: postgres
ports:
- "5432:5432"
volumes:
- "C:/Program Files/PostgreSQL/15/data:/var/lib/postgresql/data"
- '5432:5432'
29 changes: 29 additions & 0 deletions kubernetes/npest-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: npest-deployment
labels:
app: npest
spec:
selector:
matchLabels:
app: npest
replicas: 1
template:
metadata:
labels:
app: npest
spec:
containers:
- name: npest-application
image: nokibnur/npest-app:1.0.3
ports:
- containerPort: 3000
# hostPort: 80
resources:
limits:
cpu: "1"
memory: "1Gi"
requests:
cpu: "0.5"
memory: "500Mi"
17 changes: 17 additions & 0 deletions kubernetes/npest-nodeport.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: npest
labels:
app: npest
spec:
selector:
app: npest
ports:
- protocol: TCP
port: 3000
targetPort: 3000
nodePort: 30000
type: NodePort
externalIPs:
- 172.19.0.3
11 changes: 11 additions & 0 deletions kubernetes/npest-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: postgres-deployment
spec:
selector:
app: postgres-deployment
ports:
- protocol: TCP
port: 5432
targetPort: 5432
34 changes: 34 additions & 0 deletions kubernetes/postgres-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: postgres-deployment
spec:
replicas: 1
selector:
matchLabels:
app: postgres-deployment
template:
metadata:
labels:
app: postgres-deployment
spec:
containers:
- name: database
image: postgres:16
ports:
- containerPort: 5432
env:
- name: POSTGRES_USER
value: postgres
- name: POSTGRES_PASSWORD
value: nokib
- name: POSTGRES_DB
value: postgres
resources:
limits:
cpu: "1"
memory: "1Gi"
requests:
cpu: "0.5"
memory: "500Mi"

118 changes: 118 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"start:migrate": "prisma migrate dev && npm run start:debug",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
Expand All @@ -38,6 +39,7 @@
"nest-winston": "^1.9.4",
"nestjs-prisma": "^0.22.0",
"nodemailer": "^6.9.8",
"nodemon": "^3.1.0",
"passport": "^0.7.0",
"passport-local": "^1.0.0",
"prisma-zod-generator": "^0.8.13",
Expand Down
2 changes: 1 addition & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
return 'newi i hi sdf sadf dsdude i!';
}
sayCheese(): string {
return 'Cheese!';
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ async function bootstrap() {
// app.useGlobalFilters(new DatabaseExceptionFilter());
app.useGlobalFilters(new HttpExceptionFilter());

await app.listen(3000);
await app.listen(3000, '0.0.0.0');
}
bootstrap();
1 change: 1 addition & 0 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class AuthenticationService {

return user;
} catch (error) {
console.error(error);
throw error;
}
}
Expand Down

0 comments on commit 3b5a6dd

Please sign in to comment.