Skip to content

Commit 4cd10f7

Browse files
committed
Remove claims about electron working.
Revert to only supporting chromium. Add basic SAM template for deployment.
1 parent 4ae3289 commit 4cd10f7

7 files changed

+35
-16
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
.idea
33
/cypress/
4+
samconfig.toml
5+
.aws-sam/

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN yum install -y \
1313
binutils && \
1414
yum clean all
1515

16-
# Install chromium, not nessesary if using cypress's embedded electron
16+
# Install chromium
1717
RUN yum install -y \
1818
amazon-linux-extras && \
1919
amazon-linux-extras install epel -y && \
@@ -36,7 +36,8 @@ COPY tests ./tests
3636
COPY src ./src
3737
RUN npx cypress verify
3838
RUN npx tsc
39-
RUN rm cypress.config.js
39+
40+
ENV ELECTRON_EXTRA_LAUNCH_ARGS="--no-zygote --disable-gpu --single-process"
4041

4142
# Only used for local testing of unprivleged users, lambda will create it's own user
4243
RUN /sbin/adduser testuser

README.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cypress on AWS lambda example
22

3-
A demonstration of how to run cypress on AWS lambda, using electron and/or chromium.
3+
A demonstration of how to run cypress on AWS lambda, using chromium.
44

55
I've tried to make this as minimal as possible, but there might be some ways this could be simplified further.
66

@@ -9,12 +9,17 @@ I've tried to make this as minimal as possible, but there might be some ways thi
99
similar(although not identical) to how it would be run from lambda.
1010

1111
Once the image is built you will have to push it to an ECR repo, and create your lambda function.
12-
1312
A lambda with 2GB of ram seems to work ok.
1413

14+
### Using SAM
15+
A basic SAM template is included, with which you can deploy the lambda
16+
```bash
17+
# Build image
18+
sam build
19+
# Interactive deployment wizard
20+
sam deploy --guided
21+
```
22+
1523
## Things of note
1624
If you want to save screenshots or video, you may need to run the project from the tmp dir,
1725
see the initial commit for an example of this.
18-
19-
If you don't want to use electron, you can avoid patching it's binary, although you will still need to set some environment variables
20-
See the documentation in the `patch-cypress.sh` file.

patch-cypress.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ for cypress_version_dir in "$cypress_cache_dir"/*; do
77
cypress_electron_binary_location="$cypress_version_dir/Cypress/Cypress"
88
# Patches cypress's electron binary to replace references to /dev/shm to /tmp/shm, as /dev/shm isn't writable on lambda
99
#
10-
# If this is too hacky for you, and you want to use another browser like chromium.
11-
# You will need still to set ELECTRON_EXTRA_LAUNCH_ARGS="--no-zygote --disable-gpu --single-process"
12-
# Because electron is still invoked in the cypress initialization process, regardless of if you intent to use it or not
13-
# The above environment variables will be enough for the electron initialization to proceed, and avoid the need to patch
10+
# Alternatively setting ELECTRON_EXTRA_LAUNCH_ARGS="--no-zygote --disable-gpu --single-process", seems to be enough for
11+
# cypress to make it past initialisation, and start chromium, but it still seems to occasionally crash
1412
position=$(strings -t d $cypress_electron_binary_location | grep "/dev/shm" | cut -d" " -f1)
1513
for i in $position; do
1614
echo -n "/tmp/shm/" | dd bs=1 of=$cypress_electron_binary_location seek="$i" conv=notrunc

src/lambdaHandler.ts

-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import * as cypress from "cypress";
22

33
export const handler = async () => {
4-
console.log("Running cypress tests with electron");
5-
await cypress.run({
6-
headless: true,
7-
});
84
console.log("Running cypress tests with chromium");
95
await cypress.run({
106
headless: true,

template.yaml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
AWSTemplateFormatVersion: '2010-09-09'
2+
Transform: AWS::Serverless-2016-10-31
3+
4+
Resources:
5+
CypressLambda:
6+
Type: AWS::Serverless::Function
7+
Properties:
8+
Timeout: 300
9+
MemorySize: 2048
10+
PackageType: Image
11+
Architectures:
12+
- x86_64
13+
Metadata:
14+
DockerTag: sam-cypress-lambda-example
15+
DockerContext: .
16+
Dockerfile: Dockerfile

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@
2121
"strictPropertyInitialization": false,
2222
"typeRoots": ["./node_modules/@types"]
2323
},
24-
"exclude": ["node_modules"]
24+
"exclude": ["node_modules"],
25+
"include": ["src"]
2526
}

0 commit comments

Comments
 (0)