Skip to content

Commit

Permalink
add: create Dockerfile and .dockerignore for containerization
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingadonis committed Jan 8, 2025
1 parent a81ad48 commit cdc95dc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Folders

coverage/
dist/
node_modules/
out/
test/

# Files

.dockerignore
.editorconfig
.env
.gitignore
.lintstagedrc
.prettierrc
commitlint.config.js
Dockerfile
eslint.config.mjs
nest-cli.json
\*.md
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM node:20.17.0-alpine AS base
RUN addgroup -S backend && \
adduser -S backend -G backend

#--------------------------------------------------

FROM base AS base-dev
RUN npm install -g --ignore-scripts pnpm

#--------------------------------------------------

FROM base-dev AS build
WORKDIR /app
COPY package.json pnpm-lock.yaml tsconfig.json tsconfig.build.json ./
RUN pnpm install --frozen-lockfile --ignore-scripts
COPY ./src ./src
RUN pnpm run build --webpack

#--------------------------------------------------

FROM base-dev AS production-dev
ARG NODE_ENV=production
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --frozen-lockfile --prod --ignore-scripts && \
pnpm cache delete

#--------------------------------------------------

FROM base AS production
ARG NODE_ENV=production
WORKDIR /app
COPY --from=production-dev /app/node_modules ./node_modules
COPY --from=build /app/dist ./
COPY package.json ./
USER backend
ENTRYPOINT ["node", "main.js"]
EXPOSE 3000

0 comments on commit cdc95dc

Please sign in to comment.