Skip to content

Commit 75e9033

Browse files
committed
use pnpm cache store to speed docker builds
1 parent a3547cb commit 75e9033

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

docker/production/Dockerfile

+13-12
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ FROM node:20-alpine AS base
44

55
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
66
RUN apk add --no-cache libc6-compat
7-
RUN corepack enable && corepack prepare [email protected] --activate
8-
# set the store dir to a folder that is not in the project
9-
RUN pnpm config set store-dir ~/.pnpm-store
10-
RUN pnpm fetch
7+
RUN corepack enable && corepack prepare [email protected] --activate
118

129
# 1. Install all dependencies including dev dependencies
1310
FROM base AS dev
@@ -17,16 +14,25 @@ USER node
1714
# WORKDIR now sets correct permissions if you set USER first so `USER node` has permissions on `/app` directory
1815
WORKDIR /app
1916

17+
# set the store dir to a folder that is not in the project
18+
RUN pnpm config set store-dir ~/.pnpm-store
19+
2020
# Install dependencies based on the preferred package manager
21-
COPY --chown=node:node package.json pnpm-lock.yaml* ./
21+
COPY --chown=node:node package.json pnpm-lock.yaml ./
22+
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm fetch
2223
COPY --chown=node:node . .
2324

2425
ENV NODE_ENV development
2526
ENV NEXT_TELEMETRY_DISABLED 1
2627

28+
# Copied from https://stackoverflow.com/a/69867550/6141587
2729
USER root
28-
RUN pnpm install --frozen-lockfile --prefer-offline
29-
RUN pnpm install [email protected]
30+
# Give /data directory correct permissions otherwise WAL mode won't work. It means you can't have 2 users writing to the database at the same time without this line as *.sqlite-wal & *.sqlite-shm are automatically created & deleted when *.sqlite is busy.
31+
RUN mkdir -p /data && chown -R node:node /data
32+
33+
USER node
34+
RUN --mount=type=cache,id=pnpm,target=~/.pnpm-store pnpm install --frozen-lockfile --recursive --prefer-offline
35+
RUN pnpm install [email protected]
3036

3137
# 2. Rebuild the source code only when needed
3238
FROM base AS builder
@@ -42,11 +48,6 @@ COPY --chown=node:node . .
4248
# This will do the trick, use the corresponding env file for each environment.
4349
COPY --chown=node:node .env* ./
4450

45-
# Copied from https://stackoverflow.com/a/69867550/6141587
46-
USER root
47-
# Give /data directory correct permissions otherwise WAL mode won't work. It means you can't have 2 users writing to the database at the same time without this line as *.sqlite-wal & *.sqlite-shm are automatically created & deleted when *.sqlite is busy.
48-
RUN mkdir -p /data && chown -R node:node /data
49-
5051
# set to production otherwise it throws error ⚠ You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env
5152
ENV NODE_ENV production
5253
ENV NEXT_TELEMETRY_DISABLED 1

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
},
3434
"devDependencies": {
3535
"@types/better-sqlite3": "^7.6.9",
36-
"@types/node": "^20.11.26",
36+
"@types/node": "^20.11.27",
3737
"@types/react": "^18.2.65",
38-
"@types/react-dom": "^18.2.21",
38+
"@types/react-dom": "^18.2.22",
3939
"dotenv": "^16.4.5",
4040
"drizzle-kit": "^0.20.14",
4141
"knip": "^5.0.4",

pnpm-lock.yaml

+12-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)