New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(api): Optimize dockerfile - WIP #5454
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
FROM node:20-alpine3.19 as dev_base | ||
RUN apk add g++ make py3-pip | ||
|
||
ENV NX_DAEMON=false | ||
ENV NX_DAEMON=false \ | ||
NODE_ENV=production | ||
|
||
RUN npm i pm2 -g | ||
RUN npm --no-update-notifier --no-fund --global install [email protected] | ||
RUN pnpm --version | ||
|
||
USER 1000 | ||
WORKDIR /usr/src/app | ||
|
@@ -14,9 +13,7 @@ WORKDIR /usr/src/app | |
FROM dev_base AS dev | ||
ARG PACKAGE_PATH | ||
|
||
COPY --chown=1000:1000 ./meta . | ||
COPY --chown=1000:1000 ./deps . | ||
COPY --chown=1000:1000 ./pkg . | ||
COPY --chown=1000:1000 ./meta ./deps ./pkg ./ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's interim stage, I think we don't have to unite these layers because we won't use dev, it's important to decrease dev_base and prod. Docker caches each line in the Dockerfile, and that the output of one line is the input of the next. So if a line generates new output all subsequent caches are invalidated. In this case we lost an opportunity to use cache even if only last folder will be changed we copy all of them. |
||
|
||
RUN --mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 export BULL_MQ_PRO_NPM_TOKEN=$(cat /run/secrets/BULL_MQ_PRO_NPM_TOKEN) && \ | ||
if [ -n "${BULL_MQ_PRO_NPM_TOKEN}" ] ; then echo 'Building with Enterprise Edition of Novu'; rm -f .npmrc ; cp .npmrc-cloud .npmrc ; fi | ||
|
@@ -31,10 +28,9 @@ RUN --mount=type=secret,id=BULL_MQ_PRO_NPM_TOKEN,uid=1000 export BULL_MQ_PRO_NPM | |
|
||
WORKDIR /usr/src/app/apps/api | ||
|
||
RUN cp src/.example.env dist/src/.env | ||
RUN cp src/.env.test dist/src/.env.test | ||
RUN cp src/.env.development dist/src/.env.development | ||
RUN cp src/.env.production dist/src/.env.production | ||
RUN <<EOF | ||
cp src/.env.production dist/src/.env.production | ||
EOF | ||
|
||
WORKDIR /usr/src/app | ||
|
||
|
@@ -51,7 +47,9 @@ FROM dev_base AS prod | |
|
||
ARG PACKAGE_PATH | ||
|
||
ENV CI=true | ||
ENV CI=true \ | ||
NODE_ENV=production \ | ||
NEW_RELIC_NO_CONFIG_FILE=true | ||
|
||
WORKDIR /usr/src/app | ||
|
||
|
@@ -66,7 +64,5 @@ RUN --mount=type=cache,id=pnpm-store-api,target=/root/.pnpm-store\ | |
--frozen-lockfile \ | ||
--unsafe-perm | ||
|
||
ENV NEW_RELIC_NO_CONFIG_FILE=true | ||
|
||
WORKDIR /usr/src/app/apps/api | ||
CMD [ "pm2-runtime","start", "dist/main.js" ] | ||
CMD [ "dump-init", "node", "dist/main.js" ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this one be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I followed some best practices and found out about https://github.com/Yelp/dumb-init. Maybe we need it, maybe not. We will review it as soon as this is more testable. Note that my goal is to remove PM2. I don't think it adds value at this point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can exclude cache because we use dev_base in the final step
RUN apk add --no-cache g++ make py3-pip