-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Run Cypress Headless Without Binary #1232
Comments
This is something we've internally talked a lot about and I have a lot of notes for. It is possible to do this - you wouldn't be able to run Electron, but you would be able to spawn an external browser. The problem comes in where you have conflicting packages. You'd likely check in For this to work I think we'd just need to set an env var like: EDIT: another advantage of this is that if we supported Chrome headless (which we will), this avoids the need to orchestrate or have |
any progress ? |
This would help putting cypress on aws lambda for amazingly quick parallel testing. |
@lgandecki been trying to get Cypress working on AWS Lambda for a day only to come across this GitHub issue! Anyone got an update? |
Also keen to run Cypress tests on AWS Lambda, although I don't see how installing the binary precludes the tests from running? |
I don't fully remember. I think the "headful" chrome makes it so the whole thing doesn't fit in the lambda limit of 50 mb? So you have to download and install chrome which makes it slow and expensive (long running?) |
FWIW you can skirt around the 50mb limit by uploading the Lambda package as a zip to S3 first: https://hackernoon.com/exploring-the-aws-lambda-deployment-limits-9a8384b0bec3 If that is the issue then my feeling is 250mb should be enough? But if it takes a while to boot up then yeah that is an issue. |
We are using puppeteer inside an AWS lambda and would like an equivalent cypress setup if someone has worked this out. |
I tried to manually do this, but your Linux Cypress package is around 499 megs and the AWS Lambda S3 limit is 250 megs. I'd prefer to use Cypress vs. Puppeteer for Lambda, is there a way to get a smaller Linux binary? |
I put the Linux version on S3, then copied and unzipped in the Lambda. It ran out of RAM. So I pumped the Lambda's RAM up to 3008 megs. It used 1908, but then ran out of hard drive space on the EC2 (Raspberry PI?) used for the Lambda. I TRIED lol |
It's possible to run Cypress in Lambda, look in this link: https://stuartsandine.com/cypress-on-aws-lambda-part-1/ There is a github repo too. |
While that post is technically interesting, the solution relies on Chromium 59 via Electron (if I'm reading it correctly). That's not super helpful if you want to test more recent features without using polyfills, such as ResizeObserver which landed in Chrome 64 in Jan. 2018. |
Hello, I am reviving this issue <3 Since the launch of cypress 3.8.0 we now have the ability to run I've been trying to run cypress in a lambda function, and I have a few questions, which I am hoping someone here could help me with At first I thought I would be clever, and check in my node_modules into source control, then bring this into a lambda and execute cypress from there, but it didn't work out that well because I got this output, which I didn't expect
The cypress binary was a curious one, and I started digging deeper from there I saw that Cypress saves this binary, in the user's cache directory - as below (taken from a ubuntu 18.04 virtualbox install) I then tried to bring Cypress into my lambda function via a lambda layer (https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) but I quickly ran into size issues
This got me onto looking at the size of Cypress, in it's entirety Below are the sizes of directories, in the home directory cache folder for Cypress, that are 1MB and bigger 404MB is taken up by and below is the same stats from the node_modules folder which means that pretty much the entire Cypress size comes from cypress binary 111MB My questions are
And in closing, I just want to say, wow man, wow! You've built something so amazing an pretty and functional here, and I am so blown away by the quality of it all Thank you for every little bit of effort you put into cypress because it's really such a wonderful product |
Guessing there's no update on this? |
Not yet I'm afraid. Anyone want to join me on this? I hit a wall with the needed libs |
How feasible is the layer option? Here's a git-lambda layer that allows using the git binary in lambdas https://github.com/lambci/git-lambda-layer. It builds it using bash scripts |
With the layer option, as you'll see above, I have still run into size issues for cypress size |
While doing some other options, I had some success with puppeteer via https://github.com/alixaxel/chrome-aws-lambda. They use this lambda layer for the browser https://github.com/shelfio/chrome-aws-lambda-layer. Maybe the cypress team can look into integration with this browser? |
I went a bit further than @WinstonN and tried to pack the big runtime with success by doing:
I got really excited because all this is within the limits of Lambda. The function runs!! However, there is a problem in that cypress expects in addition to the runtime to also have So it's not just about the size of the runtime, it's the fact that cypress requires Electron and a graphical environment. The article already quoted in this issue is very relevant to this |
@cortopy were you able to get Xvfb installed? I was following the same article you referenced, but since it was written AWS changed the runtime in node.js lambdas to AWS Linux 2 and a lot of the dependencies don't work. |
I created a tool to package cypress binaries in an npm-package. So that one can publish it to a private npm registry and use it in applications. See comment in #5141 (comment) |
@MeStrak I'm afraid not. I didn't want to go down the route, as the documentation on the Lambda environment is sparse and, as you've experienced, may change |
I've been looking at this https://github.com/grycap/scar - but getting an error when I try to run cypress docker in a lambda, tbh I think that is the only way we will achieve this. Even though I did not document it in my comments on this issue, I also ran in to library issues, and the libraries between the blog post out there, and later versions differ greatly - to the point where the original article is no longer helpful |
@WinstonN This would be amazing, I had looked for something like this but didn't come across this project. Let me know if I can help. I'm still hacking away with the stuartsandine approach which worked in node8.10 Amazon Linux 1. The linked articles are very useful for finding the needed dependencies. |
@MeStrak I would love to connect with you and maybe between us we can make this work? I think we can do it using scar (https://github.com/grycap/scar) if you want, you can find me on LinkedIn, and connect with me there. We can then exchange contact details, and perhaps, if you want, we can setup a google hangout and exchange notes? |
@tomardern @WinstonN Would you have an example repo with your Dockerfile, lambda and any other relevant files with the modifications you've mentioned? |
@kevinold Sorry for late reply. I've added the files here - https://gist.github.com/tomardern/822642988be2851beef930f94ba62fa2 |
@tomardern Thanks for the gist. That said, it is difficult to diagnose and assist with limited structure and missing files from the overall project. In order to investigate this further, please provide a git repo with all applicable files that can be deployed via Serverless, AWS SAM, or other utility to AWS. |
This should be possible now, since AWS lambda supports container images - see https://aws.amazon.com/blogs/aws/new-for-aws-lambda-container-image-support/ I recommend starting fresh, using the above link documentation When this thread was created lambda did not support container images, and the route that I went was simply not feasible, since I wanted to run this at scale (millions of invocations) I therefore went the puppeteer / playwright route which works fine Hope this helps, and good luck! |
Has anyone gotten this working yet? |
@tomardern I have been trying to get this working the past few days. I have it working for Selenium (on AWS Lambda) by using these Chrome flags: I also use the version of Chrome from https://github.com/alixaxel/chrome-aws-lambda (I do an |
The Cypress DX Team has examined this landscape and determined a recommended approach. We recommend that the orchestration be performed by AWS CodeBuild combined with the Cypress Dashboard (vs a command-and-control/fan-out pattern based approach). This has been implemented in the Cypress Real World App using the Please refer to this https://github.com/cypress-io/cypress-realworld-app/blob/develop/buildspec.yml In the buildspec, we are:
Reference: AWS CodeBuild now supports parallel and coordinated executions of a build project |
@kevinold Is that above solution you posted about today, to get it to run in AWS Lambda ? |
@smccarthy-godaddy Yes, technically CodeBuild uses Lambda's to run the container, but abstracts that away from you. |
@kevinold I tried looking at the |
The public image is simply one of our Cypress Docker Image hosted in a Public ECR. I mentioned in my previous message that we will be creating a Cypress Public ECR to house most, if not all of our images currently on DockerHub.
In the meantime, you can clone Cypress Docker Image repo and use this browsers/node14.15.0-chrome86-ff82 or any other browsers image and compile and push it up to your own AWS ECR (Public or Private). One note is that you will need to adjust the build.sh line to remove the slashes and colons (AWS ECR's do not allow these characters): Before:
After:
|
I did manage to run Cypress in Lambda myself.. but it's complicated. Before I forget, I wanted to brain-dump this here and outline the challenges I encountered and how I solved them. Lambda has a maximum of 512mb
Right now, my /tmp space total is around 124MB, which leaves some room for screenshots and video output. I did add output of video to s3 and observed the result. Right now, for some reason, the video freezes frame at "loading tests," I suspect I'll have to do some more work to get that going properly, but underneath it all I can confirm that the tests run and are returning the desired result. |
@stevenlafl can you share your docker file and handler function ? |
I sure can, here is the repository I wrote it under https://github.com/mobomo/cypress-qa Last I checked this was working. But you might have to insert your own tests, I might have removed those. |
@stevenlafl Hi just saw your post and repo. Are you using SAM as a substitute for AWS CodeBuild that Kevinold@cypress is recommending? What's the tradeoff of using one and not the other? I've not had experience with either. Thanks! |
If anyone is still interested I managed to get cypress to run both headless and headed using chromium on an AWS Lambda using a docker image. It's a .Net container image and the Dockerfile looks like this:
I had to edit the environment.js & chrome.js file to include the following additional flags, I tried to add these in the cypress.config.js file but it never picked them up:
These flags worked with headed chrome in lambdas when running selenium tests Finally I started Xvfb with the following:
Then run the following cypress run command:
Note: I copied the spec file to a Test directory in /tmp and copied the cypress.config.js to /tmp Once the test completes I returned the content of the results xml. It might not be what people are looking for but thought I'd share in case it helps anyone |
@nhayes84 I'm interested to run cypress in lambda, without any luck yet.
is this going to work with lambda/node docker image ? i.e. |
@manv6 Yes Xvfb is started at the beginning of the lambda function however if you don't want to start it yourself just remove ENV DISPLAY=":99" form the dockerfile. You will need to modify the xvfb.js file (found: ./node_modules/cypress/lib/exec/xvfb.js) to include the following additional arguments: The environment.js and chrome.js files are local copies of the files which are installed by cypress. I have just created copies and added the additional flags as mentioned in my original post. You can find them here:
I downloaded the cypress zip file and found them that way. I found it easier to modify them locally then copy them in the dockerfile rather than try to edit them directly in the dockerfile. Finally yes the last line is copying the lambda function along with the cypress.config.js and spec file. This is default functionality when you create a .Net image container using visual studio. The key thing for me to get it working was the changes to the environment.js and chrome.js files. Adding the flags allowed me to get past the various gpu errors. I don't see why you can't get it working with a node docker image, you'd just need to find the locations of the files I've modified and see if changing them works. Hope this helps. |
@manv6 @nhayes84, here are my two cents. Would love to hear what you think. I thought I needed to run Cypress on a Lambda, but I am now thinking of using AWS CodeBuild instead. My use case:
I thought it would be easy to run cypress on a lambda, given that I am already successfully running automated cypress tests in AWS CodeBuild (codebuild spawns some kind of lambda / EC2). I didn't anticipate there would be so many issues to get something similar running in a lambda. After reading through this thread, I think I will be better off setting up my status checks inside of AWS CodeBuild (it's easy to trigger CodeBuild from a scheduler, and the cypress team has paved the way to use cypress in AWS CodeBuild). Xavier |
@xavierrobitaille That's why I prefer lambdas(cheaper and faster) BUT I cannot make it work yet. I will try @nhayes84 solution asap |
@nhayes84 unfortunately this solution doesn't work on AWS Lambda with lambda nodejs image :( I did everything as described with but the base image. Where are you running your lambda ? can we take it offline and give you some more details ? |
@manv6 have you tried the Lambda setup in the repository I posted? If that isn't working I'll have to update it. |
@stevenlafl just tried it it seems to me that the ignore above lines just managed to load browser args but now I'm getting another error |
After a lot of trial and error, I've managed to get cypress to run from a Lambda using a container image and chromium as a browser. For anyone trying to do the same thing, I've put together a full example project you can refer to. |
@magJ tried your solution and only works in aws if you patch Cypress to write in Add below block after npm install
|
@manv6 The example as-is works fine for me without patching cypress, I guess since it's using chromium, patching cypress like you demonstrated might makes it work without installing another browser I suppose? Edit: I've now implemented this electron patching in my repo, electron now works locally when ipc is disabled, but still having problems with it on lambda. |
Any updates on this? |
Current behavior:
npm install cypress
downloads the cypress app binaryDesired behavior:
npm install cypress
(or something likenpm install @cypress/headless
) does not install a binary, and only installs necessary dependencies for running tests headlessly on CI.Additional Info (images, stack traces, etc)
Our CI configuration is pretty strict about what can be externally downloaded. It would be great if cypress could be run without needing to whitelist the cypress domain.
The text was updated successfully, but these errors were encountered: