-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mircea Matei
committed
Oct 16, 2023
1 parent
81c1d52
commit 12acf0d
Showing
5 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
npm-debug.log | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
################### | ||
# BUILD FOR LOCAL DEVELOPMENT | ||
################### | ||
|
||
FROM node:18-alpine As development | ||
|
||
# Create app directory | ||
WORKDIR /usr/src/app | ||
|
||
# Copy application dependency manifests to the container image. | ||
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available). | ||
# Copying this first prevents re-running npm install on every code change. | ||
COPY --chown=node:node package*.json ./ | ||
|
||
# Install app dependencies using the `npm ci` command instead of `npm install` | ||
RUN npm ci | ||
|
||
# Bundle app source | ||
COPY --chown=node:node . . | ||
|
||
# Use the node user from the image (instead of the root user) | ||
USER node | ||
|
||
################### | ||
# BUILD FOR PRODUCTION | ||
################### | ||
|
||
FROM node:18-alpine As build | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY --chown=node:node package*.json ./ | ||
|
||
# In order to run `npm run build` we need access to the Nest CLI which is a dev dependency. In the previous development stage we ran `npm ci` which installed all dependencies, so we can copy over the node_modules directory from the development image | ||
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules | ||
|
||
COPY --chown=node:node . . | ||
|
||
# Run the build command which creates the production bundle | ||
RUN npm run build | ||
|
||
# Set NODE_ENV environment variable | ||
ENV NODE_ENV production | ||
|
||
# Running `npm ci` removes the existing node_modules directory and passing in --only=production ensures that only the production dependencies are installed. This ensures that the node_modules directory is as optimized as possible | ||
RUN npm ci --only=production && npm cache clean --force | ||
|
||
USER node | ||
|
||
################### | ||
# PRODUCTION | ||
################### | ||
|
||
FROM node:18-alpine As production | ||
|
||
# Copy the bundled code from the build stage to the production image | ||
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules | ||
COPY --chown=node:node --from=build /usr/src/app/dist ./dist | ||
|
||
# Start the server using the production build | ||
CMD [ "node", "dist/main.js" ] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
FROM node:alpine AS development | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
COPY . . | ||
|
||
RUN npm run build | ||
|
||
FROM node:alpine AS prodcution | ||
|
||
ARG NODE_ENV=prodcution | ||
ENV NODE_ENV=${NODE_ENV} | ||
|
||
WORKDIR /app | ||
|
||
COPY package*.json ./ | ||
|
||
RUN npm install --omit=dev | ||
|
||
COPY . . | ||
|
||
COPY --from=development /app/dist ./dist | ||
|
||
CMD npm run start:prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters