Comments (1)
@zkochan Should the --offline
in Dockerfile
be updated to --prefer-offline
at https://pnpm.io/cli/fetch because --offline
fails.
Also, this is in run.sh
of my Dockerfile
at the end & still downloads the dependencies each time:
run.sh
#!/bin/bash
set -e
# TODO: Only install dependencies for drizzle migration
echo "Installing production dependencies"
cd scripts
pnpm config set store-dir ~/.pnpm-store
pnpm fetch
pnpm install --prod --prefer-offline
cd ..
echo "Creating '/data/users.prod.sqlite' using bind volume mount"
pnpm run db:migrate:prod & PID=$!
# Wait for migration to finish
wait $PID
echo "Starting production server..."
node server.js & PID=$!
wait $PID
See this is the output. No reused deps:
Installing production dependencies
Importing packages to virtual store
Already up to date
Progress: resolved 1, reused 0, downloaded 0, added 0
Progress: resolved 42, reused 0, downloaded 14, added 11
Progress: resolved 42, reused 0, downloaded 40, added 40
Progress: resolved 42, reused 0, downloaded 42, added 42, done
.../node_modules/better-sqlite3 install$ prebuild-install || node-gyp rebuild --release
.../node_modules/better-sqlite3 install: Done
But there's some modules in here I guess:
/app $ du -sh ~/.pnpm-store/v3/
23.0M /home/node/.pnpm-store/v3/
Any ideas what's the problem?
Store doesn't work in Dockerfile
nor outside of it.
My current Dockerfile
& run.sh
(see above code-block) is a bit simplified.
Dockerfile
FROM node:20-alpine AS base
# mostly inspired from https://github.com/BretFisher/node-docker-good-defaults/blob/main/Dockerfile & https://github.com/remix-run/example-trellix/blob/main/Dockerfile
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare [email protected] --activate
# set the store dir to a folder that is not in the project
RUN pnpm config set store-dir ~/.pnpm-store
RUN pnpm fetch
# 1. Install all dependencies including dev dependencies
FROM base AS deps
# Root user is implicit so you don't have to actually specify it. From https://stackoverflow.com/a/45553149/6141587
# USER root
USER node
# WORKDIR now sets correct permissions if you set USER first so `USER node` has permissions on `/app` directory
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY --chown=node:node package.json pnpm-lock.yaml* ./
COPY --chown=node:node /src/app/db/migrations ./migrations
USER root
RUN pnpm install --frozen-lockfile --prefer-offline
# 2. Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps --chown=node:node /app/node_modules ./node_modules
COPY --chown=node:node . .
# This will do the trick, use the corresponding env file for each environment.
COPY --chown=node:node .env.production .env.production
# Copied from https://stackoverflow.com/a/69867550/6141587
USER root
# 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.
RUN mkdir -p /data && chown -R node:node /data
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
RUN pnpm build
# 3. Production image, copy all the files and run next
FROM base AS runner
USER node
WORKDIR /app
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME '0.0.0.0'
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
COPY --from=builder --chown=node:node /app/public ./public
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=node:node /app/.next/standalone ./
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
# Move the drizzle directory to the runtime image
COPY --from=builder --chown=node:node /app/src/app/db/migrations ./migrations
# Move the run script and litestream config to the runtime image
COPY --from=builder --chown=node:node /app/scripts/drizzle-migrate.mjs ./scripts/drizzle-migrate.mjs
COPY --from=builder --chown=node:node /app/scripts/package.json ./scripts/package.json
COPY --from=builder --chown=node:node /app/scripts/pnpm-lock.yaml ./scripts/pnpm-lock.yaml
COPY --from=builder --chown=node:node /app/scripts/run.sh ./run.sh
RUN chmod +x run.sh
CMD ["sh", "run.sh"]
from pnpm.
Related Issues (20)
- Getting `ERR_PNPM_HARDLINK_FAILED Error: EEXIST: file already exists, link` when pnpm install
- `pnpm list --recursive` should be sorted topologically
- `--ignore-engines` api in pnpm? HOT 2
- `pnpm upgrade --interactive --latest` breaks when using `.tgz` files as dependencies HOT 1
- The script written by node executes exec('pnpm update --latest \"@babel/*\"'), which does not take effect and does not report an error
- URL.canParse Error in Corepack Brew Formula with pnpm and use-node-version
- `pnpm licenses --json` in workspace package returns incorrect path
- How do I suppress this annoying "The modules directory ... will be removed and reinstalled from scratch..." question? HOT 5
- command `pnpm why` returns nothing HOT 2
- The requested module '/_nuxt/node_modules/.pnpm/@[email protected]/node_modules/@firebase/component/dist/index.cjs.js' does not provide an export named 'Component' (at index.esm2017.js:2:10) HOT 1
- `pnpm deploy` in a workspace creates `${deployDir}/node_modules/.modules.yaml` at the root of the workspace instead of under the requested deployment directory
- Please revert b970d96 HOT 3
- pnpm issues with corepack packageManager field
- Stuck after resolving packages
- With ignore-workspace-root-check set to true I am getting ERR_PNPM_ADDING_TO_ROOT HOT 2
- pnpm install --frozen-lockfile=false will not update the outdated packages HOT 6
- Cannot delete folder because esbuild.exe is locked HOT 1
- Cannot authenticate to private registry HOT 5
- `shamefully-hoist` Configuration Bug in pnpm HOT 4
- ffprobe Binary Lacks Execute Permissions When Installed in a Second Directory with pnpm
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pnpm.