From 11b9e105a7aa92c1fa7ea72214524e707039b38b Mon Sep 17 00:00:00 2001 From: MinhhTien <92145479+MinhhTien@users.noreply.github.com> Date: Sat, 24 Feb 2024 00:18:27 +0700 Subject: [PATCH] [chore][Docker]Update dockerfile --- Dockerfile | 56 ++++++++++++++++++++++++++++++---------------------- package.json | 12 +++++------ 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3cc8079..cc73d61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,36 +1,44 @@ -## Build image -FROM node:20-alpine -WORKDIR /src +################### +# BUILD FOR LOCAL DEVELOPMENT +################### +FROM node:20-alpine AS development -COPY package*.json ./ -COPY .npmrc ./ -RUN npm install -RUN rm -rf .npmrc +WORKDIR /app -COPY . . -RUN npm run build +COPY --chown=node:node package*.json ./ + +RUN npm ci + +COPY --chown=node:node . . +USER node -## Target image -FROM node:20-alpine -WORKDIR /home/nonroot +################### +# BUILD FOR PRODUCTION +################### +FROM node:20-alpine AS build +WORKDIR /app +COPY --chown=node:node package*.json ./ -COPY package*.json ./ -COPY .npmrc ./ -RUN npm install -RUN rm -rf .npmrc +COPY --chown=node:node --from=development /app/node_modules ./node_modules + +COPY --chown=node:node . . + +RUN npm run build -COPY --from=0 /src/dist ./dist +RUN npm ci --only=production && npm cache clean --force -ENV PORT=5000 -EXPOSE ${PORT} +USER node -RUN addgroup nonroot -RUN adduser --disabled-password --gecos "" --ingroup nonroot nonroot -RUN chown -R nonroot:nonroot /home/nonroot +################### +# RUN PRODUCTION +################### +FROM node:20-alpine AS production -USER nonroot +COPY --chown=node:node --from=build /app/node_modules ./node_modules +COPY --chown=node:node --from=build /app/dist ./dist +COPY --chown=node:node --from=build /app/.env ./.env -CMD ["npm", "run", "start:prod"] +CMD ["node", "dist/main.js"] diff --git a/package.json b/package.json index 9d1c504..1250fbe 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "efurniture-api", "version": "0.0.1", - "description": "", + "description": "efurniture API", "author": "Deco-Team", "license": "UNLICENSED", "scripts": { @@ -27,6 +27,8 @@ "@nestjs/mongoose": "^10.0.2", "@nestjs/platform-express": "^10.0.0", "@nestjs/swagger": "^7.2.0", + "@nestjs/jwt": "^10.2.0", + "@nestjs/passport": "^10.0.3", "axios": "^1.6.5", "bcrypt": "^5.1.1", "class-transformer": "^0.5.1", @@ -44,12 +46,12 @@ "nodemailer": "^6.9.9", "passport-custom": "^1.1.1", "reflect-metadata": "^0.1.14", - "rxjs": "^7.8.1" + "rxjs": "^7.8.1", + "passport": "^0.7.0", + "passport-jwt": "^4.0.1" }, "devDependencies": { "@nestjs/cli": "^10.0.0", - "@nestjs/jwt": "^10.2.0", - "@nestjs/passport": "^10.0.3", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.0.0", "@types/bcrypt": "^5.0.2", @@ -67,8 +69,6 @@ "eslint-config-prettier": "^8.8.0", "eslint-plugin-prettier": "^4.2.1", "jest": "^29.5.0", - "passport": "^0.7.0", - "passport-jwt": "^4.0.1", "prettier": "^2.8.8", "source-map-support": "^0.5.21", "supertest": "^6.3.3",