🐋 ci: create smaller Docker images (#2691)

- create fewer layers
- install only prod dependencies for final build
- clean npm cache
- fix layering in multi-image build
This commit is contained in:
Christian Köberl 2024-05-13 16:47:18 +02:00 committed by GitHub
parent a0d1e2a5f8
commit 5920672a8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 25 deletions

View file

@ -1,10 +1,8 @@
# v0.7.2 # v0.7.2
# Base node image # Base node image
FROM node:18-alpine3.18 AS node FROM node:20-alpine AS node
RUN apk add g++ make py3-pip
RUN npm install -g node-gyp
RUN apk --no-cache add curl RUN apk --no-cache add curl
RUN mkdir -p /app && chown node:node /app RUN mkdir -p /app && chown node:node /app
@ -14,20 +12,20 @@ USER node
COPY --chown=node:node . . COPY --chown=node:node . .
# Allow mounting of these files, which have no default RUN \
# values. # Allow mounting of these files, which have no default
RUN touch .env touch .env ; \
RUN npm config set fetch-retry-maxtimeout 600000 # Create directories for the volumes to inherit the correct permissions
RUN npm config set fetch-retries 5 mkdir -p /app/client/public/images /app/api/logs ; \
RUN npm config set fetch-retry-mintimeout 15000 npm config set fetch-retry-maxtimeout 600000 ; \
RUN npm install --no-audit npm config set fetch-retries 5 ; \
npm config set fetch-retry-mintimeout 15000 ; \
npm install --no-audit; \
# React client build
NODE_OPTIONS="--max-old-space-size=2048" npm run frontend; \
npm prune --production; \
npm cache clean --force
# React client build
ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run frontend
# Create directories for the volumes to inherit
# the correct permissions
RUN mkdir -p /app/client/public/images /app/api/logs RUN mkdir -p /app/client/public/images /app/api/logs
# Node API setup # Node API setup

View file

@ -7,32 +7,31 @@ FROM node:20-alpine AS base
FROM base AS data-provider-build FROM base AS data-provider-build
WORKDIR /app/packages/data-provider WORKDIR /app/packages/data-provider
COPY ./packages/data-provider ./ COPY ./packages/data-provider ./
RUN npm install RUN npm install; npm cache clean --force
RUN npm run build RUN npm run build
RUN npm prune --production
# React client build # React client build
FROM data-provider-build AS client-build FROM base AS client-build
WORKDIR /app/client WORKDIR /app/client
COPY ./client/package*.json ./ COPY ./client/package*.json ./
# Copy data-provider to client's node_modules # Copy data-provider to client's node_modules
RUN mkdir -p /app/client/node_modules/librechat-data-provider/ COPY --from=data-provider-build /app/packages/data-provider/ /app/client/node_modules/librechat-data-provider/
RUN cp -R /app/packages/data-provider/* /app/client/node_modules/librechat-data-provider/ RUN npm install; npm cache clean --force
RUN npm install
COPY ./client/ ./ COPY ./client/ ./
ENV NODE_OPTIONS="--max-old-space-size=2048" ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run build RUN npm run build
# Node API setup # Node API setup
FROM data-provider-build AS api-build FROM base AS api-build
WORKDIR /app/api WORKDIR /app/api
COPY api/package*.json ./ COPY api/package*.json ./
COPY api/ ./ COPY api/ ./
# Copy helper scripts # Copy helper scripts
COPY config/ ./ COPY config/ ./
# Copy data-provider to API's node_modules # Copy data-provider to API's node_modules
RUN mkdir -p /app/api/node_modules/librechat-data-provider/ COPY --from=data-provider-build /app/packages/data-provider/ /app/api/node_modules/librechat-data-provider/
RUN cp -R /app/packages/data-provider/* /app/api/node_modules/librechat-data-provider/ RUN npm install --include prod; npm cache clean --force
RUN npm install
COPY --from=client-build /app/client/dist /app/client/dist COPY --from=client-build /app/client/dist /app/client/dist
EXPOSE 3080 EXPOSE 3080
ENV HOST=0.0.0.0 ENV HOST=0.0.0.0