Unable to use offline workflow
I'm trying to install [email protected] for offline usage in a container.
Here is my dockerfile:
# escape=`
ARG PARENT_IMAGE
ARG SOLUTION_IMAGE
FROM ${SOLUTION_IMAGE} as solution
FROM ${PARENT_IMAGE} as dev
# ENV PORT=80
# WORKDIR /dev
# EXPOSE 80
FROM ${PARENT_IMAGE}
ENV PORT=3000
ENV PORT=3001
ENV PORT=3002
ENV PORT=3003
WORKDIR /app
#COPY --from=solution /artifacts/rendering/package.json /artifacts/rendering/yarn.lock ./
COPY --from=solution /artifacts/rendering ./
# Restore packages and build
USER ContainerAdministrator
ENV NODE_OPTIONS=--max-old-space-size=4096
# ENV NODE_EXTRA_CA_CERTS=c:/app/cert/registry.npmjs.com.pem
RUN node -v
# Install yarn
#RUN corepack enable
RUN corepack pack
ENV COREPACK_ENABLE_NETWORK=0
#RUN corepack yarn install -g --cache-only
RUN corepack install -g [email protected]
RUN yarn -v
RUN yarn config set nodeLinker node-modules
RUN yarn
USER ContainerUser
COPY --from=solution /artifacts/certs .certs/
EXPOSE 3000 3001 3002 3003
I do see that [email protected] is downloaded in placed in the image in corepack.tgz and yarn installation starts according to the logs, but yarn is still not available afterwards. Here are the logs:
...
Step 10/24 : WORKDIR /app
---> Running in b5c44753c1a3
---> Removed intermediate container b5c44753c1a3
---> 3378cd65d896
Step 11/24 : COPY --from=solution /artifacts/rendering ./
---> 6eea8ac43194
Step 12/24 : USER ContainerAdministrator
---> Running in 3743b806d379
---> Removed intermediate container 3743b806d379
---> 399fae2b0e4b
Step 13/24 : ENV NODE_OPTIONS=--max-old-space-size=4096
---> Running in d29ef210d6ac
---> Removed intermediate container d29ef210d6ac
---> ddf842ccf798
Step 14/24 : RUN node -v
---> Running in 141fab6a0229
v20.11.0
---> Removed intermediate container 141fab6a0229
---> 476bfcc7802e
Step 15/24 : RUN corepack pack
---> Running in d5793d9cf670
Adding [email protected] to the cache...
Packing the selected tools in corepack.tgz...
All done!
---> Removed intermediate container d5793d9cf670
---> eb77433b831e
Step 16/24 : ENV COREPACK_ENABLE_NETWORK=0
---> Running in 5a8667484609
---> Removed intermediate container 5a8667484609
---> 11b0bf50bca2
Step 17/24 : RUN corepack install -g [email protected]
---> Running in 59afd3f52227
Installing [email protected]...
---> Removed intermediate container 59afd3f52227
---> e5c340db2820
Step 18/24 : RUN yarn -v
---> Running in 657ad66767d8
'yarn' is not recognized as an internal or external command,
operable program or batch file.
The command 'cmd /S /C yarn -v' returned a non-zero code: 1
Am I doing anything wrong?
Can you try using corepack yarn everywhere you call yarn directly, and report if that changes the output/result?
I tried to applied your suggestion: RUN corepack pack RUN corepack install -g [email protected] RUN corepack yarn -v RUN corepack yarn config set nodeLinker node-modules RUN corepack yarn
It works on the image creation stage, but later, when AKS creates containers based on this image it fails with CrashLoopBackOff because it can't call a yarn command: 'yarn' is not recognized as an internal or external command
Do I need to specify a path to installed yarn? e.g.: RUN SETX /M PATH "%PATH%;C:\path\to\installed\yarn"?
I was able to solve this with the following:
# Cache yarn locally to avoid lookup at runtime
RUN corepack pack [email protected]
RUN carepack install -g --cache-only corepack.tgx
RUN chmod 444 /root/.cache/node/corepack/lastKnownGood.json
RUN chmod 555 /root/.cache/node/corepack
Took a lot of digging to find this in the unit tests: https://github.com/nodejs/corepack/blob/6efa34988229918debe6e881d45ba6715282f283/tests/main.test.ts#L507-L510
Would be nice if this was documented.