Skip to content

Commit

Permalink
chore: Update Dockerfile to improve build process and optimize image …
Browse files Browse the repository at this point in the history
…size
  • Loading branch information
guilhermeais committed Jun 15, 2024
1 parent f61d51d commit b4332e5
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,56 @@
# 🧑‍💻 Development
#
FROM node:20-alpine as dev
RUN apk add --no-cache libc6-compat
WORKDIR /app

ENV NODE_ENV development

RUN deluser --remove-home node && \
addgroup --system --gid 1001 node && \
adduser --system --uid 1001 node
RUN deluser --remove-home node
RUN addgroup --system --gid 1001 node
RUN adduser --system --uid 1001 node

RUN apk add --no-cache libc6-compat python3 py3-pip build-base pkgconfig python3-dev gcc musl-dev linux-headers && \
pip3 install --no-cache-dir --break-system-packages joblib scikit-learn pandas numpy matplotlib seaborn plotly scipy psutil

ENV JOBLIB_START_METHOD=forkserver
COPY --chown=node:node . .

COPY --chown=node:node package*.json ./
RUN npm ci
COPY --chown=node:node . .

USER node

#
# 🏡 Production Build
#
FROM dev as build
ENV JOBLIB_START_METHOD=forkserver
FROM node:20-alpine as build

WORKDIR /app
RUN apk add --no-cache libc6-compat
ENV NODE_ENV production

RUN deluser --remove-home node
RUN addgroup --system --gid 1001 node
RUN adduser --system --uid 1001 node

COPY --chown=node:node --from=dev /app/node_modules ./node_modules
COPY --chown=node:node . .
RUN mkdir dist
RUN chown -R node:node dist
RUN npm run build && npm ci --omit=dev && npm cache clean --force

RUN npm run build

RUN npm ci --omit=dev && npm cache clean --force

USER node

#
# 🚀 Production Server
#
FROM node:20-alpine as prod

WORKDIR /app
RUN apk add --no-cache libc6-compat

ENV NODE_ENV production
ENV JOBLIB_START_METHOD=forkserver

RUN deluser --remove-home node && \
addgroup --system --gid 1001 node && \
adduser --system --uid 1001 node && \
apk add --no-cache libc6-compat

RUN apk add --no-cache libc6-compat python3 py3-pip build-base pkgconfig python3-dev gcc musl-dev linux-headers && \
pip3 install --no-cache-dir --break-system-packages joblib scikit-learn pandas numpy matplotlib seaborn plotly scipy psutil
RUN deluser --remove-home node
RUN addgroup --system --gid 1001 node
RUN adduser --system --uid 1001 node

COPY --chown=node:node --from=build /app/dist dist
COPY --chown=node:node --from=build /app/node_modules node_modules
Expand Down

0 comments on commit b4332e5

Please sign in to comment.