Skip to content

Commit

Permalink
chore: use docker compose to run cypress. (#27831)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhenkes authored Sep 19, 2023
1 parent dc282cd commit 343097b
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 10 deletions.
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
"processId": "${command:PickProcess}",
"continueOnAttach": true
},
{
"type": "node",
"request": "attach",
"name": "Attach to port 5566",
"port": 5566,
"continueOnAttach": true,
},
{
"type": "node",
"request": "attach",
"name": "Attach to Docker",
"port": 5566,
"continueOnAttach": true,
"remoteRoot": "/opt/cypress",
},
{
"type": "node",
"request": "attach",
Expand Down
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,20 @@ $ yarn add https://cdn.cypress.io/beta/npm/.../cypress.tgz

Note that unzipping the Linux binary inside a Docker container onto a mapped volume drive is *slow*. But once this is done you can modify the application resource folder in the local folder `/tmp/test-folder/node_modules/cypress/cypress-cache/3.3.0/Cypress/resources/app` to debug issues.

#### Docker as a performance constrained environment

Sometimes performance issues are easier to reproduce in performance constrained environments. A docker container can be a good way to simulate this locally and allow for quick iteration.

In a fresh cypress repository run the following command:

```shell
docker compose run --service-port dev
```

This will spin up a docker container based off cypress/browsers:latest and start up the bash terminal. From here you can yarn install and develop as normal, although slower. It's recommend that you run this in a fresh repo because node modules may differ between an install on your local device and from within a linux docker image.

Ports 5566 and 5567 are available to attach debuggers to, please note that docker compose run only maps ports if the `--service-port` command is used.

### Packages

Generally when making contributions, you are typically making them to a small number of packages. Most of your local development work will be inside a single package at a time.
Expand Down
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: '3'

services:
dev:
image: cypress/browsers:latest
ports:
# Share debugging ports
- 5566:5566
- 5567:5567
environment:
# Use Hist file from shared volume
HISTFILE: /root/hist/.bash_history
# Setup inspect to use the more permissive address when debugging so
# that we can connect to it from ouside the docker container
CYPRESS_DOCKER_DEV_INSPECT_OVERRIDE: '0.0.0.0:5566'
# This disables CI mode which causes cypress to build differently
CI: ''
command: /bin/bash
working_dir: /opt/cypress
volumes:
# Copy Cypress source to docker container
- .:/opt/cypress
- bash-history:/root/hist
watch:
image: cypress/browsers:latest
environment:
# This disables CI mode which causes cypress to build differently
CI: ''
command: yarn watch
working_dir: /opt/cypress
volumes:
# Copy Cypress source to docker container
- .:/opt/cypress
ci:
# This should mirror the image used in workflows.yml
image: cypress/browsers-internal:node18.15.0-chrome114-ff115
ports:
- 5566:5566
- 5567:5567
command: /bin/bash
environment:
HISTFILE: /root/hist/.bash_history
CYPRESS_DOCKER_DEV_INSPECT_OVERRIDE: '0.0.0.0:5566'
working_dir: /opt/cypress
volumes:
- .:/opt/cypress
- bash-history:/root/hist

# persist terminal history between runs in a virtual volume
volumes:
bash-history:
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"gulp:debug": "node --inspect-brk ./node_modules/.bin/gulp",
"dev-debug": "node ./scripts/debug.js dev",
"docker": "./scripts/run-docker-local.sh",
"docker-dev": "./scripts/run-docker-local.sh dev",
"ensure-deps": "./scripts/ensure-dependencies.sh",
"get-next-version": "node scripts/get-next-version.js",
"postinstall": "node ./scripts/run-postInstall.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/electron/lib/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ module.exports = {
const opts = minimist(argv)

if (opts.inspectBrk) {
argv.unshift('--inspect-brk=5566')
if (process.env.CYPRESS_DOCKER_DEV_INSPECT_OVERRIDE) {
argv.unshift(`--inspect-brk=${process.env.CYPRESS_DOCKER_DEV_INSPECT_OVERRIDE}`)
} else {
argv.unshift('--inspect-brk=5566')
}
}
}

Expand Down
14 changes: 5 additions & 9 deletions scripts/run-docker-local.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
#!/bin/bash
SERVICE=${1:-ci}

set e+x

echo "This script should be run from cypress's root"

name=cypress/browsers-internal:node18.15.0-chrome114-ff115
echo "Pulling CI container $name"

docker pull $name
docker compose build ${SERVICE}

echo "Starting Docker image with cypress volume attached"
echo "Starting Docker compose service, $SERVICE, with cypress volume attached"
echo "You should be able to edit files locally"
echo "but execute the code in the container"

docker run -v $PWD:/home/person/cypress \
-w /home/person/cypress${WORKING_DIR:-} \
-it $name \
/bin/bash
docker compose run --service-ports ${SERVICE}

4 comments on commit 343097b

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 343097b Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.3.0/darwin-arm64/develop-343097b9d2453762ebbf9e9f2a0171225e62e60b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 343097b Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.3.0/linux-x64/develop-343097b9d2453762ebbf9e9f2a0171225e62e60b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 343097b Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.3.0/darwin-x64/develop-343097b9d2453762ebbf9e9f2a0171225e62e60b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 343097b Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.3.0/win32-x64/develop-343097b9d2453762ebbf9e9f2a0171225e62e60b/cypress.tgz

Please sign in to comment.