Skip to content

Commit

Permalink
🐋 refactor: Reduce Dockerfile.multi container size (#5066)
Browse files Browse the repository at this point in the history
* fix: Reduce Dockerfile.multi container size

Reduced container size from 1.46 GB to 1.12 GB.

* Use `npm ci` without devDependencies for final image
* Remove unneeded `npm prune commands`

* Update Dockerfile.multi

---------

Co-authored-by: Danny Avila <[email protected]>
  • Loading branch information
alex-torregrosa and danny-avila authored Dec 23, 2024
1 parent dfe5498 commit 04923dd
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Dockerfile.multi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# v0.7.6

# Base for all builds
FROM node:20-alpine AS base
FROM node:20-alpine AS base-min
WORKDIR /app
RUN apk --no-cache add curl
RUN npm config set fetch-retry-maxtimeout 600000 && \
Expand All @@ -13,22 +13,24 @@ COPY packages/data-provider/package*.json ./packages/data-provider/
COPY packages/mcp/package*.json ./packages/mcp/
COPY client/package*.json ./client/
COPY api/package*.json ./api/

# Install all dependencies for every build
FROM base-min AS base
WORKDIR /app
RUN npm ci

# Build data-provider
FROM base AS data-provider-build
WORKDIR /app/packages/data-provider
COPY packages/data-provider ./
RUN npm run build
RUN npm prune --production

# Build mcp package
FROM base AS mcp-build
WORKDIR /app/packages/mcp
COPY packages/mcp ./
COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
RUN npm run build
RUN npm prune --production

# Client build
FROM base AS client-build
Expand All @@ -37,18 +39,18 @@ COPY client ./
COPY --from=data-provider-build /app/packages/data-provider/dist /app/packages/data-provider/dist
ENV NODE_OPTIONS="--max-old-space-size=2048"
RUN npm run build
RUN npm prune --production

# API setup (including client dist)
FROM base AS api-build
FROM base-min AS api-build
WORKDIR /app
# Install only production deps
RUN npm ci --omit=dev
COPY api ./api
COPY config ./config
COPY --from=data-provider-build /app/packages/data-provider/dist ./packages/data-provider/dist
COPY --from=mcp-build /app/packages/mcp/dist ./packages/mcp/dist
COPY --from=client-build /app/client/dist ./client/dist
WORKDIR /app/api
RUN npm prune --production
EXPOSE 3080
ENV HOST=0.0.0.0
CMD ["node", "server/index.js"]
CMD ["node", "server/index.js"]

0 comments on commit 04923dd

Please sign in to comment.