Skip to content

Commit

Permalink
[OPTIMIZE] optimize docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml authored Oct 16, 2024
1 parent 11ede9e commit dd21f9b
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
FROM node:16-alpine AS build

FROM node:18.20.4-alpine as base

ARG PORT=3000

EXPOSE ${PORT}

WORKDIR /app

COPY package*.json ./
RUN npm install --legacy-peer-deps

COPY . .
FROM base as dependencies

COPY package-lock.json /app/

RUN echo "Installing dependencies" \
apk --update --no-cache add --virtual build-dependencies make g++ && \
npm install --silent --production

FROM dependencies as develop

ENV NODE_ENV=development

RUN npm install --silent

COPY ./ /app

RUN npm run build

FROM node:16-alpine
FROM base as release

WORKDIR /app
ENV NODE_ENV=production

COPY --from=dependencies /app/node_modules /app/node_modules
COPY --from=develop /app/build /app/build

RUN adduser -D -h /app -u 5000 user && \
chown -R user:user /app

COPY --from=build /app ./
USER user

EXPOSE 3000
ENTRYPOINT ["npm", "run"]

CMD ["npm", "start"]
CMD ["start"]

0 comments on commit dd21f9b

Please sign in to comment.