cypress-docker-images icon indicating copy to clipboard operation
cypress-docker-images copied to clipboard

Docker image cypress/factory does not support Yarn 3

Open Joelasaur opened this issue 1 year ago • 6 comments

Current Behavior

Cypress factory fails to install Yarn 3.

+ curl -fsSLO --compressed https://yarnpkg.com/downloads/3.5.0/yarn-v3.5.0.tar.gz
curl: (22) The requested URL returned error: 404 
child process exited with code 22
The command '/bin/sh -c node /opt/installScripts/yarn/install-yarn-version.js ${YARN_VERSION}' returned a non-zero code: 22

Desired Behavior

We should be able to specify Yarn berry in the build args.

Test code to reproduce

Create a dockerfile like so

ARG CHROME_VERSION='107.0.5304.121-1'
ARG CYPRESS_VERSION='12.5.1'
ARG YARN_VERSION='3.5.0'

FROM cypress/factory

WORKDIR /app

COPY package.json ./
COPY .yarn/cache ./.yarn/cache
COPY .yarn/plugins ./.yarn/plugins
COPY .yarn/releases ./.yarn/releases
COPY .yarnrc.yml ./
COPY yarn.lock ./

RUN yarn install

Workaround

Current workaround is to specify Yarn 1 in the build arg, but then add a run step to set the version to Yarn 3 like so:

ARG CHROME_VERSION='107.0.5304.121-1'
ARG CYPRESS_VERSION='12.5.1'
ARG YARN_VERSION='1.22.19'

FROM cypress/factory

WORKDIR /app

COPY package.json ./
COPY .yarn/cache ./.yarn/cache
COPY .yarn/plugins ./.yarn/plugins
COPY .yarn/releases ./.yarn/releases
COPY .yarnrc.yml ./
COPY yarn.lock ./

# Upgrade to yarn 3 here:
RUN yarn set version berry
RUN yarn install

Joelasaur avatar Apr 19 '23 19:04 Joelasaur

We currently only support yarn v1 in the docker factory. I think we could update the install script to support higher versions of yarn.

mjhenkes avatar Apr 20 '23 13:04 mjhenkes

We currently only support yarn v1 in the docker factory. I think we could update the install script to support higher versions of yarn.

This would be awesome! And since we are talking about Yarn 3 support, figured I'd mention this other relevant issue here, since it most likely has to do with Cypress not finding Typescript in the cypress/factory image while using Yarn 3.

This is my .yarnrc.yaml file, which as you can see is using the nodeLinker: node-modules fix which is working on my local machine, just not in the cypress factory image:

enableScripts: true

nodeLinker: node-modules

npmScopes:
  updater:
    npmAlwaysAuth: true
    npmAuthToken: "${GH_REGISTRY_TOKEN}"
    npmRegistryServer: "https://npm.pkg.github.com"

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
    spec: "@yarnpkg/plugin-interactive-tools"

supportedArchitectures:
  cpu:
    - x64
    - arm64
  libc:
    - glibc
  os:
    - darwin
    - linux

yarnPath: .yarn/releases/yarn-3.5.0.cjs

edit (fixed)

ignore this comment, it wasn't an issue with Yarn 3, I was just building and running my images incorrectly

Joelasaur avatar Apr 20 '23 14:04 Joelasaur

We currently only support yarn v1 in the docker factory. I think we could update the install script to support higher versions of yarn.

Hey seems like the curl install script of Yarn might not support Yarn 2.x and 3.x. I found this thread regarding the same. I would like to discuss futher on handling Yarn installation on these version and hopefully to contribute on them

anishpb97 avatar Apr 23 '23 09:04 anishpb97

@mjhenkes can I work on this?

anishpb97 avatar Apr 28 '23 04:04 anishpb97

@anishpb97, Sure! (sorry for the delay)

mjhenkes avatar Jun 01 '23 14:06 mjhenkes

@Joelasaur

Yarn Modern recommends installing using corepack, however this technology is still experimental and not suitable for production use, according to the Node.js documentation for corepack.

The workaround you described to install Yarn Modern using Yarn v1 Classic is for the moment the way that Cypress Docker images can support with good conscience. This can change, if/when Yarn and Node.js are able to recommended corepack for production use.

References

  • https://yarnpkg.com/getting-started/install
  • https://yarnpkg.com/corepack
  • https://nodejs.org/docs/latest/api/corepack.html
  • https://nodejs.org/docs/latest/api/documentation.html#stability-index
  • https://github.com/nodejs/corepack

MikeMcC399 avatar May 25 '24 07:05 MikeMcC399