From b802db317ab6cff5f343e02e953f755a8d7c7cf0 Mon Sep 17 00:00:00 2001 From: Viachaslau Date: Fri, 14 Jun 2024 19:27:54 +0400 Subject: [PATCH] build: docker build improvements (#345) - rework redundant `npm ci` calls - CYPRESS_INSTALL_BINARY=0 to skip downloading chromium relates-to #319 --- Dockerfile | 61 +++++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 44 deletions(-) diff --git a/Dockerfile b/Dockerfile index b89d687d..0515081e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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 @@ -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"] \ No newline at end of file +CMD ["npm", "run", "start:prod"]