Skip to content

Commit

Permalink
chore: rework Dockerfile
Browse files Browse the repository at this point in the history
Made the Dockerfile production ready. Multiple build steps.

Saved 126.1MB.
  • Loading branch information
Nidrux committed Jan 2, 2024
1 parent e5b9d6a commit f6be226
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ node_modules
npm-debug.log
README.md
.git
.env
.env
docker-compose.yaml
dist
25 changes: 18 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
FROM node:18-alpine
WORKDIR /

FROM node:18-slim AS base
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
#Hook into pnpm without installing pnpm. (magic) (https://nodejs.org/docs/latest-v18.x/api/corepack.html)
RUN corepack enable
WORKDIR /usr/src/app
COPY package*.json pnpm-lock.yaml* ./
RUN npm i -g pnpm

RUN pnpm install
#Create node_modules files without dev dependencies.
FROM base AS prod_dependencies
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

#Generate the dist directory.
FROM base AS builder
COPY . .

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN pnpm run build

CMD pnpm run start
#Final image
FROM base
WORKDIR /usr/src/app
COPY --from=prod_dependencies /usr/src/app/node_modules ./node_modules
COPY --from=builder /usr/src/app/dist ./dist
CMD [ "pnpm", "run", "start" ]
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
"prom-client": "^15.0.0",
"quickchart-js": "^3.1.3",
"topgg-autoposter": "^2.0.1",
"uuid": "^9.0.0"
"uuid": "^9.0.0",
"tslib": "^2.6.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/uuid": "^9.0.5",
"copyfiles": "^2.4.1",
"nodemon": "3.0.1",
"prettier": "^3.1.0",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
}
}
7 changes: 4 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f6be226

Please sign in to comment.