Skip to content

Commit

Permalink
[docker]: Optimized Dockerfile and updated .dockerignore (#1544)
Browse files Browse the repository at this point in the history
* [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
ongsuwannoo committed Nov 26, 2023
1 parent 30db3d7 commit b9d31d7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.vscode
.github
node_modules
npm-debug.log
.env
.git
.gitignore
.node-version
.prettierrc
Expand All @@ -10,3 +12,5 @@ config.json
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Procfile
Dockerfile
.dockerignore
30 changes: 19 additions & 11 deletions Dockerfile
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" ]

0 comments on commit b9d31d7

Please sign in to comment.