Skip to content

Commit

Permalink
Dockerfile build fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
coredumped7893 committed May 9, 2024
1 parent 3c71fab commit 0ef30ea
Show file tree
Hide file tree
Showing 2 changed files with 4,029 additions and 3,150 deletions.
22 changes: 10 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ 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 ./
COPY --chown=node:node package.json ./
COPY --chown=node:node pnpm-lock.yaml ./

RUN npm install -g pnpm@8
RUN npm install -g pnpm@9

# Install app dependencies using the `npm ci` command instead of `npm install`
RUN pnpm i
RUN pnpm install express
RUN pnpm i --frozen-lockfile

# Bundle app source
COPY --chown=node:node . .
Expand All @@ -32,24 +32,22 @@ FROM node:18-alpine As build

WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./
COPY --chown=node:node package.json ./
COPY --chown=node:node pnpm-lock.yaml ./

# 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 --from=development /usr/src/app/node_modules node_modules

COPY --chown=node:node . .

RUN npm install -g pnpm@8
RUN npm install -g pnpm@9

# Run the build command which creates the production bundle
RUN pnpm 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 pnpm i --only=production && pnpm store prune
RUN pnpm i express
RUN pnpm prune --prod
RUN pnpm i --frozen-lockfile --prod && pnpm store prune

USER node

Expand Down
Loading

0 comments on commit 0ef30ea

Please sign in to comment.