Skip to content

Commit f62d507

Browse files
committed
fix dockerfile
1 parent a860b9e commit f62d507

File tree

7 files changed

+61
-43
lines changed

7 files changed

+61
-43
lines changed

Dockerfile

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
FROM node:18-alpine AS dependences
2-
WORKDIR /app
3-
4-
COPY package.json yarn.lock ./
5-
RUN yarn install --production --frozen-lockfile
1+
# Use the official Node.js image as the base image
2+
FROM node:18-alpine
63

7-
FROM node:18-alpine AS builder
4+
# Set the working directory inside the container
85
WORKDIR /app
96

10-
COPY package.json yarn.lock ./
11-
RUN yarn --frozen-lockfile
12-
13-
COPY . .
7+
# Copy package.json and package-lock.json to the working directory
8+
COPY package*.json ./
149

15-
RUN yarn build
10+
# Install dependencies
11+
RUN npm install
1612

17-
FROM node:18-alpine AS runner
18-
WORKDIR /app
19-
20-
ARG NODE_ENV=production
21-
ENV NODE_ENV=${NODE_ENV}
13+
# Copy the rest of the application code to the working directory
14+
COPY . .
2215

23-
COPY --from=dependences /app/node_modules ./node_modules
24-
COPY --from=builder /app/dist ./dist
16+
# Build the NestJS application
17+
RUN npm run build
2518

19+
# Expose the port your NestJS application listens on
2620
EXPOSE 8080
2721

28-
CMD ["node", "dist/main"]
22+
# Define the command to run your NestJS application
23+
CMD ["node", "--max-old-space-size=4096", "dist/main.js"]

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ Nest is [MIT licensed](LICENSE).
7474

7575
## Prisma Initialize
7676
- This project source use prisma as ORM, so to start prisma use this command: `yarn prisma init`
77+
78+
## Run docker with .env file
79+
-`docker run -d --name nestjs-backend --env-file .env -p 8080:8080 gateway-server`

docker-compose.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
version: "23.0.5"
2-
services:
3-
dev-db:
4-
image: postgres:13
1+
version: "3.8"
2+
services:
3+
backend:
4+
container_name: graphql-server
5+
mem_limit: 2g
6+
restart: always
7+
build:
8+
dockerfile: Dockerfile
59
ports:
6-
# map the contianer port: 5432 to localhost port 5430
7-
- 5430:5432
10+
- "8080:8080"
811
environment:
9-
POSTGRES_USER: root
10-
POSTGRES_PASSWORD: dtth2802
11-
POSTGRES_DB: nest
12-
networks:
13-
- postgres-network
14-
test-db:
15-
image: postgres:13
16-
ports:
17-
# map the contianer port: 5432 to localhost port 5430
18-
- 5433:5435
19-
environment:
20-
POSTGRES_USER: root
21-
POSTGRES_PASSWORD: dtth2802
22-
POSTGRES_DB: nest
23-
networks:
24-
- postgres-network
12+
- DB_HOST=localhost
13+
- DB_PORT=3306
14+
- DB_USER=thuhuong
15+
- DB_PASSWORD=thuhuong0208
16+
- DB_NAME=gatewaydb  
17+
2518
networks:
26-
postgres-network:
19+
mysql-network:
20+
driver: bridge
21+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE `user` ADD COLUMN `hub_license_key` VARCHAR(100) NULL;

prisma/schema.prisma

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ model user {
1919
username String? @unique @db.VarChar(100)
2020
password String? @db.VarChar(100)
2121
22+
hub_license_key String? @db.VarChar(100)
2223
token_cache_login String? @db.VarChar(100)
2324
session session[]
2425
device device[]

src/modules/user/user.resolver.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Resolver, Query } from "@nestjs/graphql";
1+
import { Resolver, Query, Args } from "@nestjs/graphql";
22
import { UseGuards } from "@nestjs/common";
33

44
import { UserService } from "./user.service";
@@ -16,4 +16,10 @@ export class UserResolver {
1616
const user = this.userService.findOne(Number(session.session.userId));
1717
return user;
1818
}
19+
20+
@Query(() => User)
21+
userByLicense(@Args("license") license: string) {
22+
const user = this.userService.findUserByLicense(license);
23+
return user;
24+
}
1925
}

src/modules/user/user.service.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,20 @@ export class UserService {
3939
throw error;
4040
}
4141
}
42+
43+
async findUserByLicense(license: string) {
44+
try {
45+
const user = await this.prisma.user.findFirst({
46+
where: {
47+
hub_license_key: license
48+
}
49+
});
50+
if (!user) {
51+
throw new NotFoundException("User not found");
52+
}
53+
return user;
54+
} catch (error) {
55+
throw error;
56+
}
57+
}
4258
}

0 commit comments

Comments
 (0)