cypress-io / cypress-docker-images

Docker images with Cypress dependencies and browsers
https://on.cypress.io/continuous-integration
MIT License
1.02k stars 380 forks source link

docs: migrate examples to relative bind mounts #1091

Closed MikeMcC399 closed 4 months ago

MikeMcC399 commented 4 months ago

Issues

This issue concerns the syntax used in the included/README examples for Bind mounts of Cypress projects using the CLI option -v and the environment variable PWD (Print Working Directory), for example:

$ docker run -it -v $PWD:/e2e -w /e2e cypress/included:13.10.0

  1. If the path of the current working directory represented by PWD contains spaces, then the command fails with an error message:

    docker: invalid reference format
  2. If the syntax -v $PWD:/e2e is used on Windows PowerShell then the command fails with an error message:

    At line:1 char:21
    + $ docker run -it -v $PWD:/e2e -w /e2e cypress/included:13.10.0
    +                     ~~~~~
    Variable reference is not valid. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : InvalidVariableReferenceWithDrive

Relative paths

docker container run with alias docker run provides the option Mount volume (-v) with relative paths as described in the Docker documentation:

As of Docker Engine version 23, you can use relative paths on the host.

docker run -v ./content:/content -w /content -i -t ubuntu pwd

Relative paths can replace the use of the environment variable PWD. This avoids problems with PWD, enabling equivalent functionality and it simplifies the command line examples.

Change

Change all examples using docker run with mount volume -v using PWD to instead use the relative path ., so for example:

$ docker run -it -v $PWD:/e2e -w /e2e cypress/included:13.10.0

is changed to

$ docker run -it -v .:/e2e -w /e2e cypress/included:13.10.0

Verification

Ubuntu

On Ubuntu 22.04.4 LTS with Docker Desktop for Linux v4.30.0

mkdir "cy example"
cd "cy example"
git init
npm init -y
npm install cypress
npx cypress open
rm -rf node_modules package*.json
docker run -it -v .:/e2e -w /e2e cypress/included

Confirm that Cypress runs successfully.

Windows

On Windows 11 23H2 with Docker Desktop for Windows v4.30.0

Test as for Ubuntu (described above) using:

On Git Bash test with:

MSYS_NO_PATHCONV=1 docker run -it -v .:/e2e -w /e2e cypress/included
cypress-app-bot commented 4 months ago
MikeMcC399 commented 4 months ago
  1) Network Requests
       cy.request() - make an XHR request:

      AssertionError: expected 502 to be one of [ 500, 501 ]
      + expected - actual