-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docker]: Optimized Dockerfile and updated .dockerignore (#1544)
* [docker]: Optimized Dockerfile and updated .dockerignore * [build]: Updated prod script in package.json * [build]: Changed CMD to ENTRYPOINT in Dockerfile * [prod]: Updated base image in Dockerfile for prod * [build]: Removed node_modules and installed production dependencies in Dockerfile
- Loading branch information
1 parent
30db3d7
commit b9d31d7
Showing
2 changed files
with
23 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
FROM node:16.14 | ||
ARG NODE_VERSION=18.18.2-slim | ||
FROM node:${NODE_VERSION} as base | ||
|
||
ENV USER=evobot | ||
|
||
# install python and make | ||
RUN apt-get update && \ | ||
apt-get install -y python3 build-essential && \ | ||
apt-get purge -y --auto-remove | ||
apt-get install -y --no-install-recommends python3 build-essential && \ | ||
apt-get purge -y --auto-remove && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
# create evobot user | ||
RUN groupadd -r ${USER} && \ | ||
useradd --create-home --home /home/evobot -r -g ${USER} ${USER} | ||
useradd --create-home --home /home/evobot -r -g ${USER} ${USER} | ||
|
||
# set up volume and user | ||
USER ${USER} | ||
WORKDIR /home/evobot | ||
|
||
COPY --chown=${USER}:${USER} package*.json ./ | ||
RUN npm install | ||
VOLUME [ "/home/evobot" ] | ||
FROM base as build | ||
|
||
COPY --chown=${USER}:${USER} . . | ||
RUN npm ci | ||
RUN npm run build | ||
|
||
RUN rm -rf node_modules && \ | ||
npm ci --omit=dev | ||
|
||
FROM node:${NODE_VERSION} as prod | ||
|
||
COPY --chown=${USER}:${USER} package*.json ./ | ||
COPY --from=build --chown=${USER}:${USER} /home/evobot/node_modules ./node_modules | ||
COPY --from=build --chown=${USER}:${USER} /home/evobot/dist ./dist | ||
|
||
ENTRYPOINT [ "npm", "run", "prod" ] | ||
CMD [ "node", "./dist/index.js" ] |