From 999c72688116fad5a0e911f92cca41a6202fee60 Mon Sep 17 00:00:00 2001 From: ZigBalthazar Date: Fri, 13 Dec 2024 17:41:52 +0330 Subject: [PATCH] feat: add docker file --- Dockerfile | 41 +++++++++++++++++++++++++++++++++++++++++ nest-cli.json | 6 ++++-- package.json | 3 ++- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a9622b0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Stage 1: Build Stage +FROM node:18-alpine AS build + +# Set the working directory in the container +WORKDIR /app + +# Copy package.json and yarn.lock to the container +COPY package.json yarn.lock ./ + +# Install project dependencies +RUN yarn install --frozen-lockfile + +# Copy the rest of the application code to the container +COPY . . + +# Build the Nest.js application +RUN NODE_OPTIONS=--max-old-space-size=8192 yarn build + +# Stage 2: Production Stage +FROM node:18-alpine AS production + +# Set the working directory in the container +WORKDIR /app + +# Copy only the necessary files from the build stage +COPY --from=build /app/dist ./dist +COPY package.json yarn.lock ./ + +# Install only production dependencies +RUN yarn install --frozen-lockfile --production + +# Expose the ports that the Nest.js app will run on +EXPOSE 3000 +EXPOSE 50051 + +# Start the Nest.js application +CMD ["yarn", "start:prod"] + +# Healthcheck to check the application's health on port 5000 +HEALTHCHECK --interval=30s --timeout=10s \ + CMD curl -f http://localhost:3000/health || exit 1 diff --git a/nest-cli.json b/nest-cli.json index 09d4f27..b621f0b 100644 --- a/nest-cli.json +++ b/nest-cli.json @@ -7,6 +7,8 @@ "@nestjs/swagger/plugin" ], "assets": [ - ] + { "include": "**/*.proto", "outDir": "./dist/src/", "watchAssets": true } + ], + "watchAssets": true } -} \ No newline at end of file +} diff --git a/package.json b/package.json index 83b0449..3c91106 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,10 @@ "author": "zigBalthazar ", "license": "MIT", "scripts": { + "build": "nest build", "build:prod": "tsc -p tsconfig.build.json", "start:dev": "ts-node src/main.ts", - "start:prod": "node dist/main.js", + "start:prod": "node dist/src/main.js", "new": "hygen new", "watch:dev": "ts-node-dev src/main.ts", "debug:dev": "cross-env TS_NODE_CACHE=false ts-node-dev --inspect --ignore '/^src/.*\\.spec\\.ts$/' src/main.ts",