nodejs / nodejs/corepack

Offline workflow does not work

Open
#448 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.8k
Forks
279
Avg merge
1h 47m
Merged PRs (30d)
2

Description

According to the docs there is supposed to be an offline workflow where corepack doesn't need internet:

Or you're publishing your project to a system where the network is unavailable, in which case you'll preemptively generate a package manager archive from your local computer (using corepack pack -o) before storing it somewhere your container will be able to access (for example within your repository). After that it'll just be a matter of running corepack install -g --cache-only <path/to/corepack.tgz> to setup the cache.

I've created an example project to reproduce the bug with the following Dockerfile:

FROM node:20-slim AS build
WORKDIR /app

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"

COPY . .

RUN --mount=type=cache,id=corepack,target=/app/cache \
		ls -la /app/cache

RUN --mount=type=cache,id=corepack,target=/app/cache \
    if [ ! -f "/app/cache/corepack.tgz" ]; then \
		corepack pnpm --version; \
		mkdir -p /app/cache; \
    corepack pack -o /app/cache/corepack.tgz; \
    fi

RUN --mount=type=cache,id=corepack,target=/app/cache \
    COREPACK_ENABLE_NETWORK=0 corepack install -g --cache-only /app/cache/corepack.tgz

#RUN COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm --version

RUN \
	--mount=type=cache,id=pnpm,target=/pnpm/store \
	COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm install --frozen-lockfile --prefer-offline

EXPOSE 80

CMD ["node", "./src/index.js"]
  1. The Dockerfile is supposed to download pnpm using corepack and then cache it using corepack pack.

  2. Then it tries to install it from the cache

  3. At last I try to run a pnpm command through corepack with COREPACK_ENABLE_NETWORK=0 to simulate no internet. This does not work. Neither corepack pnpm install nor corepack pnpm --version.

Error log

docker build -f ./Dockerfile -t corepack-offline-bug . --progress plain:

#0 building with "orbstack" instance using docker driver

#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 900B done
#1 DONE 0.0s

#2 [internal] load metadata for docker.io/library/node:20-slim
#2 DONE 0.0s

#3 [internal] load .dockerignore
#3 transferring context: 90B done
#3 DONE 0.0s

#4 [build 1/7] FROM docker.io/library/node:20-slim
#4 DONE 0.0s

#5 [internal] load build context
#5 transferring context: 93.25kB 0.0s done
#5 DONE 0.0s

#6 [build 2/7] WORKDIR /app
#6 CACHED

#7 [build 3/7] COPY . .
#7 DONE 0.0s

#8 [build 4/7] RUN --mount=type=cache,id=corepack,target=/app/cache             ls -la /app/cache
#8 0.049 total 3784
#8 0.049 drwxr-xr-x 1 root root      24 Apr  4 14:17 .
#8 0.049 drwxr-xr-x 1 root root      10 Apr  4 14:29 ..
#8 0.049 -rw-r--r-- 1 root root 3873301 Apr  4 14:17 corepack.tgz
#8 DONE 0.1s

#9 [build 5/7] RUN --mount=type=cache,id=corepack,target=/app/cache     if [ ! -f "/app/cache/corepack.tgz" ]; then             corepack pnpm --version;                mkdir -p /app/cache;     corepack pack -o /app/cache/corepack.tgz;     fi
#9 DONE 0.1s

#10 [build 6/7] RUN --mount=type=cache,id=corepack,target=/app/cache     COREPACK_ENABLE_NETWORK=0 corepack install -g --cache-only /app/cache/corepack.tgz
#10 0.328 Adding pnpm@8.15.6 to the cache...
#10 DONE 0.6s

#11 [build 7/7] RUN     --mount=type=cache,id=pnpm,target=/pnpm/store   COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm install --frozen-lockfile --prefer-offline
#11 0.136 Usage Error: Network access disabled by the environment; can't reach npm repository https://registry.npmjs.org
#11 0.136
#11 0.136 $ pnpm ...
#11 ERROR: process "/bin/sh -c COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm install --frozen-lockfile --prefer-offline" did not complete successfully: exit code: 1
------
 > [build 7/7] RUN      --mount=type=cache,id=pnpm,target=/pnpm/store   COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm install --frozen-lockfile --prefer-offline:
0.136 Usage Error: Network access disabled by the environment; can't reach npm repository https://registry.npmjs.org
0.136
0.136 $ pnpm ...
------
Dockerfile:24
--------------------
  23 |
  24 | >>> RUN \
  25 | >>>      --mount=type=cache,id=pnpm,target=/pnpm/store \
  26 | >>>      COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm install --frozen-lockfile --prefer-offline
  27 |
--------------------
ERROR: failed to solve: process "/bin/sh -c COREPACK_ENABLE_STRICT=0 COREPACK_ENABLE_NETWORK=0 corepack pnpm install --frozen-lockfile --prefer-offline" did not complete successfully: exit code: 1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the offline workflow described in the README and reproduce the failure using the reported Dockerfile, especially the corepack install -g --cache-only and network-disabled corepack pnpm commands. Done means the final pnpm command works without network access after installing the generated cache archive.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, dockerfile, typescript
Domain
cli, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.