Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use offline workflow #414

Open
denchernov opened this issue Feb 29, 2024 · 3 comments
Open

Unable to use offline workflow #414

denchernov opened this issue Feb 29, 2024 · 3 comments

Comments

@denchernov
Copy link

denchernov commented Feb 29, 2024

I'm trying to install yarn@4.0.2 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 yarn@4.0.2
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 yarn@4.0.2 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 yarn@4.0.2 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 yarn@4.0.2
 ---> Running in 59afd3f52227
Installing yarn@4.0.2...
 ---> 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?

@aduh95
Copy link
Contributor

aduh95 commented Feb 29, 2024

Can you try using corepack yarn everywhere you call yarn directly, and report if that changes the output/result?

@denchernov
Copy link
Author

I tried to applied your suggestion:
RUN corepack pack
RUN corepack install -g yarn@4.0.2
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"?

@dtom90
Copy link

dtom90 commented May 6, 2024

I was able to solve this with the following:

# Cache yarn locally to avoid lookup at runtime
RUN corepack pack yarn@4.1.1
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:

corepack/tests/main.test.ts

Lines 507 to 510 in 6efa349

// Make COREPACK_HOME ro
const home = npath.toPortablePath(folderUtils.getCorepackHomeFolder());
await xfs.chmodPromise(ppath.join(home, `lastKnownGood.json`), 0o444);
await xfs.chmodPromise(home, 0o555);

Would be nice if this was documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants