Skip to content

Commit

Permalink
[chore][Docker]Update dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhhTien committed Feb 23, 2024
1 parent 5fd0f02 commit 11b9e10
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
56 changes: 32 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "efurniture-api",
"version": "0.0.1",
"description": "",
"description": "efurniture API",
"author": "Deco-Team",
"license": "UNLICENSED",
"scripts": {
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 11b9e10

Please sign in to comment.