Skip to content

Commit

Permalink
build: docker build improvements (#345)
Browse files Browse the repository at this point in the history
- rework redundant `npm ci` calls
- CYPRESS_INSTALL_BINARY=0 to skip downloading chromium

relates-to #319
  • Loading branch information
pmstss authored Jun 14, 2024
1 parent 649334a commit b802db3
Showing 1 changed file with 17 additions and 44 deletions.
61 changes: 17 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,38 @@
# BUILD FOR LOCAL DEVELOPMENT
###################

FROM node:14-alpine As development

WORKDIR /usr/src/app

COPY --chown=node:node package*.json ./
COPY --chown=node:node tsconfig.build.json ./
COPY --chown=node:node tsconfig.json ./
COPY --chown=node:node nest-cli.json ./
COPY --chown=node:node mikro-orm.config.ts ./
COPY --chown=node:node .env ./
COPY --chown=node:node config ./config
COPY --chown=node:node keycloak ./keycloak
COPY --chown=node:node client ./client
COPY --chown=node:node src ./src


RUN apk add --no-cache --virtual .gyp python3 py3-pip make g++

RUN npm ci
RUN npm ci --prefix=client --only=prod

RUN apk del .gyp

USER node

###################
# BUILD FOR PRODUCTION
###################

FROM node:14-alpine As build

WORKDIR /usr/src/app

RUN apk add --no-cache --virtual .gyp python3 py3-pip make g++

# Copy and build NestJS server project
COPY --chown=node:node package*.json ./
COPY --chown=node:node tsconfig.build.json ./
COPY --chown=node:node tsconfig.json ./
COPY --chown=node:node nest-cli.json ./
COPY --chown=node:node nest-cli.json ./
COPY --chown=node:node mikro-orm.config.ts ./
COPY --chown=node:node .env ./
COPY --chown=node:node config ./config
COPY --chown=node:node keycloak ./keycloak
COPY --chown=node:node client ./client
COPY --chown=node:node src ./src

COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules
COPY --chown=node:node --from=development /usr/src/app/client/node_modules ./client/node_modules

RUN apk add --no-cache --virtual .gyp python3 py3-pip make g++

# Install project dependencies before running build commands
RUN npm ci

RUN npm run build
# Build the client (React) project
RUN cd client && npm ci && npm run build
RUN npm prune --production

ENV NODE_ENV production
# Copy and build client project
COPY --chown=node:node client/package*.json ./client/
COPY --chown=node:node client/src ./client/src
COPY --chown=node:node client/public ./client/public
COPY --chown=node:node client/typings ./client/typings
COPY --chown=node:node client/vcs ./client/vcs
COPY --chown=node:node client/tsconfig.json ./client/tsconfig.json

RUN npm ci --only=production && npm cache clean --force
ENV CYPRESS_INSTALL_BINARY=0
RUN npm ci --prefix=client
RUN npm run build --prefix=client

RUN apk del .gyp

Expand All @@ -74,7 +47,7 @@ FROM node:14-alpine As production

WORKDIR /usr/src/app

COPY --chown=node:node nest-cli.json ./
COPY --chown=node:node nest-cli.json ./
COPY --chown=node:node mikro-orm.config.ts ./
COPY --chown=node:node .env ./
COPY --chown=node:node config ./config
Expand All @@ -87,4 +60,4 @@ COPY --chown=node:node --from=build /usr/src/app/dist ./dist
COPY --chown=node:node --from=build /usr/src/app/client/build ./client/build
COPY --chown=node:node --from=build /usr/src/app/client/vcs ./client/vcs

CMD ["npm", "run", "start:prod"]
CMD ["npm", "run", "start:prod"]

0 comments on commit b802db3

Please sign in to comment.