Skip to content

Commit

Permalink
feat: add docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Dec 13, 2024
1 parent 6d6eb06 commit 999c726
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"@nestjs/swagger/plugin"
],
"assets": [
]
{ "include": "**/*.proto", "outDir": "./dist/src/", "watchAssets": true }
],
"watchAssets": true
}
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"author": "zigBalthazar <[email protected]>",
"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",
Expand Down

0 comments on commit 999c726

Please sign in to comment.