Skip to content

Commit

Permalink
slimmed down docker container (#356)
Browse files Browse the repository at this point in the history
- use intern container to run webpack + ts build and then copy over the build results to final container
- moved some build deps over to devDeps to slim down runtime deps in final container
- added build + dep folders to docker ignore  (only matters for building locally, but asserts that only the built files are used in the container)
  • Loading branch information
nexus-uw committed Jun 20, 2024
1 parent b672ceb commit 7ae76f8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist
.github
.vscode
client/build
client/node_modules
service/dist
service/node_modules
17 changes: 14 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:lts-alpine
FROM node:lts-alpine as BUILD

WORKDIR /chat-e2ee
# todo break apart client and server dep installs/builds so that they can be cached b/w builds
Expand All @@ -10,10 +10,21 @@ RUN npm run build

# todo - multi part build (lets us slim down container to not unclude all the webpack stuff)

RUN rm .env.sample
FROM node:lts-alpine

WORKDIR /chat-e2ee
COPY package*.json /chat-e2ee/
RUN mkdir -p /chat-e2ee/client/build
COPY --from=BUILD /chat-e2ee/dist /chat-e2ee/dist
COPY --from=BUILD /chat-e2ee/client/build /chat-e2ee/client/build

# dont install dev deps
ENV NODE_ENV "production"
# dont run scripts to avoid pulling all client build deps + stuff
RUN npm ci --ignore-scripts=true --omit dev

EXPOSE 3001
USER node
#Set production mode deployment
ENV NODE_ENV "production"

ENTRYPOINT [ "npm", "run", "docker_start" ]
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
"form-data": "^3.0.0",
"mongodb": "^4.17.0",
"node-fetch": "^2.6.7",
"react-bootstrap": "^1.5.2",
"socket.io": "^4.5.4",
"ts-node": "^10.9.1",
"typescript": "5.0.4",
"socket.io": "^4.5.4",
"uuid": "^8.2.0"
},
"devDependencies": {
"react-bootstrap": "^1.5.2",
"ts-node": "^10.9.1",
"typescript": "5.0.4",
"@commitlint/cli": "^17.3.0",
"@commitlint/config-conventional": "^17.3.0",
"@types/cors": "^2.8.12",
Expand Down

0 comments on commit 7ae76f8

Please sign in to comment.